blob: 3712c06cbcba0f1c02c6666923d150ed3c939969 [file] [log] [blame]
Yi Tseng51f1be92017-09-01 17:24:57 -07001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.dhcprelay.config;
18
19import com.fasterxml.jackson.databind.JsonNode;
20import com.fasterxml.jackson.databind.ObjectMapper;
21import com.google.common.io.Resources;
22import org.junit.Test;
23import org.onlab.packet.VlanId;
24import org.onosproject.TestApplicationId;
25import org.onosproject.core.ApplicationId;
26import org.onosproject.net.DeviceId;
27
28import java.io.IOException;
29import java.util.Collection;
30
31import static org.junit.Assert.assertEquals;
32import static org.junit.Assert.assertTrue;
33import static org.onosproject.dhcprelay.DhcpRelayManager.DHCP_RELAY_APP;
34
35public class IgnoreDhcpConfigTest {
36 private static final String CONFIG_FILE_PATH = "dhcp-relay.json";
37 private static final ApplicationId APP_ID = new TestApplicationId("DhcpRelayTest");
38 private static final DeviceId DEV_1_ID = DeviceId.deviceId("of:0000000000000001");
39 private static final DeviceId DEV_2_ID = DeviceId.deviceId("of:0000000000000002");
40 private static final VlanId IGNORED_VLAN = VlanId.vlanId("100");
41 @Test
42 public void testIgnoredDhcpConfig() throws IOException {
43 ObjectMapper om = new ObjectMapper();
44 JsonNode json = om.readTree(Resources.getResource(CONFIG_FILE_PATH));
45 IgnoreDhcpConfig config = new IgnoreDhcpConfig();
46 json = json.path("apps").path(DHCP_RELAY_APP).path(IgnoreDhcpConfig.KEY);
47 config.init(APP_ID, IgnoreDhcpConfig.KEY, json, om, null);
48
49 assertEquals(2, config.ignoredVlans().size());
50 Collection<VlanId> vlanForDev1 = config.ignoredVlans().get(DEV_1_ID);
51 Collection<VlanId> vlanForDev2 = config.ignoredVlans().get(DEV_2_ID);
52
53 assertEquals(1, vlanForDev1.size());
54 assertEquals(1, vlanForDev2.size());
55
56 assertTrue(vlanForDev1.contains(IGNORED_VLAN));
57 assertTrue(vlanForDev2.contains(IGNORED_VLAN));
58 }
59}