Yi Tseng | 51f1be9 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.dhcprelay.config; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 21 | import com.google.common.io.Resources; |
| 22 | import org.junit.Test; |
| 23 | import org.onlab.packet.VlanId; |
| 24 | import org.onosproject.TestApplicationId; |
| 25 | import org.onosproject.core.ApplicationId; |
| 26 | import org.onosproject.net.DeviceId; |
| 27 | |
| 28 | import java.io.IOException; |
| 29 | import java.util.Collection; |
| 30 | |
| 31 | import static org.junit.Assert.assertEquals; |
| 32 | import static org.junit.Assert.assertTrue; |
| 33 | import static org.onosproject.dhcprelay.DhcpRelayManager.DHCP_RELAY_APP; |
| 34 | |
| 35 | public 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 | } |