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