blob: 03536cd02fc59f3a2c50ad6923943db5005b43f3 [file] [log] [blame]
Charles Chand55e84d2016-03-30 17:54:24 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Charles Chand55e84d2016-03-30 17:54:24 -07003 *
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
Ray Milkeyd29bc1c2018-03-13 11:57:11 -070017package org.onosproject.net.config.basics;
Charles Chand55e84d2016-03-30 17:54:24 -070018
19import com.fasterxml.jackson.databind.JsonNode;
20import com.fasterxml.jackson.databind.ObjectMapper;
21import com.google.common.annotations.Beta;
22import org.junit.Before;
23import org.junit.Test;
24import org.onlab.packet.VlanId;
25import org.onosproject.TestApplicationId;
26import org.onosproject.core.ApplicationId;
27import org.onosproject.core.CoreService;
28import org.onosproject.net.config.Config;
29import org.onosproject.net.config.ConfigApplyDelegate;
30
31import java.io.InputStream;
32
33import static org.hamcrest.Matchers.is;
Ray Milkeyd29bc1c2018-03-13 11:57:11 -070034import static org.junit.Assert.assertFalse;
35import static org.junit.Assert.assertNotNull;
36import static org.junit.Assert.assertThat;
37import static org.junit.Assert.assertTrue;
Charles Chand55e84d2016-03-30 17:54:24 -070038
39/**
40 * Tests for class {@link McastConfig}.
41 */
42@Beta
43public class McastConfigTest {
44 private static final TestApplicationId APP_ID =
45 new TestApplicationId(CoreService.CORE_APP_NAME);
46 private McastConfig config;
47 private McastConfig invalidConfig;
48
49 private static final VlanId INGRESS_VLAN_1 = VlanId.NONE;
50 private static final VlanId EGRESS_VLAN_1 = VlanId.NONE;
51 private static final VlanId INGRESS_VLAN_2 = VlanId.vlanId((short) 100);
52 private static final VlanId EGRESS_VLAN_2 = VlanId.vlanId((short) 100);
53
54 /**
55 * Initialize test related variables.
56 *
57 * @throws Exception
58 */
59 @Before
60 public void setUp() throws Exception {
61 InputStream jsonStream = McastConfigTest.class
62 .getResourceAsStream("/mcast-config.json");
63 InputStream invalidJsonStream = McastConfigTest.class
64 .getResourceAsStream("/mcast-config-invalid.json");
65
66 ApplicationId subject = APP_ID;
67 String key = CoreService.CORE_APP_NAME;
68 ObjectMapper mapper = new ObjectMapper();
69 JsonNode jsonNode = mapper.readTree(jsonStream);
70 JsonNode invalidJsonNode = mapper.readTree(invalidJsonStream);
71 ConfigApplyDelegate delegate = new MockDelegate();
72
73 config = new McastConfig();
74 config.init(subject, key, jsonNode, mapper, delegate);
75 invalidConfig = new McastConfig();
76 invalidConfig.init(subject, key, invalidJsonNode, mapper, delegate);
77 }
78
79 /**
80 * Tests config validity.
81 *
82 * @throws Exception
83 */
84 @Test
85 public void isValid() throws Exception {
86 assertTrue(config.isValid());
87 assertFalse(invalidConfig.isValid());
88 }
89
90 /**
91 * Tests ingress VLAN getter.
92 *
93 * @throws Exception
94 */
95 @Test
96 public void ingressVlan() throws Exception {
97 VlanId ingressVlan = config.ingressVlan();
98 assertNotNull("ingressVlan should not be null", ingressVlan);
99 assertThat(ingressVlan, is(INGRESS_VLAN_1));
100 }
101
102 /**
103 * Tests ingress VLAN setter.
104 *
105 * @throws Exception
106 */
107 @Test
108 public void setIngressVlan() throws Exception {
109 config.setIngressVlan(INGRESS_VLAN_2);
110
111 VlanId ingressVlan = config.ingressVlan();
112 assertNotNull("ingressVlan should not be null", ingressVlan);
113 assertThat(ingressVlan, is(INGRESS_VLAN_2));
114 }
115
116 /**
117 * Tests egress VLAN getter.
118 *
119 * @throws Exception
120 */
121 @Test
122 public void egressVlan() throws Exception {
123 VlanId egressVlan = config.egressVlan();
124 assertNotNull("egressVlan should not be null", egressVlan);
125 assertThat(egressVlan, is(EGRESS_VLAN_1));
126 }
127
128 /**
129 * Tests egress VLAN setter.
130 *
131 * @throws Exception
132 */
133 @Test
134 public void setEgressVlan() throws Exception {
135 config.setEgressVlan(EGRESS_VLAN_2);
136
137 VlanId egressVlan = config.egressVlan();
138 assertNotNull("egressVlan should not be null", egressVlan);
139 assertThat(egressVlan, is(EGRESS_VLAN_2));
140 }
141
142 private class MockDelegate implements ConfigApplyDelegate {
143 @Override
144 public void onApply(Config config) {
145 }
146 }
Ray Milkey6c1f0f02017-08-15 11:02:29 -0700147}