Annce John | 84229f7 | 2017-11-22 06:27:01 -0500 | [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.ra.config; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | |
| 24 | import org.onosproject.net.DeviceId; |
| 25 | import org.onosproject.net.config.Config; |
| 26 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 27 | import java.util.List; |
| 28 | import java.util.ArrayList; |
| 29 | import org.onosproject.net.host.InterfaceIpAddress; |
| 30 | |
| 31 | import java.io.InputStream; |
| 32 | import static org.junit.Assert.assertThat; |
| 33 | import static org.junit.Assert.assertTrue; |
| 34 | import static org.hamcrest.Matchers.is; |
| 35 | |
| 36 | /** |
| 37 | * Tests for class {@link RouterAdvertisementDeviceConfig}. |
| 38 | */ |
| 39 | public class RouterAdvertisementDeviceConfigTest { |
| 40 | private RouterAdvertisementDeviceConfig config; |
| 41 | private List<InterfaceIpAddress> prefixes; |
| 42 | |
| 43 | @Before |
| 44 | public void setUp() throws Exception { |
| 45 | InputStream jsonStream = RouterAdvertisementDeviceConfigTest.class |
| 46 | .getResourceAsStream("/device.json"); |
| 47 | |
| 48 | prefixes = new ArrayList<InterfaceIpAddress>(); |
| 49 | |
| 50 | prefixes.add(InterfaceIpAddress.valueOf("2001:0558:FF10:04C9::6:100/120")); |
| 51 | prefixes.add(InterfaceIpAddress.valueOf("2001:0558:FF10:04C9::7:100/120")); |
| 52 | |
| 53 | DeviceId subject = DeviceId.deviceId("of:0000000000000001"); |
| 54 | String key = "routeradvertisement"; |
| 55 | ObjectMapper mapper = new ObjectMapper(); |
| 56 | JsonNode jsonNode = mapper.readTree(jsonStream); |
| 57 | ConfigApplyDelegate delegate = new MockDelegate(); |
| 58 | |
| 59 | config = new RouterAdvertisementDeviceConfig(); |
| 60 | config.init(subject, key, jsonNode, mapper, delegate); |
| 61 | |
| 62 | } |
| 63 | |
| 64 | @Test |
| 65 | public void testIsValid() { |
| 66 | assertTrue(config.isValid()); |
| 67 | } |
| 68 | |
| 69 | @Test |
| 70 | public void testPrefixes() throws Exception { |
| 71 | assertThat(config.prefixes(), is(prefixes)); |
| 72 | } |
| 73 | |
| 74 | private class MockDelegate implements ConfigApplyDelegate { |
| 75 | @Override |
| 76 | public void onApply(Config configFile) { |
| 77 | } |
| 78 | } |
| 79 | } |