Kalyankumar Asangi
Committed by Thomas Vachuska

ONOS-2740,ONOS-2741,from ONOS-3032 - to ONOS 3071 , OSPF Protocol Implementation Unit Tests

Change-Id: I7cb129186a99bbf3d20fd6731485e3d84905e939
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
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 +package org.onosproject.ospf.controller.area;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +import org.onosproject.ospf.controller.OspfProcess;
22 +
23 +import java.util.ArrayList;
24 +import java.util.List;
25 +
26 +import static org.hamcrest.CoreMatchers.is;
27 +import static org.hamcrest.CoreMatchers.notNullValue;
28 +import static org.hamcrest.MatcherAssert.assertThat;
29 +
30 +/**
31 + * Unit test class for Configuration.
32 + */
33 +public class ConfigurationTest {
34 + private Configuration configuration;
35 + private List<OspfProcess> ospfProcesses;
36 + private List result;
37 + private OspfProcessImpl ospfProcessImpl;
38 +
39 + @Before
40 + public void setUp() throws Exception {
41 + configuration = new Configuration();
42 + }
43 +
44 + @After
45 + public void tearDown() throws Exception {
46 + configuration = null;
47 + ospfProcessImpl = new OspfProcessImpl();
48 + result = null;
49 + ospfProcesses = null;
50 + }
51 +
52 + /**
53 + * Tests getProcesses() getter method.
54 + */
55 + @Test
56 + public void testGetOspfProcess() throws Exception {
57 + ospfProcesses = new ArrayList();
58 + ospfProcesses.add(ospfProcessImpl);
59 + ospfProcesses.add(ospfProcessImpl);
60 + configuration.setProcesses(ospfProcesses);
61 + result = configuration.getProcesses();
62 + assertThat(result.size(), is(2));
63 + }
64 +
65 + /**
66 + * Tests setProcesses() setter method.
67 + */
68 + @Test
69 + public void testSetOspfProcess() throws Exception {
70 + ospfProcesses = new ArrayList();
71 + ospfProcesses.add(ospfProcessImpl);
72 + ospfProcesses.add(ospfProcessImpl);
73 + configuration.setProcesses(ospfProcesses);
74 + result = configuration.getProcesses();
75 + assertThat(result.size(), is(2));
76 + }
77 +
78 + /**
79 + * Tests getMethod() getter method.
80 + */
81 + @Test
82 + public void testGetMethod() throws Exception {
83 + configuration.setMethod("method");
84 + assertThat(configuration.getMethod(), is("method"));
85 + }
86 +
87 + /**
88 + * Tests setMethod() setter method.
89 + */
90 + @Test
91 + public void testSetMethod() throws Exception {
92 + configuration.setMethod("method");
93 + assertThat(configuration.getMethod(), is("method"));
94 + }
95 +
96 + /**
97 + * Tests to string method.
98 + */
99 + @Test
100 + public void testToString() throws Exception {
101 + assertThat(configuration.toString(), is(notNullValue()));
102 + }
103 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
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 +package org.onosproject.ospf.controller.area;
17 +
18 +
19 +import org.easymock.EasyMock;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onlab.packet.Ip4Address;
24 +import org.onosproject.ospf.controller.OspfAreaAddressRange;
25 +
26 +import static org.hamcrest.CoreMatchers.is;
27 +import static org.hamcrest.CoreMatchers.notNullValue;
28 +import static org.hamcrest.MatcherAssert.assertThat;
29 +
30 +/**
31 + * Unit test class for OspfAreaAddressRangeImpl.
32 + */
33 +public class OspfAreaAddressRangeImplTest {
34 +
35 + private OspfAreaAddressRange ospfAreaAddressRange;
36 + private int result;
37 + private String result1;
38 +
39 + @Before
40 + public void setUp() throws Exception {
41 + ospfAreaAddressRange = new OspfAreaAddressRangeImpl();
42 + }
43 +
44 + @After
45 + public void tearDown() throws Exception {
46 + ospfAreaAddressRange = null;
47 + }
48 +
49 + /**
50 + * Tests ipAddress() getter method.
51 + */
52 + @Test
53 + public void testGetIpAddress() throws Exception {
54 + ospfAreaAddressRange.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
55 + assertThat(ospfAreaAddressRange.ipAddress(), is(Ip4Address.valueOf("1.1.1.1")));
56 + }
57 +
58 + /**
59 + * Tests ipAddress() setter method.
60 + */
61 + @Test
62 + public void testSetIpAddress() throws Exception {
63 + ospfAreaAddressRange.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
64 + assertThat(ospfAreaAddressRange.ipAddress(), is(Ip4Address.valueOf("1.1.1.1")));
65 + }
66 +
67 + /**
68 + * Tests mask() getter method.
69 + */
70 + @Test
71 + public void testGetMask() throws Exception {
72 + ospfAreaAddressRange.setMask("1.1.1.1");
73 + assertThat(ospfAreaAddressRange.mask(), is("1.1.1.1"));
74 + }
75 +
76 + /**
77 + * Tests mask() setter method.
78 + */
79 + @Test
80 + public void testSetMask() throws Exception {
81 + ospfAreaAddressRange.setMask("1.1.1.1");
82 + assertThat(ospfAreaAddressRange.mask(), is("1.1.1.1"));
83 + }
84 +
85 + /**
86 + * Tests isAdvertise() getter method.
87 + */
88 + @Test
89 + public void testIsAdvertise() throws Exception {
90 + ospfAreaAddressRange.setAdvertise(true);
91 + assertThat(ospfAreaAddressRange.isAdvertise(), is(true));
92 + }
93 +
94 + /**
95 + * Tests isAdvertise() setter method.
96 + */
97 + @Test
98 + public void testSetAdvertise() throws Exception {
99 + ospfAreaAddressRange.setAdvertise(true);
100 + assertThat(ospfAreaAddressRange.isAdvertise(), is(true));
101 + }
102 +
103 + /**
104 + * Tests equals() method.
105 + */
106 + @Test
107 + public void testEquals() throws Exception {
108 + assertThat(ospfAreaAddressRange.equals(new OspfAreaAddressRangeImpl()), is(false));
109 + }
110 +
111 + /**
112 + * Tests equals() method.
113 + */
114 + @Test
115 + public void testEquals1() throws Exception {
116 + assertThat(ospfAreaAddressRange.equals(EasyMock.createMock(OspfAreaAddressRange.class)), is(false));
117 + }
118 +
119 + @Test
120 + public void testHashCode() throws Exception {
121 + result = ospfAreaAddressRange.hashCode();
122 + assertThat(result, is(notNullValue()));
123 + }
124 +
125 + /**
126 + * Tests to string method.
127 + */
128 + @Test
129 + public void testToString() throws Exception {
130 + result1 = ospfAreaAddressRange.toString();
131 + assertThat(result1, is(notNullValue()));
132 + }
133 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
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 +package org.onosproject.ospf.controller.area;
17 +
18 +import org.easymock.EasyMock;
19 +import org.junit.After;
20 +import org.junit.Before;
21 +import org.junit.Test;
22 +import org.onlab.packet.Ip4Address;
23 +import org.onosproject.ospf.controller.OspfArea;
24 +import org.onosproject.ospf.controller.OspfAreaAddressRange;
25 +import org.onosproject.ospf.controller.OspfInterface;
26 +import org.onosproject.ospf.controller.OspfNbr;
27 +import org.onosproject.ospf.controller.OspfNeighborState;
28 +import org.onosproject.ospf.controller.TopologyForDeviceAndLink;
29 +import org.onosproject.ospf.controller.impl.Controller;
30 +import org.onosproject.ospf.controller.impl.OspfInterfaceChannelHandler;
31 +import org.onosproject.ospf.controller.impl.OspfNbrImpl;
32 +import org.onosproject.ospf.controller.impl.TopologyForDeviceAndLinkImpl;
33 +import org.onosproject.ospf.controller.lsdb.LsaWrapperImpl;
34 +import org.onosproject.ospf.protocol.lsa.LsaHeader;
35 +import org.onosproject.ospf.protocol.lsa.types.NetworkLsa;
36 +import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
37 +import org.onosproject.ospf.protocol.util.OspfInterfaceState;
38 +
39 +import java.util.ArrayList;
40 +import java.util.HashMap;
41 +import java.util.List;
42 +
43 +import static org.hamcrest.MatcherAssert.assertThat;
44 +import static org.hamcrest.Matchers.*;
45 +
46 +/**
47 + * Unit test class for OspfAreaImpl.
48 + */
49 +public class OspfAreaImplTest {
50 +
51 + private OspfAreaImpl ospfArea;
52 + private int result;
53 + private OspfInterfaceImpl ospfInterface;
54 + private HashMap<String, OspfNbr> ospfNbrList;
55 + private List<OspfInterface> ospfInterfaces;
56 + private OspfInterfaceImpl ospfInterface1;
57 + private OspfInterfaceImpl ospfInterface2;
58 + private OspfInterfaceImpl ospfInterface3;
59 + private OspfInterfaceImpl ospfInterface4;
60 + private OspfInterfaceImpl ospfInterface5;
61 + private OspfInterfaceImpl ospfInterface6;
62 + private NetworkLsa networkLsa;
63 + private OspfNbrImpl ospfNbr;
64 + private RouterLsa routerLsa;
65 + private List<OspfAreaAddressRange> ospfAreaAddressRanges;
66 + private LsaHeader lsaHeader;
67 + private TopologyForDeviceAndLink topologyForDeviceAndLink;
68 +
69 + @Before
70 + public void setUp() throws Exception {
71 + ospfArea = new OspfAreaImpl();
72 + topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl();
73 + }
74 +
75 + @After
76 + public void tearDown() throws Exception {
77 + ospfArea = null;
78 + ospfInterface = null;
79 + ospfNbrList = null;
80 + ospfInterfaces = null;
81 + ospfAreaAddressRanges = null;
82 + lsaHeader = null;
83 + routerLsa = null;
84 + ospfNbr = null;
85 + networkLsa = null;
86 + ospfInterface1 = null;
87 + ospfInterface2 = null;
88 + ospfInterface3 = null;
89 + ospfInterface4 = null;
90 + ospfInterface5 = null;
91 + ospfInterface6 = null;
92 +
93 + }
94 +
95 + /**
96 + * Tests equals() method.
97 + */
98 + @Test
99 + public void testEquals() throws Exception {
100 + ospfArea = new OspfAreaImpl();
101 + ospfInterface = new OspfInterfaceImpl();
102 + ospfArea.setTransitCapability(true);
103 + ospfArea.setExternalRoutingCapability(true);
104 + ospfArea.setStubCost(100);
105 + ospfArea.initializeDb();
106 + ospfArea.setAddressRanges(ospfAreaAddressRanges);
107 + assertThat(ospfArea.equals(ospfArea), is(true));
108 + ospfArea = EasyMock.createMock(OspfAreaImpl.class);
109 + assertThat(ospfArea.equals(ospfArea), is(true));
110 + OspfArea ospfArea = new OspfAreaImpl();
111 + assertThat(ospfArea.equals(ospfArea), is(true));
112 + }
113 +
114 + /**
115 + * Tests hashCode() method.
116 + */
117 + @Test
118 + public void testHashCode() throws Exception {
119 + result = ospfArea.hashCode();
120 + assertThat(result, is(notNullValue()));
121 + }
122 +
123 + /**
124 + * Tests routerId() getter method.
125 + */
126 + @Test
127 + public void testGetRouterId() throws Exception {
128 + ospfArea.setRouterId(Ip4Address.valueOf("1.1.1.1"));
129 + assertThat(ospfArea.routerId(), is(Ip4Address.valueOf("1.1.1.1")));
130 + }
131 +
132 + /**
133 + * Tests routerId() setter method.
134 + */
135 + @Test
136 + public void testSetRouterId() throws Exception {
137 + ospfArea.setRouterId(Ip4Address.valueOf("1.1.1.1"));
138 + assertThat(ospfArea.routerId(), is(Ip4Address.valueOf("1.1.1.1")));
139 + }
140 +
141 + /**
142 + * Tests isOpaqueEnabled() getter method.
143 + */
144 + @Test
145 + public void testSetisOpaqueEnabled() throws Exception {
146 + ospfArea.setIsOpaqueEnabled(true);
147 + assertThat(ospfArea.isOpaqueEnabled(), is(true));
148 + }
149 +
150 + /**
151 + * Tests isOpaqueEnabled() setter method.
152 + */
153 + @Test
154 + public void testIsOpaqueEnabled() throws Exception {
155 + ospfArea.setIsOpaqueEnabled(true);
156 + assertThat(ospfArea.isOpaqueEnabled(), is(true));
157 + }
158 +
159 + /**
160 + * Tests initializeDb() method.
161 + */
162 + @Test
163 + public void testInitializeDb() throws Exception {
164 + ospfArea.initializeDb();
165 + assertThat(ospfArea, is(notNullValue()));
166 + }
167 +
168 + /**
169 + * Tests refreshArea() method.
170 + */
171 + @Test
172 + public void testRefreshArea() throws Exception {
173 +
174 + ospfInterface = new OspfInterfaceImpl();
175 + ospfInterface.setState(OspfInterfaceState.DR);
176 + ospfNbrList = new HashMap();
177 + ospfNbrList.put("1.1.1.1", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
178 + Ip4Address.valueOf("1.1.1.1"),
179 + Ip4Address.valueOf("2.2.2.2"), 2,
180 + new OspfInterfaceChannelHandler(new Controller(),
181 + new OspfAreaImpl(),
182 + new OspfInterfaceImpl()),
183 + topologyForDeviceAndLink));
184 + ospfNbrList.put("2.2.2.2", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
185 + Ip4Address.valueOf("1.1.1.1"),
186 + Ip4Address.valueOf("2.2.2.2"), 2,
187 + new OspfInterfaceChannelHandler(new Controller(),
188 + new OspfAreaImpl(),
189 + new OspfInterfaceImpl())
190 + , topologyForDeviceAndLink));
191 + ospfNbrList.put("3.3.3.3", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
192 + Ip4Address.valueOf("1.1.1.1"),
193 + Ip4Address.valueOf("2.2.2.2"), 2,
194 + new OspfInterfaceChannelHandler(new Controller(),
195 + new OspfAreaImpl(),
196 + new OspfInterfaceImpl())
197 + , topologyForDeviceAndLink));
198 + ospfNbrList.put("4.4.4.4", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
199 + Ip4Address.valueOf("1.1.1.1"),
200 + Ip4Address.valueOf("2.2.2.2"), 2,
201 + new OspfInterfaceChannelHandler(new Controller(),
202 + new OspfAreaImpl(),
203 + new OspfInterfaceImpl())
204 + , topologyForDeviceAndLink));
205 +
206 + ospfInterface.setListOfNeighbors(ospfNbrList);
207 + ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.10"));
208 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
209 + ospfInterfaces = new ArrayList();
210 + ospfInterface1 = new OspfInterfaceImpl();
211 + ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
212 + ospfInterfaces.add(ospfInterface1);
213 + ospfInterface2 = new OspfInterfaceImpl();
214 + ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
215 + ospfInterfaces.add(ospfInterface2);
216 + ospfInterface3 = new OspfInterfaceImpl();
217 + ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
218 + ospfInterfaces.add(ospfInterface3);
219 + ospfArea.setInterfacesLst(ospfInterfaces);
220 + ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
221 + networkLsa = ospfArea.buildNetworkLsa(Ip4Address.valueOf("1.1.1.1"),
222 + Ip4Address.valueOf("255.255.255.255"));
223 + ospfArea.refreshArea(ospfInterface);
224 + assertThat(ospfNbrList.size(), is(4));
225 + assertThat(networkLsa, is(notNullValue()));
226 + assertThat(ospfArea, is(notNullValue()));
227 + }
228 +
229 + /**
230 + * Tests buildNetworkLsa() method.
231 + */
232 + @Test
233 + public void testBuildNetworkLsa() throws Exception {
234 + ospfInterfaces = new ArrayList();
235 + ospfInterface1 = new OspfInterfaceImpl();
236 + ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
237 + ospfInterfaces.add(ospfInterface1);
238 + ospfInterface2 = new OspfInterfaceImpl();
239 + ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
240 + ospfInterfaces.add(ospfInterface2);
241 + ospfInterface3 = new OspfInterfaceImpl();
242 + ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
243 + ospfInterfaces.add(ospfInterface3);
244 + ospfArea.setInterfacesLst(ospfInterfaces);
245 + ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
246 + networkLsa = ospfArea.buildNetworkLsa(Ip4Address.valueOf("1.1.1.1"),
247 + Ip4Address.valueOf("255.255.255.255"));
248 + assertThat(ospfInterfaces.size(), is(3));
249 + assertThat(networkLsa, is(notNullValue()));
250 + assertThat(ospfArea, is(notNullValue()));
251 + }
252 +
253 + /**
254 + * Tests buildNetworkLsa() method.
255 + */
256 + @Test
257 + public void testBuildNetworkLsa1() throws Exception {
258 + ospfInterfaces = new ArrayList();
259 + ospfInterface1 = new OspfInterfaceImpl();
260 + ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
261 + ospfInterface1.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
262 + ospfInterface1.setState(OspfInterfaceState.POINT2POINT);
263 + ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
264 + Ip4Address.valueOf("1.1.1.1"),
265 + Ip4Address.valueOf("2.2.2.2"), 2,
266 + new OspfInterfaceChannelHandler(new Controller(),
267 + new OspfAreaImpl(),
268 + new OspfInterfaceImpl())
269 + , topologyForDeviceAndLink);
270 + ospfNbr.setState(OspfNeighborState.FULL);
271 + ospfInterface1.addNeighbouringRouter(ospfNbr);
272 + ospfInterfaces.add(ospfInterface1);
273 + ospfArea.setInterfacesLst(ospfInterfaces);
274 + ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
275 + networkLsa = ospfArea.buildNetworkLsa(Ip4Address.valueOf("1.1.1.1"),
276 + Ip4Address.valueOf("255.255.255.255"));
277 + assertThat(ospfInterfaces.size(), is(1));
278 + assertThat(networkLsa, is(notNullValue()));
279 + assertThat(ospfArea, is(notNullValue()));
280 + }
281 +
282 + /**
283 + * Tests buildRouterLsa() method.
284 + */
285 + @Test
286 + public void testBuildRouterLsa() throws Exception {
287 + ospfNbrList = new HashMap();
288 + ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
289 + Ip4Address.valueOf("1.1.1.1"),
290 + Ip4Address.valueOf("2.2.2.2"), 2,
291 + new OspfInterfaceChannelHandler(new Controller(),
292 + new OspfAreaImpl(),
293 + new OspfInterfaceImpl())
294 + , topologyForDeviceAndLink);
295 + ospfNbr.setState(OspfNeighborState.FULL);
296 + ospfInterfaces = new ArrayList();
297 + ospfInterface1 = new OspfInterfaceImpl();
298 + ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
299 + ospfInterface1.setState(OspfInterfaceState.DOWN);
300 + ospfInterface1.addNeighbouringRouter(ospfNbr);
301 + ospfInterfaces.add(ospfInterface1);
302 + ospfInterface2 = new OspfInterfaceImpl();
303 + ospfInterface2.setState(OspfInterfaceState.LOOPBACK);
304 + ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
305 + ospfInterface2.addNeighbouringRouter(ospfNbr);
306 + ospfInterfaces.add(ospfInterface2);
307 + ospfInterface3 = new OspfInterfaceImpl();
308 + ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
309 + ospfInterface3.setState(OspfInterfaceState.POINT2POINT);
310 + ospfInterface3.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
311 + ospfInterface3.addNeighbouringRouter(ospfNbr);
312 + ospfInterface3.setListOfNeighbors(ospfNbrList);
313 + ospfInterfaces.add(ospfInterface3);
314 + ospfInterface4 = new OspfInterfaceImpl();
315 + ospfInterface4.setState(OspfInterfaceState.WAITING);
316 + ospfInterface4.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
317 + ospfInterface4.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
318 + ospfInterfaces.add(ospfInterface4);
319 + ospfInterface5 = new OspfInterfaceImpl();
320 + ospfInterface5.setState(OspfInterfaceState.DR);
321 + ospfInterface5.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
322 + ospfInterfaces.add(ospfInterface5);
323 + ospfInterface6 = new OspfInterfaceImpl();
324 + ospfInterface6.setState(OspfInterfaceState.BDR);
325 + ospfInterface6.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
326 + ospfInterface6.setDr(Ip4Address.valueOf("3.3.3.3"));
327 + ospfInterfaces.add(ospfInterface6);
328 + ospfArea.setInterfacesLst(ospfInterfaces);
329 + ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
330 + assertThat(ospfInterfaces.size(), is(6));
331 + routerLsa = ospfArea.buildRouterLsa(ospfInterface1);
332 + assertThat(routerLsa, is(notNullValue()));
333 + routerLsa = ospfArea.buildRouterLsa(ospfInterface2);
334 + assertThat(routerLsa, is(notNullValue()));
335 + routerLsa = ospfArea.buildRouterLsa(ospfInterface3);
336 + assertThat(routerLsa, is(notNullValue()));
337 + assertThat(ospfArea, is(notNullValue()));
338 + }
339 +
340 + /**
341 + * Tests buildRouterLsa() method.
342 + */
343 + @Test
344 + public void testBuildRouterLsa1() throws Exception {
345 + ospfInterfaces = new ArrayList();
346 + ospfInterface1 = new OspfInterfaceImpl();
347 + ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
348 + ospfInterface1.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
349 + ospfInterface1.setState(OspfInterfaceState.POINT2POINT);
350 + ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
351 + Ip4Address.valueOf("1.1.1.1"),
352 + Ip4Address.valueOf("2.2.2.2"), 2,
353 + new OspfInterfaceChannelHandler(new Controller(),
354 + new OspfAreaImpl(),
355 + new OspfInterfaceImpl())
356 + , topologyForDeviceAndLink);
357 + ospfNbr.setState(OspfNeighborState.FULL);
358 + ospfInterface1.addNeighbouringRouter(ospfNbr);
359 + ospfInterfaces.add(ospfInterface1);
360 + ospfArea.setInterfacesLst(ospfInterfaces);
361 + ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
362 + routerLsa = ospfArea.buildRouterLsa(ospfInterface1);
363 + assertThat(routerLsa, is(notNullValue()));
364 + }
365 +
366 + /**
367 + * Tests areaId() getter method.
368 + */
369 + @Test
370 + public void testGetAreaId() throws Exception {
371 + ospfArea.setAreaId(Ip4Address.valueOf("1.1.1.1"));
372 + assertThat(ospfArea.areaId(), is(Ip4Address.valueOf("1.1.1.1")));
373 + }
374 +
375 + /**
376 + * Tests areaId() setter method.
377 + */
378 + @Test
379 + public void testSetAreaId() throws Exception {
380 + ospfArea.setAreaId(Ip4Address.valueOf("1.1.1.1"));
381 + assertThat(ospfArea.areaId(), is(Ip4Address.valueOf("1.1.1.1")));
382 + }
383 +
384 + /**
385 + * Tests addressRanges() getter method.
386 + */
387 + @Test
388 + public void testGetAddressRanges() throws Exception {
389 + ospfAreaAddressRanges = new ArrayList();
390 + ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
391 + ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
392 + ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
393 + ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
394 + ospfArea.setAddressRanges(ospfAreaAddressRanges);
395 + assertThat(ospfArea.addressRanges().size(), is(4));
396 + }
397 +
398 + /**
399 + * Tests addressRanges() setter method.
400 + */
401 + @Test
402 + public void testSetAddressRanges() throws Exception {
403 + ospfAreaAddressRanges = new ArrayList();
404 + ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
405 + ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
406 + ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
407 + ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
408 + ospfArea.setAddressRanges(ospfAreaAddressRanges);
409 + assertThat(ospfArea.addressRanges().size(), is(4));
410 + }
411 +
412 + /**
413 + * Tests isTransitCapability() getter method.
414 + */
415 + @Test
416 + public void testIsTransitCapability() throws Exception {
417 + ospfArea.setTransitCapability(true);
418 + assertThat(ospfArea.isTransitCapability(), is(true));
419 + }
420 +
421 + /**
422 + * Tests isTransitCapability() setter method.
423 + */
424 + @Test
425 + public void testSetTransitCapability() throws Exception {
426 + ospfArea.setTransitCapability(true);
427 + assertThat(ospfArea.isTransitCapability(), is(true));
428 + }
429 +
430 + /**
431 + * Tests isExternalRoutingCapability() getter method.
432 + */
433 + @Test
434 + public void testIsExternalRoutingCapability() throws Exception {
435 + ospfArea.setExternalRoutingCapability(true);
436 + assertThat(ospfArea.isExternalRoutingCapability(), is(true));
437 + }
438 +
439 + /**
440 + * Tests isExternalRoutingCapability() setter method.
441 + */
442 + @Test
443 + public void testSetExternalRoutingCapability() throws Exception {
444 + ospfArea.setExternalRoutingCapability(true);
445 + assertThat(ospfArea.isExternalRoutingCapability(), is(true));
446 + }
447 +
448 + /**
449 + * Tests stubCost() getter method.
450 + */
451 + @Test
452 + public void testGetStubCost() throws Exception {
453 + ospfArea.setStubCost(100);
454 + assertThat(ospfArea.stubCost(), is(100));
455 + }
456 +
457 + /**
458 + * Tests stubCost() setter method.
459 + */
460 + @Test
461 + public void testSetStubCost() throws Exception {
462 + ospfArea.setStubCost(100);
463 + assertThat(ospfArea.stubCost(), is(100));
464 + }
465 +
466 + /**
467 + * Tests getInterfacesLst() getter method.
468 + */
469 + @Test
470 + public void testGetInterfacesLst() throws Exception {
471 + ospfInterfaces = new ArrayList();
472 + ospfInterface1 = new OspfInterfaceImpl();
473 + ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
474 + ospfInterfaces.add(ospfInterface1);
475 + ospfInterface2 = new OspfInterfaceImpl();
476 + ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
477 + ospfInterfaces.add(ospfInterface2);
478 + ospfInterface3 = new OspfInterfaceImpl();
479 + ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
480 + ospfInterfaces.add(ospfInterface3);
481 + ospfArea.setInterfacesLst(ospfInterfaces);
482 + assertThat(ospfInterfaces.size(), is(3));
483 + assertThat(ospfArea.getInterfacesLst(), is(notNullValue()));
484 + }
485 +
486 + /**
487 + * Tests setInterfacesLst() setter method.
488 + */
489 + @Test
490 + public void testSetInterfacesLst() throws Exception {
491 + ospfInterfaces = new ArrayList();
492 + ospfInterface1 = new OspfInterfaceImpl();
493 + ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
494 + ospfInterfaces.add(ospfInterface1);
495 + ospfInterface2 = new OspfInterfaceImpl();
496 + ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
497 + ospfInterfaces.add(ospfInterface2);
498 + ospfInterface3 = new OspfInterfaceImpl();
499 + ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
500 + ospfInterfaces.add(ospfInterface3);
501 + ospfArea.setInterfacesLst(ospfInterfaces);
502 + assertThat(ospfInterfaces.size(), is(3));
503 + assertThat(ospfArea.getInterfacesLst(), is(notNullValue()));
504 + }
505 +
506 + /**
507 + * Tests noNeighborInLsaExchangeProcess() method.
508 + */
509 + @Test
510 + public void testNoNeighborInLsaExchangeProcess() throws Exception {
511 + ospfInterfaces = new ArrayList();
512 + ospfInterface1 = new OspfInterfaceImpl();
513 + ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
514 + ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
515 + Ip4Address.valueOf("1.1.1.1"),
516 + Ip4Address.valueOf("2.2.2.2"), 2,
517 + new OspfInterfaceChannelHandler(new Controller(),
518 + new OspfAreaImpl(),
519 + new OspfInterfaceImpl())
520 + , topologyForDeviceAndLink);
521 + ospfNbr.setState(OspfNeighborState.EXCHANGE.EXCHANGE);
522 + ospfInterface1.addNeighbouringRouter(ospfNbr);
523 + ospfInterfaces.add(ospfInterface1);
524 + ospfArea.setInterfacesLst(ospfInterfaces);
525 + assertThat(ospfArea.noNeighborInLsaExchangeProcess(), is(false));
526 + }
527 +
528 + /**
529 + * Tests getLsaHeaders() method.
530 + */
531 + @Test
532 + public void testGetLsaHeaders() throws Exception {
533 + assertThat(ospfArea.getLsaHeaders(true, true).size(), is(0));
534 + }
535 +
536 + /**
537 + * Tests getLsa() method.
538 + */
539 + @Test
540 + public void testGetLsa() throws Exception {
541 + assertThat(ospfArea.getLsa(1, "1.1.1.1", "1.1.1.1"), is(nullValue()));
542 + assertThat(ospfArea.getLsa(10, "1.1.1.1", "1.1.1.1"), is(nullValue()));
543 + }
544 +
545 + /**
546 + * Tests lsaLookup() method.
547 + */
548 + @Test
549 + public void testLsaLookup() throws Exception {
550 + assertThat(ospfArea.lsaLookup(new RouterLsa()), is(nullValue()));
551 + }
552 +
553 + /**
554 + * Tests isNewerOrSameLsa() method.
555 + */
556 + @Test
557 + public void testIsNewerOrSameLsa() throws Exception {
558 + assertThat(ospfArea.isNewerOrSameLsa(new RouterLsa(), new RouterLsa()), is("same"));
559 + }
560 +
561 + /**
562 + * Tests addLsa() method.
563 + */
564 + @Test
565 + public void testAddLsa() throws Exception {
566 + ospfArea.addLsa(new RouterLsa(), new OspfInterfaceImpl());
567 + assertThat(ospfArea, is(notNullValue()));
568 + }
569 +
570 + /**
571 + * Tests addLsa() method.
572 + */
573 + @Test
574 + public void testAddLsa1() throws Exception {
575 + ospfArea.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
576 + assertThat(ospfArea, is(notNullValue()));
577 + }
578 +
579 + /**
580 + * Tests addLsaToMaxAgeBin() method.
581 + */
582 + @Test
583 + public void testAddLsaToMaxAgeBin() throws Exception {
584 + ospfArea.addLsaToMaxAgeBin("111", new LsaWrapperImpl());
585 + assertThat(ospfArea, is(notNullValue()));
586 + }
587 +
588 + /**
589 + * Tests setDbRouterSequenceNumber() method.
590 + */
591 + @Test
592 + public void testSetDbRouterSequenceNumber() throws Exception {
593 + ospfArea.setDbRouterSequenceNumber(123456);
594 + assertThat(ospfArea, is(notNullValue()));
595 + }
596 +
597 + /**
598 + * Tests deleteLsa() method.
599 + */
600 + @Test
601 + public void testDeleteLsa() throws Exception {
602 + ospfArea.deleteLsa(new LsaHeader());
603 + assertThat(ospfArea, is(notNullValue()));
604 + }
605 +
606 + /**
607 + * Tests removeLsaFromBin() method.
608 + */
609 + @Test
610 + public void testRemoveLsaFromBin() throws Exception {
611 + ospfArea.removeLsaFromBin(new LsaWrapperImpl());
612 + assertThat(ospfArea, is(notNullValue()));
613 + }
614 +
615 + /**
616 + * Tests to string method.
617 + */
618 + @Test
619 + public void testToString() throws Exception {
620 + assertThat(ospfArea.toString(), is(notNullValue()));
621 + }
622 +
623 + /**
624 + * Tests getNeighborsInFullState() method.
625 + */
626 + @Test
627 + public void testGetNeighborsinFullState() throws Exception {
628 + ospfInterfaces = new ArrayList();
629 + ospfInterface1 = new OspfInterfaceImpl();
630 + ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
631 + ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
632 + Ip4Address.valueOf("1.1.1.1"),
633 + Ip4Address.valueOf("2.2.2.2"), 2,
634 + new OspfInterfaceChannelHandler(new Controller(),
635 + new OspfAreaImpl(),
636 + new OspfInterfaceImpl())
637 + , topologyForDeviceAndLink);
638 + ospfNbr.setState(OspfNeighborState.FULL);
639 + ospfInterface1.addNeighbouringRouter(ospfNbr);
640 + ospfInterfaces.add(ospfInterface1);
641 + ospfArea.setInterfacesLst(ospfInterfaces);
642 + assertThat(ospfArea.getNeighborsInFullState(ospfInterface1).size(), is(1));
643 + }
644 +
645 + /**
646 + * Tests getLsaKey() method.
647 + */
648 + @Test
649 + public void testGetLsaKey() throws Exception {
650 + lsaHeader = new LsaHeader();
651 + lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1"));
652 + assertThat(ospfArea.getLsaKey(lsaHeader), is(notNullValue()));
653 + }
654 +
655 + /**
656 + * Tests addToOtherNeighborLsaTxList() method.
657 + */
658 + @Test
659 + public void testAddToOtherNeighborLsaTxList() throws Exception {
660 + ospfInterfaces = new ArrayList();
661 + ospfInterface1 = new OspfInterfaceImpl();
662 + ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
663 + ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
664 + Ip4Address.valueOf("1.1.1.1"),
665 + Ip4Address.valueOf("2.2.2.2"), 2,
666 + new OspfInterfaceChannelHandler(new Controller(),
667 + new OspfAreaImpl(),
668 + new OspfInterfaceImpl())
669 + , topologyForDeviceAndLink);
670 + ospfNbr.setState(OspfNeighborState.FULL);
671 + ospfInterface1.addNeighbouringRouter(ospfNbr);
672 + ospfInterfaces.add(ospfInterface1);
673 + ospfArea.setInterfacesLst(ospfInterfaces);
674 + lsaHeader = new LsaHeader();
675 + lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1"));
676 + ospfArea.addToOtherNeighborLsaTxList(lsaHeader);
677 + assertThat(ospfArea, is(notNullValue()));
678 + }
679 +
680 + /**
681 + * Tests options() getter method.
682 + */
683 + @Test
684 + public void testGetOptions() throws Exception {
685 + ospfArea.setOptions(2);
686 + assertThat(ospfArea.options(), is(2));
687 + }
688 +
689 + /**
690 + * Tests options() setter method.
691 + */
692 + @Test
693 + public void testSetOptions() throws Exception {
694 + ospfArea.setOptions(2);
695 + assertThat(ospfArea.options(), is(2));
696 + }
697 +
698 + /**
699 + * Tests isOpaqueEnabled() method.
700 + */
701 + @Test
702 + public void testGetOpaqueEnabledOptions() throws Exception {
703 + ospfArea.setIsOpaqueEnabled(true);
704 + assertThat(ospfArea.isOpaqueEnabled(), is(true));
705 + }
706 +
707 + /**
708 + * Tests database() method.
709 + */
710 + @Test
711 + public void testGetDatabase() throws Exception {
712 + assertThat(ospfArea.database(), is(notNullValue()));
713 + }
714 +
715 + /**
716 + * Tests opaqueEnabledOptions() method.
717 + */
718 + @Test
719 + public void testOpaqueEnabledOptionsa() throws Exception {
720 + assertThat(ospfArea.opaqueEnabledOptions(), is(66));
721 + }
722 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
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 +package org.onosproject.ospf.controller.lsdb;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +import org.onosproject.ospf.controller.LsaWrapper;
22 +import org.onosproject.ospf.protocol.lsa.LsaHeader;
23 +
24 +import static org.hamcrest.CoreMatchers.is;
25 +import static org.hamcrest.CoreMatchers.notNullValue;
26 +import static org.hamcrest.MatcherAssert.assertThat;
27 +
28 +/**
29 + * Unit test class for LsaBinImpl.
30 + */
31 +public class LsaBinImplTest {
32 + private LsaBinImpl lsaBin;
33 + private LsaHeader ospflsa1;
34 + private LsaWrapper lsaWrapper;
35 +
36 +
37 + @Before
38 + public void setUp() throws Exception {
39 + ospflsa1 = new LsaHeader();
40 + ospflsa1.setAge(20);
41 + lsaBin = new LsaBinImpl(1);
42 + }
43 +
44 + @After
45 + public void tearDown() throws Exception {
46 + ospflsa1 = null;
47 + lsaBin = null;
48 + }
49 +
50 + /**
51 + * Tests binNumber() getter method.
52 + */
53 + @Test
54 + public void testGetBinNumber() throws Exception {
55 + lsaWrapper = new LsaWrapperImpl();
56 + lsaBin.addOspfLsa("lsa1", lsaWrapper);
57 + assertThat(lsaBin.binNumber(), is(1));
58 + }
59 +
60 + /**
61 + * Tests addOspfLsa() method.
62 + */
63 + @Test
64 + public void testAddOspfLsa() throws Exception {
65 + LsaWrapper lsaWrapper = new LsaWrapperImpl();
66 + lsaBin.addOspfLsa("lsa1", lsaWrapper);
67 + assertThat(lsaBin, is(notNullValue()));
68 + }
69 +
70 + /**
71 + * Tests ospfLsa() getter method.
72 + */
73 + @Test
74 + public void testGetOspfLsa() throws Exception {
75 + lsaWrapper = new LsaWrapperImpl();
76 + lsaBin.addOspfLsa("lsa1", lsaWrapper);
77 + assertThat(lsaBin, is(notNullValue()));
78 + assertThat(lsaBin.ospfLsa("lsa1"), is(lsaWrapper));
79 + }
80 +
81 + /**
82 + * Tests removeOspfLsa() method.
83 + */
84 + @Test
85 + public void testRemoveOspfLsa() throws Exception {
86 + lsaWrapper = new LsaWrapperImpl();
87 + lsaBin.addOspfLsa("lsa1", lsaWrapper);
88 + lsaBin.removeOspfLsa("lsa1", lsaWrapper);
89 + assertThat(lsaBin, is(notNullValue()));
90 + }
91 +
92 + /**
93 + * Tests listOfLsa() method.
94 + */
95 + @Test
96 + public void testGetListOfLsa() throws Exception {
97 + lsaWrapper = new LsaWrapperImpl();
98 + lsaBin.addOspfLsa("lsa1", lsaWrapper);
99 + assertThat(lsaBin.listOfLsa().size(), is(1));
100 + }
101 +
102 + /**
103 + * Tests to string method.
104 + */
105 + @Test
106 + public void testToString() throws Exception {
107 + assertThat(lsaBin.toString(), is(notNullValue()));
108 + }
109 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
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 +package org.onosproject.ospf.controller.lsdb;
17 +
18 +import org.easymock.EasyMock;
19 +import org.jboss.netty.channel.Channel;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onosproject.ospf.controller.LsaWrapper;
24 +import org.onosproject.ospf.controller.OspfArea;
25 +import org.onosproject.ospf.controller.OspfLsaType;
26 +import org.onosproject.ospf.controller.area.OspfAreaImpl;
27 +import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
28 +import org.onosproject.ospf.protocol.lsa.LsaHeader;
29 +import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
30 +import org.onosproject.ospf.protocol.util.OspfInterfaceState;
31 +
32 +import java.util.concurrent.ArrayBlockingQueue;
33 +import java.util.concurrent.BlockingQueue;
34 +
35 +import static org.hamcrest.CoreMatchers.is;
36 +import static org.hamcrest.CoreMatchers.notNullValue;
37 +import static org.hamcrest.MatcherAssert.assertThat;
38 +
39 +/**
40 + * Unit test class for LsaQueueConsumer.
41 + */
42 +public class LsaQueueConsumerTest {
43 + private LsaQueueConsumer lsaQueueConsumer;
44 + private BlockingQueue<LsaWrapper> blockingQueue;
45 + private Channel channel;
46 + private LsaWrapperImpl lsaWrapper;
47 + private OspfArea ospfArea;
48 + private RouterLsa routerLsa;
49 + private OspfInterfaceImpl ospfInterface;
50 + private LsaHeader lsaHeader;
51 + private LsdbAgeImpl lsdbAge;
52 +
53 + @Before
54 + public void setUp() throws Exception {
55 + lsaQueueConsumer = EasyMock.createMock(LsaQueueConsumer.class);
56 + }
57 +
58 + @After
59 + public void tearDown() throws Exception {
60 + lsaQueueConsumer = null;
61 + blockingQueue = null;
62 + channel = null;
63 + lsaWrapper = null;
64 + lsdbAge = null;
65 + lsaHeader = null;
66 + ospfInterface = null;
67 + ospfArea = null;
68 + routerLsa = null;
69 + }
70 +
71 + /**
72 + * Tests run() method.
73 + */
74 + @Test
75 + public void testRun() throws Exception {
76 + blockingQueue = new ArrayBlockingQueue(5);
77 + channel = EasyMock.createMock(Channel.class);
78 + ospfArea = new OspfAreaImpl();
79 + lsaWrapper = new LsaWrapperImpl();
80 + lsaWrapper.setLsaProcessing("verifyChecksum");
81 + blockingQueue.add(lsaWrapper);
82 + lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea);
83 + lsaQueueConsumer.run();
84 + assertThat(lsaQueueConsumer, is(notNullValue()));
85 + }
86 +
87 + /**
88 + * Tests run() method.
89 + */
90 + @Test
91 + public void testRun1() throws Exception {
92 + blockingQueue = new ArrayBlockingQueue(5);
93 + channel = EasyMock.createMock(Channel.class);
94 + ospfArea = new OspfAreaImpl();
95 + lsaWrapper = new LsaWrapperImpl();
96 + routerLsa = new RouterLsa();
97 + routerLsa.setLsType(1);
98 + lsaWrapper.addLsa(OspfLsaType.ROUTER, routerLsa);
99 + ospfInterface = new OspfInterfaceImpl();
100 + ospfInterface.setState(OspfInterfaceState.DR);
101 + lsaWrapper.setOspfInterface(ospfInterface);
102 + lsaWrapper.setIsSelfOriginated(true);
103 + lsaHeader = new LsaHeader();
104 + lsaHeader.setLsType(1);
105 + lsaWrapper.setLsaHeader(lsaHeader);
106 + lsaWrapper.setLsaProcessing("refreshLsa");
107 + lsaWrapper.setLsdbAge(new LsdbAgeImpl(new OspfAreaImpl()));
108 + blockingQueue.add(lsaWrapper);
109 + lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea);
110 + lsaQueueConsumer.run();
111 + assertThat(lsaQueueConsumer, is(notNullValue()));
112 + }
113 +
114 + @Test
115 + public void testRun3() throws Exception {
116 + blockingQueue = new ArrayBlockingQueue(5);
117 + channel = EasyMock.createMock(Channel.class);
118 + ospfArea = new OspfAreaImpl();
119 + lsaWrapper = new LsaWrapperImpl();
120 + routerLsa = new RouterLsa();
121 + routerLsa.setLsType(2);
122 + lsaWrapper.addLsa(OspfLsaType.NETWORK, routerLsa);
123 + ospfInterface = new OspfInterfaceImpl();
124 + ospfInterface.setState(OspfInterfaceState.BDR);
125 + lsaWrapper.setOspfInterface(ospfInterface);
126 + lsaWrapper.setIsSelfOriginated(true);
127 + lsaHeader = new LsaHeader();
128 + lsaHeader.setLsType(2);
129 + lsaWrapper.setLsaHeader(lsaHeader);
130 + lsaWrapper.setLsaProcessing("refreshLsa");
131 + lsaWrapper.setLsdbAge(new LsdbAgeImpl(new OspfAreaImpl()));
132 + blockingQueue.add(lsaWrapper);
133 + lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea);
134 + lsaQueueConsumer.run();
135 + assertThat(lsaQueueConsumer, is(notNullValue()));
136 + }
137 +
138 + /**
139 + * Tests run() method.
140 + */
141 + @Test
142 + public void testRun5() throws Exception {
143 + blockingQueue = new ArrayBlockingQueue(5);
144 + channel = EasyMock.createMock(Channel.class);
145 + ospfArea = new OspfAreaImpl();
146 + lsaWrapper = new LsaWrapperImpl();
147 + routerLsa = new RouterLsa();
148 + routerLsa.setLsType(2);
149 + lsaWrapper.addLsa(OspfLsaType.NETWORK, routerLsa);
150 + ospfInterface = new OspfInterfaceImpl();
151 + ospfInterface.setState(OspfInterfaceState.DR);
152 + lsaWrapper.setOspfInterface(ospfInterface);
153 + lsaWrapper.setIsSelfOriginated(true);
154 + lsaHeader = new LsaHeader();
155 + lsaHeader.setLsType(2);
156 + lsaWrapper.setLsaHeader(lsaHeader);
157 + lsaWrapper.setLsaProcessing("maxAgeLsa");
158 + lsaWrapper.setLsdbAge(new LsdbAgeImpl(new OspfAreaImpl()));
159 + blockingQueue.add(lsaWrapper);
160 + lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea);
161 + lsaQueueConsumer.run();
162 + assertThat(lsaQueueConsumer, is(notNullValue()));
163 + }
164 +
165 + /**
166 + * Tests setChannel() method.
167 + */
168 + @Test
169 + public void testSetChannel() throws Exception {
170 + channel = EasyMock.createMock(Channel.class);
171 + lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
172 + lsdbAge.startDbAging();
173 + lsdbAge.setChannel(channel);
174 + assertThat(lsaQueueConsumer, is(notNullValue()));
175 + }
176 +
177 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
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 +package org.onosproject.ospf.controller.lsdb;
17 +
18 +import org.easymock.EasyMock;
19 +import org.junit.After;
20 +import org.junit.Before;
21 +import org.junit.Test;
22 +import org.onosproject.ospf.controller.OspfLsaType;
23 +import org.onosproject.ospf.controller.area.OspfAreaImpl;
24 +import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
25 +import org.onosproject.ospf.protocol.lsa.LsaHeader;
26 +import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
27 +
28 +import static org.hamcrest.CoreMatchers.*;
29 +import static org.hamcrest.MatcherAssert.assertThat;
30 +
31 +/**
32 + * Unit test class for LsaWrapperImpl.
33 + */
34 +public class LsaWrapperImplTest {
35 +
36 + private LsaWrapperImpl lsaWrapper;
37 + private LsdbAgeImpl lsdbAge;
38 + private LsaHeader header;
39 + private OspfInterfaceImpl ospfInterfaceImpl;
40 +
41 + @Before
42 + public void setUp() throws Exception {
43 + lsaWrapper = new LsaWrapperImpl();
44 + }
45 +
46 + @After
47 + public void tearDown() throws Exception {
48 + lsaWrapper = null;
49 + header = null;
50 + lsdbAge = null;
51 + ospfInterfaceImpl = null;
52 + }
53 +
54 + /**
55 + * Tests lsaType() getter method.
56 + */
57 + @Test
58 + public void testGetLsaType() throws Exception {
59 + lsaWrapper.setLsaType(OspfLsaType.ROUTER);
60 + assertThat(lsaWrapper.lsaType(), is(OspfLsaType.ROUTER));
61 + }
62 +
63 + /**
64 + * Tests lsaType() setter method.
65 + */
66 + @Test
67 + public void testSetLsaType() throws Exception {
68 + lsaWrapper.setLsaType(OspfLsaType.ROUTER);
69 + assertThat(lsaWrapper.lsaType(), is(OspfLsaType.ROUTER));
70 + }
71 +
72 + /**
73 + * Tests isSelfOriginated() getter method.
74 + */
75 + @Test
76 + public void testIsSelfOriginated() throws Exception {
77 + lsaWrapper.setIsSelfOriginated(true);
78 + assertThat(lsaWrapper.isSelfOriginated(), is(true));
79 + }
80 +
81 + /**
82 + * Tests isSelfOriginated() setter method.
83 + */
84 + @Test
85 + public void testSetIsSelfOriginated() throws Exception {
86 + lsaWrapper.setIsSelfOriginated(true);
87 + assertThat(lsaWrapper.isSelfOriginated(), is(true));
88 + }
89 +
90 + /**
91 + * Tests addLsa() method.
92 + */
93 + @Test
94 + public void testAddLSA() throws Exception {
95 + lsaWrapper.addLsa(OspfLsaType.ROUTER, new RouterLsa());
96 + assertThat(lsaWrapper, is(notNullValue()));
97 + }
98 +
99 + /**
100 + * Tests lsaAgeReceived() getter method.
101 + */
102 + @Test
103 + public void testGetLsaAgeReceived() throws Exception {
104 + lsaWrapper.setLsaAgeReceived(10);
105 + assertThat(lsaWrapper.lsaAgeReceived(), is(10));
106 + }
107 +
108 + /**
109 + * Tests lsaAgeReceived() setter method.
110 + */
111 + @Test
112 + public void testSetLsaAgeReceived() throws Exception {
113 + lsaWrapper.setLsaAgeReceived(10);
114 + assertThat(lsaWrapper.lsaAgeReceived(), is(10));
115 + }
116 +
117 + /**
118 + * Tests lsaHeader() getter method.
119 + */
120 + @Test
121 + public void testGetLsaHeader() throws Exception {
122 + lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
123 + lsdbAge.ageLsaAndFlood();
124 + lsaWrapper.setLsdbAge(lsdbAge);
125 + header = new LsaHeader();
126 + lsaWrapper.setLsaHeader(header);
127 + assertThat(lsaWrapper.lsaHeader(), instanceOf(LsaHeader.class));
128 + }
129 +
130 + /**
131 + * Tests lsaHeader() setter method.
132 + */
133 + @Test
134 + public void testSetLsaHeader() throws Exception {
135 + lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
136 + lsdbAge.ageLsaAndFlood();
137 + lsaWrapper.setLsdbAge(lsdbAge);
138 + header = new LsaHeader();
139 + lsaWrapper.setLsaHeader(header);
140 + assertThat(lsaWrapper.lsaHeader(), instanceOf(LsaHeader.class));
141 + }
142 +
143 + /**
144 + * Tests setOspfLsa() setter method.
145 + */
146 + @Test
147 + public void testSetOspfLsa() throws Exception {
148 + lsaWrapper.setOspfLsa(new RouterLsa());
149 + assertThat(lsaWrapper, is(notNullValue()));
150 + }
151 +
152 + /**
153 + * Tests noReTransmissionLists() getter method.
154 + */
155 + @Test
156 + public void testGetNoReTransmissionLists() throws Exception {
157 + lsaWrapper.setNoReTransmissionLists(10);
158 + assertThat(lsaWrapper.noReTransmissionLists(), is(10));
159 + }
160 +
161 + /**
162 + * Tests noReTransmissionLists() setter method.
163 + */
164 + @Test
165 + public void testSetNoReTransmissionLists() throws Exception {
166 + lsaWrapper.setNoReTransmissionLists(10);
167 + assertThat(lsaWrapper.noReTransmissionLists(), is(10));
168 + }
169 +
170 + /**
171 + * Tests isInAnAgeBin() getter method.
172 + */
173 + @Test
174 + public void testIsInAnAgeBin() throws Exception {
175 + lsaWrapper.setInAnAgeBin(true);
176 + assertThat(lsaWrapper.isInAnAgeBin(), is(true));
177 + }
178 +
179 + /**
180 + * Tests isInAnAgeBin() setter method.
181 + */
182 + @Test
183 + public void testSetInAnAgeBin() throws Exception {
184 + lsaWrapper.setInAnAgeBin(true);
185 + assertThat(lsaWrapper.isInAnAgeBin(), is(true));
186 + }
187 +
188 + /**
189 + * Tests isChangedSinceLastFlood() getter method.
190 + */
191 + @Test
192 + public void testIsChangedSinceLastFlood() throws Exception {
193 + lsaWrapper.setChangedSinceLastFlood(true);
194 + assertThat(lsaWrapper.isChangedSinceLastFlood(), is(true));
195 + }
196 +
197 + /**
198 + * Tests isChangedSinceLastFlood() setter method.
199 + */
200 + @Test
201 + public void testSetChangedSinceLastFlood() throws Exception {
202 + lsaWrapper.setChangedSinceLastFlood(true);
203 + assertThat(lsaWrapper.isChangedSinceLastFlood(), is(true));
204 + }
205 +
206 + /**
207 + * Tests isSequenceRollOver() method.
208 + */
209 + @Test
210 + public void testIsSequenceRollOver() throws Exception {
211 + lsaWrapper.setIsSequenceRollOver(true);
212 + assertThat(lsaWrapper.isSequenceRollOver(), is(true));
213 + }
214 +
215 + /**
216 + * Tests isSentReplyForOlderLsa() method.
217 + */
218 + @Test
219 + public void testIsSentReplyForOlderLSA() throws Exception {
220 + lsaWrapper.setSentReplyForOlderLsa(true);
221 + assertThat(lsaWrapper.isSentReplyForOlderLsa(), is(true));
222 + }
223 +
224 + /**
225 + * Tests isCheckAge() getter method.
226 + */
227 + @Test
228 + public void testIsCheckAge() throws Exception {
229 + lsaWrapper.setCheckAge(true);
230 + assertThat(lsaWrapper.isCheckAge(), is(true));
231 + }
232 +
233 + /**
234 + * Tests isCheckAge() setter method.
235 + */
236 + @Test
237 + public void testIsSentReplyForOlderLsa() throws Exception {
238 + lsaWrapper.setIsSequenceRollOver(true);
239 + assertThat(lsaWrapper.isSequenceRollOver(), is(true));
240 + }
241 +
242 + /**
243 + * Tests isSentReplyForOlderLsa() getter method.
244 + */
245 + @Test
246 + public void testSetSentReplyForOlderLsa() throws Exception {
247 + lsaWrapper.setSentReplyForOlderLsa(true);
248 + assertThat(lsaWrapper.isSentReplyForOlderLsa(), is(true));
249 + }
250 +
251 + /**
252 + * Tests isSentReplyForOlderLsa() setter method.
253 + */
254 + @Test
255 + public void testSetCheckAge() throws Exception {
256 + lsaWrapper.setCheckAge(true);
257 + assertThat(lsaWrapper.isCheckAge(), is(true));
258 + }
259 +
260 + /**
261 + * Tests isAging() getter method.
262 + */
263 + @Test
264 + public void testIsAging() throws Exception {
265 + lsaWrapper.setIsAging(true);
266 + assertThat(lsaWrapper.isAging(), is(true));
267 + }
268 +
269 + /**
270 + * Tests isAging() setter method.
271 + */
272 + @Test
273 + public void testSetIsAging() throws Exception {
274 + lsaWrapper.setIsAging(true);
275 + assertThat(lsaWrapper.isAging(), is(true));
276 + }
277 +
278 + /**
279 + * Tests currentAge() method.
280 + */
281 + @Test
282 + public void testGetCurrentAge() throws Exception {
283 + lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
284 + lsdbAge.ageLsaAndFlood();
285 + lsaWrapper.setLsdbAge(lsdbAge);
286 + assertThat(lsaWrapper.currentAge(), is(notNullValue()));
287 + }
288 +
289 + /**
290 + * Tests ageCounterWhenReceived() getter method.
291 + */
292 + @Test
293 + public void testGetAgeCounterWhenReceived() throws Exception {
294 + lsaWrapper.setAgeCounterWhenReceived(10);
295 + assertThat(lsaWrapper.ageCounterWhenReceived(), is(10));
296 + }
297 +
298 + /**
299 + * Tests ageCounterWhenReceived() setter method.
300 + */
301 + @Test
302 + public void testSetAgeCounterWhenReceived() throws Exception {
303 + lsaWrapper.setAgeCounterWhenReceived(10);
304 + assertThat(lsaWrapper.ageCounterWhenReceived(), is(10));
305 + }
306 +
307 + /**
308 + * Tests lsaProcessing() getter method.
309 + */
310 + @Test
311 + public void testGetLsaProcessing() throws Exception {
312 + lsaWrapper.setLsaProcessing("router");
313 + assertThat(lsaWrapper.lsaProcessing(), is("router"));
314 + }
315 +
316 + /**
317 + * Tests lsaProcessing() setter method.
318 + */
319 + @Test
320 + public void testSetLsaProcessing() throws Exception {
321 + lsaWrapper.setLsaProcessing("router");
322 + assertThat(lsaWrapper.lsaProcessing(), is("router"));
323 + }
324 +
325 + /**
326 + * Tests binNumber() getter method.
327 + */
328 + @Test
329 + public void testGetBinNumber() throws Exception {
330 + lsaWrapper.setBinNumber(10);
331 + assertThat(lsaWrapper.binNumber(), is(10));
332 + }
333 +
334 + /**
335 + * Tests binNumber() setter method.
336 + */
337 + @Test
338 + public void testSetBinNumber() throws Exception {
339 + lsaWrapper.setBinNumber(10);
340 + assertThat(lsaWrapper.binNumber(), is(10));
341 + }
342 +
343 + /**
344 + * Tests ospfInterface() getter method.
345 + */
346 + @Test
347 + public void testGetOspfInterface() throws Exception {
348 + ospfInterfaceImpl = EasyMock.createMock(OspfInterfaceImpl.class);
349 + lsaWrapper.setOspfInterface(ospfInterfaceImpl);
350 + assertThat(lsaWrapper.ospfInterface(), is(notNullValue()));
351 + }
352 +
353 + /**
354 + * Tests ospfInterface() setter method.
355 + */
356 + @Test
357 + public void testSetOspfInterface() throws Exception {
358 + ospfInterfaceImpl = EasyMock.createMock(OspfInterfaceImpl.class);
359 + lsaWrapper.setOspfInterface(ospfInterfaceImpl);
360 + assertThat(lsaWrapper.ospfInterface(), is(notNullValue()));
361 + }
362 +
363 + /**
364 + * Tests getLsdbAge() method.
365 + */
366 + @Test
367 + public void testGetLsdbAge() throws Exception {
368 + assertThat(lsaWrapper.getLsdbAge(), is(nullValue()));
369 + }
370 +
371 + /**
372 + * Tests to string method.
373 + */
374 + @Test
375 + public void testToString() throws Exception {
376 + assertThat(lsaWrapper.toString(), is(notNullValue()));
377 + }
378 +
379 + /**
380 + * Tests equals() method.
381 + */
382 + @Test
383 + public void testEquals() throws Exception {
384 + assertThat(lsaWrapper.equals(new LsaWrapperImpl()), is(true));
385 + }
386 +
387 + /**
388 + * Tests hashCode() method.
389 + */
390 + @Test
391 + public void testHashCode() throws Exception {
392 + int hashCode = lsaWrapper.hashCode();
393 + assertThat(hashCode, is(notNullValue()));
394 + }
395 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
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 +package org.onosproject.ospf.controller.lsdb;
17 +
18 +import org.easymock.EasyMock;
19 +import org.jboss.netty.channel.Channel;
20 +import org.junit.After;
21 +import org.junit.Assert;
22 +import org.junit.Before;
23 +import org.junit.Test;
24 +import org.onosproject.ospf.controller.LsaBin;
25 +import org.onosproject.ospf.controller.OspfArea;
26 +import org.onosproject.ospf.controller.area.OspfAreaImpl;
27 +
28 +import static org.hamcrest.CoreMatchers.*;
29 +import static org.hamcrest.MatcherAssert.assertThat;
30 +
31 +/**
32 + * Unit test class for LsdbAgeImpl.
33 + */
34 +public class LsdbAgeImplTest {
35 + private LsdbAgeImpl lsdbAge;
36 + private OspfAreaImpl ospfAreaImpl;
37 + private LsaBinImpl lsaBin;
38 + private LsaBin lsaBin1;
39 + private LsaWrapperImpl lsaWrapper;
40 + private OspfArea ospfArea;
41 + private Channel channel;
42 +
43 + @Before
44 + public void setUp() throws Exception {
45 + ospfAreaImpl = EasyMock.createMock(OspfAreaImpl.class);
46 + lsdbAge = new LsdbAgeImpl(ospfAreaImpl);
47 + }
48 +
49 + @After
50 + public void tearDown() throws Exception {
51 + lsdbAge = null;
52 + lsaBin = null;
53 + lsaBin1 = null;
54 + ospfAreaImpl = null;
55 + lsaWrapper = null;
56 + channel = null;
57 + ospfArea = null;
58 + }
59 +
60 + /**
61 + * Tests getLsaBin() method.
62 + */
63 + @Test
64 + public void testGetLsaBin() throws Exception {
65 + lsaBin = new LsaBinImpl(1);
66 + lsdbAge.addLsaBin(1, lsaBin);
67 + assertThat(lsdbAge, is(notNullValue()));
68 + lsaBin1 = lsdbAge.getLsaBin(1);
69 + assertThat(lsaBin, instanceOf(LsaBin.class));
70 + assertThat(lsaBin1, instanceOf(LsaBin.class));
71 + }
72 +
73 + /**
74 + * Tests addLsaBin() method.
75 + */
76 + @Test
77 + public void testAddLsaBin() throws Exception {
78 + lsaBin = new LsaBinImpl(1);
79 + lsdbAge.addLsaBin(1, lsaBin);
80 + assertThat(lsdbAge, is(notNullValue()));
81 + assertThat(lsaBin, instanceOf(LsaBin.class));
82 + }
83 +
84 + /**
85 + * Tests equals() method.
86 + */
87 + @Test
88 + public void testEquals() throws Exception {
89 + assertThat(lsdbAge.equals(lsdbAge), is(true));
90 + }
91 +
92 + /**
93 + * Tests hashCode() method.
94 + */
95 + @Test
96 + public void testHashCode() throws Exception {
97 + int hashCode = lsdbAge.hashCode();
98 + assertThat(hashCode, is(notNullValue()));
99 + }
100 +
101 + /**
102 + * Tests addLsaToMaxAgeBin() method.
103 + */
104 + @Test
105 + public void testAddLsaToMaxAgeBin() throws Exception {
106 + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
107 + lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
108 + assertThat(lsdbAge, is(notNullValue()));
109 + }
110 +
111 + /**
112 + * Tests removeLsaFromBin() method.
113 + */
114 + @Test
115 + public void testRemoveLsaFromBin() throws Exception {
116 + lsaBin = EasyMock.createMock(LsaBinImpl.class);
117 + lsaWrapper = new LsaWrapperImpl();
118 + lsaWrapper.setBinNumber(-1);
119 + lsaBin.addOspfLsa("1", lsaWrapper);
120 + lsdbAge.startDbAging();
121 + lsdbAge.addLsaToMaxAgeBin("3600", lsaWrapper);
122 + lsdbAge.addLsaBin(-1, lsaBin);
123 + lsdbAge.removeLsaFromBin(lsaWrapper);
124 + assertThat(lsdbAge, is(notNullValue()));
125 + }
126 +
127 + /**
128 + * Tests startDbAging() method.
129 + */
130 + @Test
131 + public void testStartDbAging() throws Exception {
132 + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
133 + lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
134 + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
135 + lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper);
136 + lsdbAge.startDbAging();
137 + assertThat(lsdbAge, is(notNullValue()));
138 + }
139 +
140 + /**
141 + * Tests ageLsaAndFlood() method.
142 + */
143 + @Test
144 + public void testAgeLsaAndFlood() throws Exception {
145 + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
146 + lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
147 + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
148 + lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper);
149 + lsdbAge.startDbAging();
150 + lsdbAge.ageLsaAndFlood();
151 + Assert.assertNotNull(lsdbAge);
152 + }
153 +
154 + /**
155 + * Tests maxAgeLsa() method.
156 + */
157 + @Test
158 + public void testMaxageLsa() throws Exception {
159 + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
160 + ospfArea = new OspfAreaImpl();
161 + lsdbAge = new LsdbAgeImpl(ospfArea);
162 + lsaWrapper.setLsdbAge(lsdbAge);
163 + lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
164 + lsaBin = new LsaBinImpl(1);
165 + lsaBin.addOspfLsa("1", lsaWrapper);
166 + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
167 + lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper);
168 + lsaBin.addOspfLsa("2", lsaWrapper);
169 + lsdbAge.startDbAging();
170 + lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
171 + lsdbAge.ageLsaAndFlood();
172 + lsdbAge.maxAgeLsa();
173 + assertThat(lsdbAge, is(notNullValue()));
174 +
175 + }
176 +
177 + /**
178 + * Tests refreshLsa() method.
179 + */
180 + @Test
181 + public void testRefereshLsa() throws Exception {
182 + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
183 + lsaWrapper.setBinNumber(0);
184 + lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
185 + lsdbAge.ageLsaAndFlood();
186 + lsaWrapper.setBinNumber(0);
187 + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
188 + lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper);
189 + lsdbAge.ageLsaAndFlood();
190 + lsdbAge.startDbAging();
191 + lsaBin = new LsaBinImpl(1809);
192 + lsdbAge.refreshLsa();
193 + assertThat(lsdbAge, is(notNullValue()));
194 + }
195 +
196 + /**
197 + * Tests checkAges() method.
198 + */
199 + @Test
200 + public void testCheckAges() throws Exception {
201 + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
202 + lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
203 + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
204 + lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper);
205 + lsdbAge.startDbAging();
206 + lsdbAge.checkAges();
207 + assertThat(lsdbAge, is(notNullValue()));
208 +
209 + }
210 +
211 + /**
212 + * Tests getChannel() getter method.
213 + */
214 + @Test
215 + public void testGetChannel() throws Exception {
216 + channel = EasyMock.createMock(Channel.class);
217 + lsdbAge.setChannel(channel);
218 + assertThat(lsdbAge.getChannel(), is(notNullValue()));
219 + }
220 +
221 + /**
222 + * Tests setChannel() setter method.
223 + */
224 + @Test
225 + public void testSetChannel() throws Exception {
226 + channel = EasyMock.createMock(Channel.class);
227 + lsdbAge.setChannel(channel);
228 + assertThat(lsdbAge.getChannel(), is(notNullValue()));
229 + }
230 +
231 + /**
232 + * Tests getAgeCounter() method.
233 + */
234 + @Test
235 + public void testGetAgeCounter() throws Exception {
236 + lsaBin = new LsaBinImpl(1);
237 + lsdbAge.addLsaBin(1, lsaBin);
238 + int age = lsdbAge.getAgeCounter();
239 + assertThat(age, is(notNullValue()));
240 + }
241 +
242 + /**
243 + * Tests getAgeCounterRollOver() method.
244 + */
245 + @Test
246 + public void testGetAgeCounterRollOver() throws Exception {
247 + lsaBin = new LsaBinImpl(1);
248 + lsdbAge.addLsaBin(1, lsaBin);
249 + lsdbAge.startDbAging();
250 + assertThat(lsdbAge.getAgeCounterRollOver(), is(notNullValue()));
251 + }
252 +
253 + /**
254 + * Tests getMaxAgeBin() method.
255 + */
256 + @Test
257 + public void testGetMaxAgeBin() throws Exception {
258 + lsaBin = new LsaBinImpl(1);
259 + lsdbAge.addLsaBin(1, lsaBin);
260 + lsdbAge.startDbAging();
261 + assertThat(lsdbAge.getMaxAgeBin(), is(notNullValue()));
262 + }
263 +
264 + /**
265 + * Tests age2Bin() method.
266 + */
267 + @Test
268 + public void testAge2Bin() throws Exception {
269 + int age = lsdbAge.age2Bin(0);
270 + assertThat(age, is(notNullValue()));
271 + }
272 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
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 +package org.onosproject.ospf.controller.lsdb;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +import org.onosproject.ospf.controller.OspfLsaType;
22 +import org.onosproject.ospf.controller.area.OspfAreaImpl;
23 +import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
24 +import org.onosproject.ospf.protocol.lsa.LsaHeader;
25 +import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
26 +import org.onosproject.ospf.protocol.lsa.types.AsbrSummaryLsa;
27 +import org.onosproject.ospf.protocol.lsa.types.ExternalLsa;
28 +import org.onosproject.ospf.protocol.lsa.types.NetworkLsa;
29 +import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa10;
30 +import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa11;
31 +import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa9;
32 +import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
33 +import org.onosproject.ospf.protocol.lsa.types.SummaryLsa;
34 +
35 +import static org.hamcrest.CoreMatchers.*;
36 +import static org.hamcrest.MatcherAssert.assertThat;
37 +
38 +/**
39 + * Unit test class for OspfLsdbImpl.
40 + */
41 +public class OspfLsdbImplTest {
42 + private OspfLsdbImpl ospfLsdb;
43 + private RouterLsa routerLsa;
44 + private NetworkLsa networkLsa;
45 + private SummaryLsa summaryLsa;
46 + private AsbrSummaryLsa asbrSummaryLsa;
47 + private OpaqueLsa9 opaqueLsa9;
48 + private OpaqueLsa10 opaqueLsa10;
49 + private OpaqueLsa11 opaqueLsa11;
50 + private ExternalLsa externalLsa;
51 + private OpaqueLsaHeader opaqueLsaHeader;
52 + private LsaWrapperImpl lsaWrapper;
53 + private OpaqueLsaHeader opaqueLsaHeader1;
54 + private String key;
55 +
56 + @Before
57 + public void setUp() throws Exception {
58 + OspfAreaImpl ospfArea = new OspfAreaImpl();
59 + ospfLsdb = new OspfLsdbImpl(ospfArea);
60 + routerLsa = new RouterLsa();
61 + networkLsa = new NetworkLsa();
62 + summaryLsa = new SummaryLsa(new LsaHeader());
63 + asbrSummaryLsa = new AsbrSummaryLsa(new LsaHeader());
64 + opaqueLsa9 = new OpaqueLsa9(new OpaqueLsaHeader());
65 + opaqueLsa10 = new OpaqueLsa10(new OpaqueLsaHeader());
66 + opaqueLsa11 = new OpaqueLsa11(new OpaqueLsaHeader());
67 + externalLsa = new ExternalLsa(new LsaHeader());
68 +
69 +
70 + }
71 +
72 + @After
73 + public void tearDown() throws Exception {
74 + ospfLsdb = null;
75 + routerLsa = null;
76 + externalLsa = null;
77 + summaryLsa = null;
78 + asbrSummaryLsa = null;
79 + opaqueLsa10 = null;
80 + opaqueLsa11 = null;
81 + opaqueLsa9 = null;
82 + networkLsa = null;
83 + lsaWrapper = null;
84 + opaqueLsaHeader = null;
85 + opaqueLsaHeader1 = null;
86 + key = null;
87 + }
88 +
89 + /**
90 + * Tests equals() method.
91 + */
92 + @Test
93 + public void testEquals() throws Exception {
94 + assertThat(ospfLsdb.equals(new OspfLsdbImpl(new OspfAreaImpl())), is(false));
95 + }
96 +
97 + /**
98 + * Tests hashCode() method.
99 + */
100 + @Test
101 + public void testHashCode() throws Exception {
102 + int hashCode = ospfLsdb.hashCode();
103 + assertThat(hashCode, is(notNullValue()));
104 + }
105 +
106 + /**
107 + * Tests initializeDb() method.
108 + */
109 + @Test
110 + public void testInitializeDb() throws Exception {
111 + ospfLsdb.initializeDb();
112 + assertThat(ospfLsdb, is(notNullValue()));
113 + }
114 +
115 + /**
116 + * Tests getAllLsaHeaders() method.
117 + */
118 + @Test
119 + public void testGetAllLsaHeaders() throws Exception {
120 + ospfLsdb.initializeDb();
121 + routerLsa.setLsType(1);
122 + assertThat(ospfLsdb.addLsa(routerLsa, false, new OspfInterfaceImpl()), is(true));
123 + networkLsa.setLsType(2);
124 + assertThat(ospfLsdb.addLsa(networkLsa, false, new OspfInterfaceImpl()), is(true));
125 + summaryLsa.setLsType(3);
126 + assertThat(ospfLsdb.addLsa(summaryLsa, false, new OspfInterfaceImpl()), is(true));
127 + asbrSummaryLsa.setLsType(4);
128 + assertThat(ospfLsdb.addLsa(asbrSummaryLsa, false, new OspfInterfaceImpl()), is(true));
129 + externalLsa.setLsType(5);
130 + assertThat(ospfLsdb.addLsa(externalLsa, false, new OspfInterfaceImpl()), is(true));
131 + ospfLsdb.initializeDb();
132 + assertThat(ospfLsdb.getAllLsaHeaders(true, true).size(), is(5));
133 +
134 + }
135 +
136 + /**
137 + * Tests getLsaKey() method.
138 + */
139 + @Test
140 + public void testGetLsaKey() throws Exception {
141 + opaqueLsaHeader = new OpaqueLsaHeader();
142 + opaqueLsaHeader.setLsType(1);
143 + assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
144 + opaqueLsaHeader = new OpaqueLsaHeader();
145 + opaqueLsaHeader.setLsType(2);
146 + assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
147 + opaqueLsaHeader = new OpaqueLsaHeader();
148 + opaqueLsaHeader.setLsType(3);
149 + assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
150 + opaqueLsaHeader = new OpaqueLsaHeader();
151 + opaqueLsaHeader.setLsType(4);
152 + assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
153 + opaqueLsaHeader = new OpaqueLsaHeader();
154 + opaqueLsaHeader.setLsType(5);
155 + assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
156 + opaqueLsaHeader = new OpaqueLsaHeader();
157 + opaqueLsaHeader.setLsType(9);
158 + assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
159 + opaqueLsaHeader = new OpaqueLsaHeader();
160 + opaqueLsaHeader.setLsType(10);
161 + assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
162 + opaqueLsaHeader = new OpaqueLsaHeader();
163 + opaqueLsaHeader.setLsType(11);
164 + assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
165 + }
166 +
167 + /**
168 + * Tests lsaLookup() method.
169 + */
170 + @Test
171 + public void testLsaLookup() throws Exception {
172 + ospfLsdb.initializeDb();
173 + opaqueLsaHeader = new OpaqueLsaHeader();
174 + ospfLsdb.addLsa(opaqueLsaHeader, true, new OspfInterfaceImpl());
175 + opaqueLsaHeader.setLsType(1);
176 + String key = ospfLsdb.getLsaKey(opaqueLsaHeader);
177 + assertThat(ospfLsdb.lsaLookup(opaqueLsaHeader), is(nullValue()));
178 + }
179 +
180 + /**
181 + * Tests findLsa() method.
182 + */
183 + @Test
184 + public void testFindlsa() throws Exception {
185 + opaqueLsaHeader = new OpaqueLsaHeader();
186 + opaqueLsaHeader.setLsType(1);
187 + key = ospfLsdb.getLsaKey(opaqueLsaHeader);
188 + ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
189 + lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
190 + assertThat(lsaWrapper, is(nullValue()));
191 + opaqueLsaHeader = new OpaqueLsaHeader();
192 + opaqueLsaHeader.setLsType(2);
193 + key = ospfLsdb.getLsaKey(opaqueLsaHeader);
194 + ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
195 + lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
196 + assertThat(lsaWrapper, is(nullValue()));
197 + opaqueLsaHeader = new OpaqueLsaHeader();
198 + opaqueLsaHeader.setLsType(3);
199 + key = ospfLsdb.getLsaKey(opaqueLsaHeader);
200 + ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
201 + lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
202 + assertThat(lsaWrapper, is(nullValue()));
203 + opaqueLsaHeader = new OpaqueLsaHeader();
204 + opaqueLsaHeader.setLsType(4);
205 + key = ospfLsdb.getLsaKey(opaqueLsaHeader);
206 + ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
207 + lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
208 + assertThat(lsaWrapper, is(nullValue()));
209 + opaqueLsaHeader = new OpaqueLsaHeader();
210 + opaqueLsaHeader.setLsType(5);
211 + key = ospfLsdb.getLsaKey(opaqueLsaHeader);
212 + ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
213 + lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
214 + assertThat(lsaWrapper, is(nullValue()));
215 + opaqueLsaHeader = new OpaqueLsaHeader();
216 + opaqueLsaHeader.setLsType(9);
217 + key = ospfLsdb.getLsaKey(opaqueLsaHeader);
218 + ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
219 + lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
220 + assertThat(lsaWrapper, is(nullValue()));
221 + opaqueLsaHeader = new OpaqueLsaHeader();
222 + opaqueLsaHeader.setLsType(10);
223 + key = ospfLsdb.getLsaKey(opaqueLsaHeader);
224 + ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
225 + lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
226 + assertThat(lsaWrapper, is(nullValue()));
227 + opaqueLsaHeader = new OpaqueLsaHeader();
228 + opaqueLsaHeader.setLsType(11);
229 + key = ospfLsdb.getLsaKey(opaqueLsaHeader);
230 + ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
231 + lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
232 + assertThat(lsaWrapper, is(nullValue()));
233 + }
234 +
235 + /**
236 + * Tests addLSA() method.
237 + */
238 + @Test
239 + public void testAddLSA() throws Exception {
240 + routerLsa.setLsType(1);
241 + assertThat(ospfLsdb.addLsa(routerLsa, false, new OspfInterfaceImpl()), is(true));
242 + networkLsa.setLsType(2);
243 + assertThat(ospfLsdb.addLsa(networkLsa, false, new OspfInterfaceImpl()), is(true));
244 + summaryLsa.setLsType(3);
245 + assertThat(ospfLsdb.addLsa(summaryLsa, false, new OspfInterfaceImpl()), is(true));
246 + asbrSummaryLsa.setLsType(4);
247 + assertThat(ospfLsdb.addLsa(asbrSummaryLsa, false, new OspfInterfaceImpl()), is(true));
248 + externalLsa.setLsType(5);
249 + assertThat(ospfLsdb.addLsa(externalLsa, false, new OspfInterfaceImpl()), is(true));
250 + opaqueLsa9.setLsType(9);
251 + assertThat(ospfLsdb.addLsa(opaqueLsa9, false, new OspfInterfaceImpl()), is(true));
252 + opaqueLsa10.setLsType(10);
253 + assertThat(ospfLsdb.addLsa(opaqueLsa10, false, new OspfInterfaceImpl()), is(true));
254 + opaqueLsa11.setLsType(11);
255 + assertThat(ospfLsdb.addLsa(opaqueLsa11, false, new OspfInterfaceImpl()), is(true));
256 +
257 + }
258 +
259 + /**
260 + * Tests addLsaToMaxAgeBin() method.
261 + */
262 + @Test
263 + public void testAddLsaToMaxAgeBin() throws Exception {
264 + lsaWrapper = new LsaWrapperImpl();
265 + opaqueLsaHeader = new OpaqueLsaHeader();
266 + opaqueLsaHeader.setLsType(1);
267 + key = ospfLsdb.getLsaKey(opaqueLsaHeader);
268 + lsaWrapper.setLsaHeader((OpaqueLsaHeader) opaqueLsaHeader);
269 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
270 + lsaWrapper = new LsaWrapperImpl();
271 + opaqueLsaHeader = new OpaqueLsaHeader();
272 + opaqueLsaHeader.setLsType(2);
273 + ospfLsdb.getLsaKey(opaqueLsaHeader);
274 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
275 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
276 + lsaWrapper = new LsaWrapperImpl();
277 + opaqueLsaHeader = new OpaqueLsaHeader();
278 + opaqueLsaHeader.setLsType(3);
279 + ospfLsdb.getLsaKey(opaqueLsaHeader);
280 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
281 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
282 + lsaWrapper = new LsaWrapperImpl();
283 + opaqueLsaHeader = new OpaqueLsaHeader();
284 + opaqueLsaHeader.setLsType(4);
285 + ospfLsdb.getLsaKey(opaqueLsaHeader);
286 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
287 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
288 + lsaWrapper = new LsaWrapperImpl();
289 + opaqueLsaHeader = new OpaqueLsaHeader();
290 + opaqueLsaHeader.setLsType(5);
291 + ospfLsdb.getLsaKey(opaqueLsaHeader);
292 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
293 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
294 + lsaWrapper = new LsaWrapperImpl();
295 + opaqueLsaHeader = new OpaqueLsaHeader();
296 + opaqueLsaHeader.setLsType(9);
297 + ospfLsdb.getLsaKey(opaqueLsaHeader);
298 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
299 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
300 + lsaWrapper = new LsaWrapperImpl();
301 + opaqueLsaHeader = new OpaqueLsaHeader();
302 + opaqueLsaHeader.setLsType(10);
303 + ospfLsdb.getLsaKey(opaqueLsaHeader);
304 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
305 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
306 + lsaWrapper = new LsaWrapperImpl();
307 + opaqueLsaHeader = new OpaqueLsaHeader();
308 + opaqueLsaHeader.setLsType(11);
309 + ospfLsdb.getLsaKey(opaqueLsaHeader);
310 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
311 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
312 + assertThat(ospfLsdb, is(notNullValue()));
313 + }
314 +
315 + /**
316 + * Tests removeLsaFromBin() method.
317 + */
318 + @Test
319 + public void testRemoveLsaFromBin() throws Exception {
320 + lsaWrapper = new LsaWrapperImpl();
321 + opaqueLsaHeader = new OpaqueLsaHeader();
322 + opaqueLsaHeader.setLsType(1);
323 + key = ospfLsdb.getLsaKey(opaqueLsaHeader);
324 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
325 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
326 + ospfLsdb.removeLsaFromBin(lsaWrapper);
327 + lsaWrapper = new LsaWrapperImpl();
328 + opaqueLsaHeader = new OpaqueLsaHeader();
329 + opaqueLsaHeader.setLsType(2);
330 + ospfLsdb.getLsaKey(opaqueLsaHeader);
331 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
332 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
333 + ospfLsdb.removeLsaFromBin(lsaWrapper);
334 + lsaWrapper = new LsaWrapperImpl();
335 + opaqueLsaHeader = new OpaqueLsaHeader();
336 + opaqueLsaHeader.setLsType(3);
337 + ospfLsdb.getLsaKey(opaqueLsaHeader);
338 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
339 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
340 + ospfLsdb.removeLsaFromBin(lsaWrapper);
341 + lsaWrapper = new LsaWrapperImpl();
342 + opaqueLsaHeader = new OpaqueLsaHeader();
343 + opaqueLsaHeader.setLsType(4);
344 + ospfLsdb.getLsaKey(opaqueLsaHeader);
345 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
346 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
347 + ospfLsdb.removeLsaFromBin(lsaWrapper);
348 + lsaWrapper = new LsaWrapperImpl();
349 + opaqueLsaHeader = new OpaqueLsaHeader();
350 + opaqueLsaHeader.setLsType(5);
351 + ospfLsdb.getLsaKey(opaqueLsaHeader);
352 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
353 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
354 + ospfLsdb.removeLsaFromBin(lsaWrapper);
355 + lsaWrapper = new LsaWrapperImpl();
356 + opaqueLsaHeader = new OpaqueLsaHeader();
357 + opaqueLsaHeader.setLsType(9);
358 + ospfLsdb.getLsaKey(opaqueLsaHeader);
359 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
360 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
361 + ospfLsdb.removeLsaFromBin(lsaWrapper);
362 + lsaWrapper = new LsaWrapperImpl();
363 + opaqueLsaHeader = new OpaqueLsaHeader();
364 + opaqueLsaHeader.setLsType(10);
365 + ospfLsdb.getLsaKey(opaqueLsaHeader);
366 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
367 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
368 + ospfLsdb.removeLsaFromBin(lsaWrapper);
369 + lsaWrapper = new LsaWrapperImpl();
370 + opaqueLsaHeader = new OpaqueLsaHeader();
371 + opaqueLsaHeader.setLsType(11);
372 + ospfLsdb.getLsaKey(opaqueLsaHeader);
373 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
374 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
375 + ospfLsdb.removeLsaFromBin(lsaWrapper);
376 + assertThat(ospfLsdb, is(notNullValue()));
377 + }
378 +
379 + /**
380 + * Tests isNewerOrSameLsa() method.
381 + */
382 + @Test
383 + public void testIsNewerorSameLSA() throws Exception {
384 + lsaWrapper = new LsaWrapperImpl();
385 + opaqueLsaHeader1 = new OpaqueLsaHeader();
386 + opaqueLsaHeader1.setLsType(1);
387 + key = ospfLsdb.getLsaKey(opaqueLsaHeader1);
388 + lsaWrapper.setLsaHeader(opaqueLsaHeader1);
389 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
390 + lsaWrapper = new LsaWrapperImpl();
391 + opaqueLsaHeader = new OpaqueLsaHeader();
392 + opaqueLsaHeader.setLsType(2);
393 + ospfLsdb.getLsaKey(opaqueLsaHeader);
394 + lsaWrapper.setLsaHeader(opaqueLsaHeader);
395 + ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
396 + assertThat(ospfLsdb.isNewerOrSameLsa(opaqueLsaHeader1, opaqueLsaHeader), is(notNullValue()));
397 + assertThat(ospfLsdb, is(notNullValue()));
398 + }
399 +
400 + /**
401 + * Tests getLsSequenceNumber() method.
402 + */
403 + @Test
404 + public void testGetLsSequenceNumber() throws Exception {
405 + assertThat(ospfLsdb.getLsSequenceNumber(OspfLsaType.NETWORK), is(notNullValue()));
406 + assertThat(ospfLsdb.getLsSequenceNumber(OspfLsaType.ROUTER), is(notNullValue()));
407 + }
408 +
409 + /**
410 + * Tests deleteLsa() method.
411 + */
412 + @Test
413 + public void testDeleteLsa() throws Exception {
414 + opaqueLsaHeader1 = new OpaqueLsaHeader();
415 + opaqueLsaHeader1.setLsType(1);
416 + ospfLsdb.deleteLsa(opaqueLsaHeader1);
417 + opaqueLsaHeader1 = new OpaqueLsaHeader();
418 + opaqueLsaHeader1.setLsType(2);
419 + ospfLsdb.deleteLsa(opaqueLsaHeader1);
420 + opaqueLsaHeader1 = new OpaqueLsaHeader();
421 + opaqueLsaHeader1.setLsType(3);
422 + ospfLsdb.deleteLsa(opaqueLsaHeader1);
423 + opaqueLsaHeader1 = new OpaqueLsaHeader();
424 + opaqueLsaHeader1.setLsType(4);
425 + ospfLsdb.deleteLsa(opaqueLsaHeader1);
426 + opaqueLsaHeader1 = new OpaqueLsaHeader();
427 + opaqueLsaHeader1.setLsType(5);
428 + ospfLsdb.deleteLsa(opaqueLsaHeader1);
429 + opaqueLsaHeader1 = new OpaqueLsaHeader();
430 + opaqueLsaHeader1.setLsType(9);
431 + ospfLsdb.deleteLsa(opaqueLsaHeader1);
432 + opaqueLsaHeader1 = new OpaqueLsaHeader();
433 + opaqueLsaHeader1.setLsType(10);
434 + ospfLsdb.deleteLsa(opaqueLsaHeader1);
435 + opaqueLsaHeader1 = new OpaqueLsaHeader();
436 + opaqueLsaHeader1.setLsType(11);
437 + ospfLsdb.deleteLsa(opaqueLsaHeader1);
438 + assertThat(ospfLsdb, is(notNullValue()));
439 +
440 + }
441 +
442 + /**
443 + * Tests getLsSequenceNumber() method.
444 + */
445 + @Test
446 + public void testSetRouterLsaSeqNo() throws Exception {
447 + ospfLsdb.setRouterLsaSeqNo(-2147483647);
448 + assertThat(ospfLsdb.getLsSequenceNumber(OspfLsaType.ROUTER), is(-2147483647L));
449 + }
450 +
451 + /**
452 + * Tests getLsSequenceNumber() method.
453 + */
454 + @Test
455 + public void testSetNetworkLsaSeqNo() throws Exception {
456 + ospfLsdb.setNetworkLsaSeqNo(111111);
457 + assertThat(ospfLsdb.getLsSequenceNumber(OspfLsaType.NETWORK), is(111111L));
458 + }
459 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
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 +package org.onosproject.ospf.controller.util;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +import org.onlab.packet.Ip4Address;
22 +
23 +import static org.hamcrest.CoreMatchers.is;
24 +import static org.hamcrest.MatcherAssert.assertThat;
25 +
26 +/**
27 + * Unit test class for OspfEligibleRouter.
28 + */
29 +public class OspfEligibleRouterTest {
30 +
31 + private OspfEligibleRouter ospfEligibleRouter;
32 +
33 + @Before
34 + public void setUp() throws Exception {
35 + ospfEligibleRouter = new OspfEligibleRouter();
36 + }
37 +
38 + @After
39 + public void tearDown() throws Exception {
40 + ospfEligibleRouter = null;
41 + }
42 +
43 + /**
44 + * Tests getIpAddress() getter method.
45 + */
46 + @Test
47 + public void testGetIpAddress() throws Exception {
48 + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
49 + assertThat(ospfEligibleRouter.getIpAddress(), is(Ip4Address.valueOf("1.1.1.1")));
50 + }
51 +
52 + /**
53 + * Tests setIpAddress() setter method.
54 + */
55 + @Test
56 + public void testSetIpAddress() throws Exception {
57 + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
58 + assertThat(ospfEligibleRouter.getIpAddress(), is(Ip4Address.valueOf("1.1.1.1")));
59 + }
60 +
61 + /**
62 + * Tests getRouterId() getter method.
63 + */
64 + @Test
65 + public void testGetRouterId() throws Exception {
66 + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
67 + assertThat(ospfEligibleRouter.getRouterId(), is(Ip4Address.valueOf("1.1.1.1")));
68 + }
69 +
70 + /**
71 + * Tests setRouterId() setter method.
72 + */
73 + @Test
74 + public void testSetRouterId() throws Exception {
75 + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
76 + assertThat(ospfEligibleRouter.getRouterId(), is(Ip4Address.valueOf("1.1.1.1")));
77 + }
78 +
79 + /**
80 + * Tests getRouterPriority() getter method.
81 + */
82 + @Test
83 + public void testGetRouterPriority() throws Exception {
84 + ospfEligibleRouter.setRouterPriority(1);
85 + assertThat(ospfEligibleRouter.getRouterPriority(), is(1));
86 + }
87 +
88 + /**
89 + * Tests getRouterPriority() setter method.
90 + */
91 + @Test
92 + public void testSetRouterPriority() throws Exception {
93 + ospfEligibleRouter.setRouterPriority(1);
94 + assertThat(ospfEligibleRouter.getRouterPriority(), is(1));
95 + }
96 +
97 + /**
98 + * Tests isDr() getter method.
99 + */
100 + @Test
101 + public void testIsDr() throws Exception {
102 + ospfEligibleRouter.setIsDr(true);
103 + assertThat(ospfEligibleRouter.isDr(), is(true));
104 + }
105 +
106 + /**
107 + * Tests isDr() setter method.
108 + */
109 + @Test
110 + public void testSetIsDr() throws Exception {
111 + ospfEligibleRouter.setIsDr(true);
112 + assertThat(ospfEligibleRouter.isDr(), is(true));
113 + }
114 +
115 + /**
116 + * Tests isBdr() getter method.
117 + */
118 + @Test
119 + public void testIsBdr() throws Exception {
120 + ospfEligibleRouter.setIsBdr(true);
121 + assertThat(ospfEligibleRouter.isBdr(), is(true));
122 + }
123 +
124 + /**
125 + * Tests isBdr() setter method.
126 + */
127 + @Test
128 + public void testSetIsBdr() throws Exception {
129 + ospfEligibleRouter.setIsBdr(true);
130 + assertThat(ospfEligibleRouter.isBdr(), is(true));
131 + }
132 +}