blob: 52a38db51ce0f3b6892a34b94fb2965acaabe76e [file] [log] [blame]
Annce Johnc23416b2017-11-22 06:27:01 -05001/*
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.ra.config;
18
19import com.fasterxml.jackson.databind.JsonNode;
20import com.fasterxml.jackson.databind.ObjectMapper;
21import org.junit.Before;
22import org.junit.Test;
23
24import org.onosproject.net.DeviceId;
25import org.onosproject.net.config.Config;
26import org.onosproject.net.config.ConfigApplyDelegate;
27import java.util.List;
28import java.util.ArrayList;
29import org.onosproject.net.host.InterfaceIpAddress;
30
31import java.io.InputStream;
32import static org.junit.Assert.assertThat;
33import static org.junit.Assert.assertTrue;
34import static org.hamcrest.Matchers.is;
35
36/**
37 * Tests for class {@link RouterAdvertisementDeviceConfig}.
38 */
39public 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}