Committed by
Thomas Vachuska
ONOS-2740,ONOS-2741,from ONOS-3032 - to ONOS 3071 , OSPF Protocol Implementation Unit Tests
Change-Id: Ie7f02bd9bff16902647c7af406f7ece9cdf0ae6c
Showing
12 changed files
with
2400 additions
and
0 deletions
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/area/OspfInterfaceImplTest.java
0 → 100755
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.junit.After; | ||
20 | +import org.junit.Assert; | ||
21 | +import org.junit.Before; | ||
22 | +import org.junit.Test; | ||
23 | +import org.onlab.packet.Ip4Address; | ||
24 | +import org.onosproject.ospf.controller.OspfNbr; | ||
25 | +import org.onosproject.ospf.controller.TopologyForDeviceAndLink; | ||
26 | +import org.onosproject.ospf.controller.impl.Controller; | ||
27 | +import org.onosproject.ospf.controller.impl.OspfInterfaceChannelHandler; | ||
28 | +import org.onosproject.ospf.controller.impl.OspfNbrImpl; | ||
29 | +import org.onosproject.ospf.controller.impl.TopologyForDeviceAndLinkImpl; | ||
30 | +import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader; | ||
31 | +import org.onosproject.ospf.protocol.util.OspfInterfaceState; | ||
32 | + | ||
33 | +import java.util.HashMap; | ||
34 | + | ||
35 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
36 | +import static org.hamcrest.Matchers.is; | ||
37 | +import static org.hamcrest.Matchers.notNullValue; | ||
38 | + | ||
39 | +/** | ||
40 | + * Unit test class for OspfInterfaceImpl. | ||
41 | + */ | ||
42 | +public class OspfInterfaceImplTest { | ||
43 | + | ||
44 | + private OspfInterfaceImpl ospfInterface; | ||
45 | + private OspfNbrImpl ospfNbr; | ||
46 | + private OpaqueLsaHeader opaqueLsaHeader; | ||
47 | + private int result; | ||
48 | + private HashMap<String, OspfNbr> ospfNbrHashMap; | ||
49 | + private TopologyForDeviceAndLink topologyForDeviceAndLink; | ||
50 | + | ||
51 | + @Before | ||
52 | + public void setUp() throws Exception { | ||
53 | + ospfInterface = new OspfInterfaceImpl(); | ||
54 | + topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl(); | ||
55 | + } | ||
56 | + | ||
57 | + @After | ||
58 | + public void tearDown() throws Exception { | ||
59 | + ospfInterface = null; | ||
60 | + ospfNbr = null; | ||
61 | + opaqueLsaHeader = null; | ||
62 | + ospfNbrHashMap = null; | ||
63 | + } | ||
64 | + | ||
65 | + /** | ||
66 | + * Tests state() getter method. | ||
67 | + */ | ||
68 | + @Test | ||
69 | + public void testGetState() throws Exception { | ||
70 | + ospfInterface.setState(OspfInterfaceState.DROTHER); | ||
71 | + assertThat(ospfInterface.state(), is(OspfInterfaceState.DROTHER)); | ||
72 | + } | ||
73 | + | ||
74 | + /** | ||
75 | + * Tests state() setter method. | ||
76 | + */ | ||
77 | + @Test | ||
78 | + public void testSetState() throws Exception { | ||
79 | + ospfInterface.setState(OspfInterfaceState.DROTHER); | ||
80 | + assertThat(ospfInterface.state(), is(OspfInterfaceState.DROTHER)); | ||
81 | + } | ||
82 | + | ||
83 | + /** | ||
84 | + * Tests linkStateHeaders() method. | ||
85 | + */ | ||
86 | + @Test | ||
87 | + public void testGetLinkStateHeaders() throws Exception { | ||
88 | + | ||
89 | + assertThat(ospfInterface.linkStateHeaders().size(), is(0)); | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * Tests ipNetworkMask() getter method. | ||
94 | + */ | ||
95 | + @Test | ||
96 | + public void testGetIpNetworkMask() throws Exception { | ||
97 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("1.1.1.1")); | ||
98 | + assertThat(ospfInterface.ipNetworkMask(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * Tests ipNetworkMask() setter method. | ||
103 | + */ | ||
104 | + @Test | ||
105 | + public void testSetIpNetworkMask() throws Exception { | ||
106 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("1.1.1.1")); | ||
107 | + assertThat(ospfInterface.ipNetworkMask(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
108 | + } | ||
109 | + | ||
110 | + /** | ||
111 | + * Tests addNeighbouringRouter() method. | ||
112 | + */ | ||
113 | + @Test | ||
114 | + public void testAddNeighbouringRouter() throws Exception { | ||
115 | + ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), | ||
116 | + Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2, | ||
117 | + new OspfInterfaceChannelHandler(new Controller(), new OspfAreaImpl(), | ||
118 | + new OspfInterfaceImpl()) | ||
119 | + , topologyForDeviceAndLink); | ||
120 | + ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111")); | ||
121 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
122 | + assertThat(ospfInterface, is(notNullValue())); | ||
123 | + | ||
124 | + } | ||
125 | + | ||
126 | + /** | ||
127 | + * Tests neighbouringRouter() method. | ||
128 | + */ | ||
129 | + @Test | ||
130 | + public void testGetNeighbouringRouter() throws Exception { | ||
131 | + ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), | ||
132 | + Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2, | ||
133 | + new OspfInterfaceChannelHandler(new Controller(), new OspfAreaImpl(), | ||
134 | + new OspfInterfaceImpl()) | ||
135 | + , topologyForDeviceAndLink); | ||
136 | + ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111")); | ||
137 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
138 | + assertThat(ospfInterface.neighbouringRouter("111.111.111.111"), is(notNullValue())); | ||
139 | + } | ||
140 | + | ||
141 | + /** | ||
142 | + * Tests addLsaHeaderForDelayAck() method. | ||
143 | + */ | ||
144 | + @Test | ||
145 | + public void testAddLsaHeaderForDelayAck() throws Exception { | ||
146 | + opaqueLsaHeader = new OpaqueLsaHeader(); | ||
147 | + opaqueLsaHeader.setLsType(10); | ||
148 | + ospfInterface.addLsaHeaderForDelayAck(opaqueLsaHeader); | ||
149 | + assertThat(ospfInterface, is(notNullValue())); | ||
150 | + } | ||
151 | + | ||
152 | + /** | ||
153 | + * Tests removeLsaFromNeighborMap() method. | ||
154 | + */ | ||
155 | + @Test | ||
156 | + public void testRemoveLsaFromNeighborMap() throws Exception { | ||
157 | + ospfInterface.removeLsaFromNeighborMap("lsa10"); | ||
158 | + assertThat(ospfInterface, is(notNullValue())); | ||
159 | + } | ||
160 | + | ||
161 | + /** | ||
162 | + * Tests isNeighborInList() method. | ||
163 | + */ | ||
164 | + @Test | ||
165 | + public void testIsNeighborinList() throws Exception { | ||
166 | + ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), | ||
167 | + Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2, | ||
168 | + new OspfInterfaceChannelHandler(new Controller(), new OspfAreaImpl(), | ||
169 | + new OspfInterfaceImpl()) | ||
170 | + , topologyForDeviceAndLink); | ||
171 | + ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111")); | ||
172 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
173 | + assertThat(ospfInterface.isNeighborInList("111.111.111.111"), is(notNullValue())); | ||
174 | + } | ||
175 | + | ||
176 | + /** | ||
177 | + * Tests listOfNeighbors() getter method. | ||
178 | + */ | ||
179 | + @Test | ||
180 | + public void testGetListOfNeighbors() throws Exception { | ||
181 | + ospfNbrHashMap = new HashMap(); | ||
182 | + ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), | ||
183 | + Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2, | ||
184 | + new OspfInterfaceChannelHandler(new Controller(), | ||
185 | + new OspfAreaImpl(), | ||
186 | + new OspfInterfaceImpl()) | ||
187 | + , topologyForDeviceAndLink); | ||
188 | + ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111")); | ||
189 | + ospfNbrHashMap.put("111.111.111.111", ospfNbr); | ||
190 | + ospfInterface.setListOfNeighbors(ospfNbrHashMap); | ||
191 | + assertThat(ospfInterface.listOfNeighbors().size(), is(1)); | ||
192 | + } | ||
193 | + | ||
194 | + /** | ||
195 | + * Tests listOfNeighbors() setter method. | ||
196 | + */ | ||
197 | + @Test | ||
198 | + public void testSetListOfNeighbors() throws Exception { | ||
199 | + ospfNbrHashMap = new HashMap(); | ||
200 | + ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), | ||
201 | + Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2, | ||
202 | + new OspfInterfaceChannelHandler(new Controller(), new OspfAreaImpl(), | ||
203 | + new OspfInterfaceImpl()) | ||
204 | + , topologyForDeviceAndLink); | ||
205 | + ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111")); | ||
206 | + ospfNbrHashMap.put("111.111.111.111", ospfNbr); | ||
207 | + ospfInterface.setListOfNeighbors(ospfNbrHashMap); | ||
208 | + assertThat(ospfInterface.listOfNeighbors().size(), is(1)); | ||
209 | + } | ||
210 | + | ||
211 | + /** | ||
212 | + * Tests ipAddress() getter method. | ||
213 | + */ | ||
214 | + @Test | ||
215 | + public void testGetIpAddress() throws Exception { | ||
216 | + ospfInterface.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
217 | + assertThat(ospfInterface.ipAddress(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
218 | + } | ||
219 | + | ||
220 | + /** | ||
221 | + * Tests ipAddress() getter method. | ||
222 | + */ | ||
223 | + @Test | ||
224 | + public void testSetIpAddress() throws Exception { | ||
225 | + ospfInterface.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
226 | + assertThat(ospfInterface.ipAddress(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
227 | + } | ||
228 | + | ||
229 | + /** | ||
230 | + * Tests routerPriority() getter method. | ||
231 | + */ | ||
232 | + @Test | ||
233 | + public void testGetRouterPriority() throws Exception { | ||
234 | + ospfInterface.setRouterPriority(1); | ||
235 | + Assert.assertEquals(1, ospfInterface.routerPriority()); | ||
236 | + } | ||
237 | + | ||
238 | + /** | ||
239 | + * Tests routerPriority() setter method. | ||
240 | + */ | ||
241 | + @Test | ||
242 | + public void testSetRouterPriority() throws Exception { | ||
243 | + ospfInterface.setRouterPriority(1); | ||
244 | + assertThat(ospfInterface.routerPriority(), is(1)); | ||
245 | + } | ||
246 | + | ||
247 | + /** | ||
248 | + * Tests areaId() getter method. | ||
249 | + */ | ||
250 | + @Test | ||
251 | + public void testGetAreaId() throws Exception { | ||
252 | + ospfInterface.setAreaId(1); | ||
253 | + assertThat(ospfInterface.areaId(), is(1)); | ||
254 | + } | ||
255 | + | ||
256 | + /** | ||
257 | + * Tests areaId() setter method. | ||
258 | + */ | ||
259 | + @Test | ||
260 | + public void testSetAreaId() throws Exception { | ||
261 | + ospfInterface.setAreaId(1); | ||
262 | + assertThat(ospfInterface.areaId(), is(1)); | ||
263 | + } | ||
264 | + | ||
265 | + /** | ||
266 | + * Tests helloIntervalTime() getter method. | ||
267 | + */ | ||
268 | + @Test | ||
269 | + public void testGetHelloIntervalTime() throws Exception { | ||
270 | + ospfInterface.setHelloIntervalTime(10); | ||
271 | + assertThat(ospfInterface.helloIntervalTime(), is(10)); | ||
272 | + } | ||
273 | + | ||
274 | + /** | ||
275 | + * Tests helloIntervalTime() setter method. | ||
276 | + */ | ||
277 | + @Test | ||
278 | + public void testSetHelloIntervalTime() throws Exception { | ||
279 | + ospfInterface.setHelloIntervalTime(10); | ||
280 | + assertThat(ospfInterface.helloIntervalTime(), is(10)); | ||
281 | + } | ||
282 | + | ||
283 | + /** | ||
284 | + * Tests routerDeadIntervalTime() getter method. | ||
285 | + */ | ||
286 | + @Test | ||
287 | + public void testGetRouterDeadIntervalTime() throws Exception { | ||
288 | + ospfInterface.setRouterDeadIntervalTime(10); | ||
289 | + assertThat(ospfInterface.routerDeadIntervalTime(), is(10)); | ||
290 | + } | ||
291 | + | ||
292 | + /** | ||
293 | + * Tests routerDeadIntervalTime() setter method. | ||
294 | + */ | ||
295 | + @Test | ||
296 | + public void testSetRouterDeadIntervalTime() throws Exception { | ||
297 | + ospfInterface.setRouterDeadIntervalTime(10); | ||
298 | + assertThat(ospfInterface.routerDeadIntervalTime(), is(10)); | ||
299 | + } | ||
300 | + | ||
301 | + /** | ||
302 | + * Tests interfaceType() getter method. | ||
303 | + */ | ||
304 | + @Test | ||
305 | + public void testGetInterfaceType() throws Exception { | ||
306 | + ospfInterface.setInterfaceType(1); | ||
307 | + assertThat(ospfInterface.interfaceType(), is(1)); | ||
308 | + } | ||
309 | + | ||
310 | + /** | ||
311 | + * Tests interfaceType() setter method. | ||
312 | + */ | ||
313 | + @Test | ||
314 | + public void testSetInterfaceType() throws Exception { | ||
315 | + ospfInterface.setInterfaceType(1); | ||
316 | + assertThat(ospfInterface.interfaceType(), is(1)); | ||
317 | + } | ||
318 | + | ||
319 | + /** | ||
320 | + * Tests interfaceCost() getter method. | ||
321 | + */ | ||
322 | + @Test | ||
323 | + public void testGetInterfaceCost() throws Exception { | ||
324 | + ospfInterface.setInterfaceCost(100); | ||
325 | + assertThat(ospfInterface.interfaceCost(), is(100)); | ||
326 | + } | ||
327 | + | ||
328 | + /** | ||
329 | + * Tests interfaceCost() setter method. | ||
330 | + */ | ||
331 | + @Test | ||
332 | + public void testSetInterfaceCost() throws Exception { | ||
333 | + ospfInterface.setInterfaceCost(100); | ||
334 | + assertThat(ospfInterface.interfaceCost(), is(100)); | ||
335 | + } | ||
336 | + | ||
337 | + /** | ||
338 | + * Tests authType() getter method. | ||
339 | + */ | ||
340 | + @Test | ||
341 | + public void testGetAuthType() throws Exception { | ||
342 | + ospfInterface.setAuthType("00"); | ||
343 | + assertThat(ospfInterface.authType(), is("00")); | ||
344 | + } | ||
345 | + | ||
346 | + /** | ||
347 | + * Tests authType() setter method. | ||
348 | + */ | ||
349 | + @Test | ||
350 | + public void testSetAuthType() throws Exception { | ||
351 | + ospfInterface.setAuthType("00"); | ||
352 | + assertThat(ospfInterface.authType(), is("00")); | ||
353 | + } | ||
354 | + | ||
355 | + /** | ||
356 | + * Tests authKey() getter method. | ||
357 | + */ | ||
358 | + @Test | ||
359 | + public void testGetAuthKey() throws Exception { | ||
360 | + ospfInterface.setAuthKey("00"); | ||
361 | + assertThat(ospfInterface.authKey(), is("00")); | ||
362 | + } | ||
363 | + | ||
364 | + /** | ||
365 | + * Tests authKey() setter method. | ||
366 | + */ | ||
367 | + @Test | ||
368 | + public void testSetAuthKey() throws Exception { | ||
369 | + ospfInterface.setAuthKey("00"); | ||
370 | + assertThat(ospfInterface.authKey(), is("00")); | ||
371 | + } | ||
372 | + | ||
373 | + /** | ||
374 | + * Tests pollInterval() getter method. | ||
375 | + */ | ||
376 | + @Test | ||
377 | + public void testGetPollInterval() throws Exception { | ||
378 | + ospfInterface.setPollInterval(100); | ||
379 | + assertThat(ospfInterface.pollInterval(), is(100)); | ||
380 | + } | ||
381 | + | ||
382 | + /** | ||
383 | + * Tests pollInterval() setter method. | ||
384 | + */ | ||
385 | + @Test | ||
386 | + public void testSetPollInterval() throws Exception { | ||
387 | + ospfInterface.setPollInterval(100); | ||
388 | + assertThat(ospfInterface.pollInterval(), is(100)); | ||
389 | + } | ||
390 | + | ||
391 | + /** | ||
392 | + * Tests mtu() getter method. | ||
393 | + */ | ||
394 | + @Test | ||
395 | + public void testGetMtu() throws Exception { | ||
396 | + ospfInterface.setMtu(100); | ||
397 | + assertThat(ospfInterface.mtu(), is(100)); | ||
398 | + } | ||
399 | + | ||
400 | + /** | ||
401 | + * Tests mtu() setter method. | ||
402 | + */ | ||
403 | + @Test | ||
404 | + public void testSetMtu() throws Exception { | ||
405 | + ospfInterface.setMtu(100); | ||
406 | + assertThat(ospfInterface.mtu(), is(100)); | ||
407 | + } | ||
408 | + | ||
409 | + /** | ||
410 | + * Tests reTransmitInterval() getter method. | ||
411 | + */ | ||
412 | + @Test | ||
413 | + public void testGetReTransmitInterval() throws Exception { | ||
414 | + ospfInterface.setReTransmitInterval(100); | ||
415 | + assertThat(ospfInterface.reTransmitInterval(), is(100)); | ||
416 | + } | ||
417 | + | ||
418 | + /** | ||
419 | + * Tests reTransmitInterval() setter method. | ||
420 | + */ | ||
421 | + @Test | ||
422 | + public void testSetReTransmitInterval() throws Exception { | ||
423 | + ospfInterface.setReTransmitInterval(100); | ||
424 | + assertThat(ospfInterface.reTransmitInterval(), is(100)); | ||
425 | + } | ||
426 | + | ||
427 | + /** | ||
428 | + * Tests dr() getter method. | ||
429 | + */ | ||
430 | + @Test | ||
431 | + public void testGetDr() throws Exception { | ||
432 | + ospfInterface.setDr(Ip4Address.valueOf("1.1.1.1")); | ||
433 | + assertThat(ospfInterface.dr(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
434 | + } | ||
435 | + | ||
436 | + /** | ||
437 | + * Tests dr() setter method. | ||
438 | + */ | ||
439 | + @Test | ||
440 | + public void testSetDr() throws Exception { | ||
441 | + ospfInterface.setDr(Ip4Address.valueOf("1.1.1.1")); | ||
442 | + assertThat(ospfInterface.dr(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
443 | + } | ||
444 | + | ||
445 | + /** | ||
446 | + * Tests bdr() getter method. | ||
447 | + */ | ||
448 | + @Test | ||
449 | + public void testGetBdr() throws Exception { | ||
450 | + ospfInterface.setBdr(Ip4Address.valueOf("1.1.1.1")); | ||
451 | + assertThat(ospfInterface.bdr(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
452 | + } | ||
453 | + | ||
454 | + /** | ||
455 | + * Tests bdr() setter method. | ||
456 | + */ | ||
457 | + @Test | ||
458 | + public void testSetBdr() throws Exception { | ||
459 | + ospfInterface.setBdr(Ip4Address.valueOf("1.1.1.1")); | ||
460 | + assertThat(ospfInterface.bdr(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
461 | + } | ||
462 | + | ||
463 | + /** | ||
464 | + * Tests transmitDelay() getter method. | ||
465 | + */ | ||
466 | + @Test | ||
467 | + public void testGetTransmitDelay() throws Exception { | ||
468 | + ospfInterface.setTransmitDelay(100); | ||
469 | + assertThat(ospfInterface.transmitDelay(), is(100)); | ||
470 | + } | ||
471 | + | ||
472 | + /** | ||
473 | + * Tests transmitDelay() setter method. | ||
474 | + */ | ||
475 | + @Test | ||
476 | + public void testSetTransmitDelay() throws Exception { | ||
477 | + ospfInterface.setTransmitDelay(100); | ||
478 | + assertThat(ospfInterface.transmitDelay(), is(100)); | ||
479 | + } | ||
480 | + | ||
481 | + /** | ||
482 | + * Tests equals() method. | ||
483 | + */ | ||
484 | + @Test | ||
485 | + public void testEquals() throws Exception { | ||
486 | + assertThat(ospfInterface.equals(new OspfInterfaceImpl()), is(true)); | ||
487 | + } | ||
488 | + | ||
489 | + /** | ||
490 | + * Tests hashCode() method. | ||
491 | + */ | ||
492 | + @Test | ||
493 | + public void testHashCode() throws Exception { | ||
494 | + result = ospfInterface.hashCode(); | ||
495 | + assertThat(result, is(notNullValue())); | ||
496 | + } | ||
497 | + | ||
498 | + /** | ||
499 | + * Tests to string method. | ||
500 | + */ | ||
501 | + @Test | ||
502 | + public void testToString() throws Exception { | ||
503 | + assertThat(ospfInterface.toString(), is(notNullValue())); | ||
504 | + } | ||
505 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/area/OspfProcessImplTest.java
0 → 100755
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.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.onosproject.ospf.controller.OspfArea; | ||
23 | + | ||
24 | +import java.util.ArrayList; | ||
25 | +import java.util.List; | ||
26 | + | ||
27 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
28 | +import static org.hamcrest.Matchers.is; | ||
29 | +import static org.hamcrest.Matchers.notNullValue; | ||
30 | + | ||
31 | +/** | ||
32 | + * Unit test class for OspfProcessImpl. | ||
33 | + */ | ||
34 | +public class OspfProcessImplTest { | ||
35 | + | ||
36 | + private OspfProcessImpl ospfProcess; | ||
37 | + private List<OspfArea> list; | ||
38 | + private List result; | ||
39 | + | ||
40 | + @Before | ||
41 | + public void setUp() throws Exception { | ||
42 | + ospfProcess = new OspfProcessImpl(); | ||
43 | + } | ||
44 | + | ||
45 | + @After | ||
46 | + public void tearDown() throws Exception { | ||
47 | + ospfProcess = null; | ||
48 | + list = null; | ||
49 | + } | ||
50 | + | ||
51 | + /** | ||
52 | + * Tests areas() getter method. | ||
53 | + */ | ||
54 | + @Test | ||
55 | + public void testGetAreas() throws Exception { | ||
56 | + list = new ArrayList(); | ||
57 | + list.add(new OspfAreaImpl()); | ||
58 | + list.add(new OspfAreaImpl()); | ||
59 | + ospfProcess.setAreas(list); | ||
60 | + result = ospfProcess.areas(); | ||
61 | + assertThat(result.size(), is(2)); | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * Tests areas() setter method. | ||
66 | + */ | ||
67 | + @Test | ||
68 | + public void testSetAreas() throws Exception { | ||
69 | + list = new ArrayList(); | ||
70 | + list.add(new OspfAreaImpl()); | ||
71 | + list.add(new OspfAreaImpl()); | ||
72 | + ospfProcess.setAreas(list); | ||
73 | + result = ospfProcess.areas(); | ||
74 | + assertThat(result.size(), is(2)); | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * Tests processId() getter method. | ||
79 | + */ | ||
80 | + @Test | ||
81 | + public void testGetProcessId() throws Exception { | ||
82 | + ospfProcess.setProcessId("1.1.1.1"); | ||
83 | + assertThat(ospfProcess.processId(), is("1.1.1.1")); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Tests processId() setter method. | ||
88 | + */ | ||
89 | + @Test | ||
90 | + public void testSetProcessId() throws Exception { | ||
91 | + ospfProcess.setProcessId("1.1.1.1"); | ||
92 | + assertThat(ospfProcess.processId(), is("1.1.1.1")); | ||
93 | + } | ||
94 | + | ||
95 | + /** | ||
96 | + * Tests to string method. | ||
97 | + */ | ||
98 | + @Test | ||
99 | + public void testToString() throws Exception { | ||
100 | + assertThat(ospfProcess.toString(), is(notNullValue())); | ||
101 | + } | ||
102 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/ControllerTest.java
0 → 100755
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.impl; | ||
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.net.driver.DriverService; | ||
25 | +import org.onosproject.ospf.controller.OspfAgent; | ||
26 | +import org.onosproject.ospf.controller.OspfArea; | ||
27 | +import org.onosproject.ospf.controller.OspfInterface; | ||
28 | +import org.onosproject.ospf.controller.OspfProcess; | ||
29 | +import org.onosproject.ospf.controller.OspfRouter; | ||
30 | +import org.onosproject.ospf.controller.area.OspfAreaImpl; | ||
31 | +import org.onosproject.ospf.controller.area.OspfInterfaceImpl; | ||
32 | +import org.onosproject.ospf.controller.area.OspfProcessImpl; | ||
33 | + | ||
34 | +import java.nio.channels.Channel; | ||
35 | +import java.util.ArrayList; | ||
36 | +import java.util.HashMap; | ||
37 | +import java.util.List; | ||
38 | +import java.util.Map; | ||
39 | + | ||
40 | +import static org.hamcrest.CoreMatchers.*; | ||
41 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
42 | + | ||
43 | +/** | ||
44 | + * Unit test class for Controller. | ||
45 | + */ | ||
46 | +public class ControllerTest { | ||
47 | + private Controller controller; | ||
48 | + private Map<String, Long> maps; | ||
49 | + private OspfAgent ospfAgent; | ||
50 | + private DriverService driverService; | ||
51 | + private List<Channel> connectedChannels; | ||
52 | + private List<OspfProcess> process; | ||
53 | + private OspfProcess ospfProcess; | ||
54 | + private OspfArea ospfArea; | ||
55 | + private OspfInterface ospfInterface; | ||
56 | + private List<OspfInterface> ospfInterfaces; | ||
57 | + private List<OspfArea> ospfAreas; | ||
58 | + private List<OspfProcess> ospfProcesses; | ||
59 | + private OspfProcess ospfProcess1; | ||
60 | + private OspfArea ospfArea1; | ||
61 | + private OspfRouter ospfRouter; | ||
62 | + | ||
63 | + @Before | ||
64 | + public void setUp() throws Exception { | ||
65 | + controller = new Controller(); | ||
66 | + maps = new HashMap<String, Long>(); | ||
67 | + ospfProcess = new OspfProcessImpl(); | ||
68 | + ospfArea = new OspfAreaImpl(); | ||
69 | + ospfInterface = new OspfInterfaceImpl(); | ||
70 | + ospfInterfaces = new ArrayList(); | ||
71 | + ospfInterface.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
72 | + ospfInterfaces.add(ospfInterface); | ||
73 | + ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2")); | ||
74 | + ospfArea.setInterfacesLst(ospfInterfaces); | ||
75 | + ospfProcess.setProcessId("10.10.10.10"); | ||
76 | + ospfAreas = new ArrayList(); | ||
77 | + ospfAreas.add(ospfArea); | ||
78 | + ospfProcess.setAreas(ospfAreas); | ||
79 | + ospfProcesses = new ArrayList(); | ||
80 | + ospfProcesses.add(ospfProcess); | ||
81 | + ospfProcess1 = new OspfProcessImpl(); | ||
82 | + ospfProcess1.setProcessId("11.11.11.11"); | ||
83 | + ospfArea1 = new OspfAreaImpl(); | ||
84 | + ospfArea1.setAreaId(Ip4Address.valueOf("2.2.2.2")); | ||
85 | + ospfArea1.setInterfacesLst(ospfInterfaces); | ||
86 | + ospfAreas.add(ospfArea1); | ||
87 | + ospfProcess1.setAreas(ospfAreas); | ||
88 | + ospfProcesses.add(ospfProcess1); | ||
89 | + connectedChannels = new ArrayList<>(); | ||
90 | + } | ||
91 | + | ||
92 | + @After | ||
93 | + public void tearDown() throws Exception { | ||
94 | + controller = null; | ||
95 | + maps.clear(); | ||
96 | + connectedChannels.clear(); | ||
97 | + controller = null; | ||
98 | + maps = null; | ||
99 | + ospfAgent = null; | ||
100 | + driverService = null; | ||
101 | + connectedChannels = null; | ||
102 | + process = null; | ||
103 | + ospfProcess = null; | ||
104 | + ospfArea = null; | ||
105 | + ospfInterface = null; | ||
106 | + ospfInterfaces = null; | ||
107 | + ospfAreas = null; | ||
108 | + ospfProcesses = null; | ||
109 | + ospfProcess1 = null; | ||
110 | + ospfArea1 = null; | ||
111 | + } | ||
112 | + | ||
113 | + /** | ||
114 | + * Tests getAllConfiguredProcesses() method. | ||
115 | + */ | ||
116 | + @Test | ||
117 | + public void testGetAllConfiguredProcesses() throws Exception { | ||
118 | + process = controller.getAllConfiguredProcesses(); | ||
119 | + assertThat(process, is(nullValue())); | ||
120 | + } | ||
121 | + | ||
122 | + /** | ||
123 | + * Tests addDeviceDetails() method. | ||
124 | + */ | ||
125 | + @Test(expected = Exception.class) | ||
126 | + public void testAddDeviceDetails() throws Exception { | ||
127 | + controller.addDeviceDetails(new OspfRouterImpl()); | ||
128 | + assertThat(controller, is(notNullValue())); | ||
129 | + } | ||
130 | + | ||
131 | + /** | ||
132 | + * Tests removeDeviceDetails() method. | ||
133 | + */ | ||
134 | + @Test(expected = Exception.class) | ||
135 | + public void testRemoveDeviceDetails() throws Exception { | ||
136 | + controller.removeDeviceDetails(new OspfRouterImpl()); | ||
137 | + assertThat(controller, is(notNullValue())); | ||
138 | + } | ||
139 | + | ||
140 | + /** | ||
141 | + * Tests init() method. | ||
142 | + */ | ||
143 | + @Test | ||
144 | + public void testInit() throws Exception { | ||
145 | + controller.init(); | ||
146 | + assertThat(controller.systemStartTime, is(notNullValue())); | ||
147 | + } | ||
148 | + | ||
149 | + /** | ||
150 | + * Tests start() method. | ||
151 | + */ | ||
152 | + @Test | ||
153 | + public void testStart() throws Exception { | ||
154 | + ospfAgent = EasyMock.createMock(OspfAgent.class); | ||
155 | + controller.start(ospfAgent, driverService); | ||
156 | + controller.updateConfig(ospfProcesses); | ||
157 | + assertThat(controller, is(notNullValue())); | ||
158 | + } | ||
159 | + | ||
160 | + /** | ||
161 | + * Tests stop() method. | ||
162 | + */ | ||
163 | + @Test(expected = Exception.class) | ||
164 | + public void testStop() throws Exception { | ||
165 | + controller.start(ospfAgent, driverService); | ||
166 | + controller.stop(); | ||
167 | + assertThat(controller, is(notNullValue())); | ||
168 | + } | ||
169 | + | ||
170 | + /** | ||
171 | + * Tests deleteInterfaceFromArea() method. | ||
172 | + */ | ||
173 | + @Test | ||
174 | + public void testDeleteInterfaceFromArea() throws Exception { | ||
175 | + controller.updateConfig(ospfProcesses); | ||
176 | + assertThat(controller.deleteInterfaceFromArea("10.10.10.10", "2.2.2.2", "1.1.1.1"), is(true)); | ||
177 | + assertThat(controller.deleteInterfaceFromArea("10.10.10.10", "2.2.2.2", "5.5.5.5"), is(false)); | ||
178 | + } | ||
179 | + | ||
180 | + /** | ||
181 | + * Tests checkArea() method. | ||
182 | + */ | ||
183 | + @Test | ||
184 | + public void testCheckArea() throws Exception { | ||
185 | + controller.updateConfig(ospfProcesses); | ||
186 | + assertThat(controller.checkArea("10.10.10.10", "2.2.2.2"), is(true)); | ||
187 | + } | ||
188 | + | ||
189 | + /** | ||
190 | + * Tests checkArea() method. | ||
191 | + */ | ||
192 | + @Test | ||
193 | + public void testCheckArea1() throws Exception { | ||
194 | + controller.updateConfig(ospfProcesses); | ||
195 | + assertThat(controller.checkArea("10.10.10.10", "111.111.111.111"), is(false)); | ||
196 | + } | ||
197 | + | ||
198 | + /** | ||
199 | + * Tests checkProcess() method. | ||
200 | + */ | ||
201 | + @Test | ||
202 | + public void testCheckProcess() throws Exception { | ||
203 | + controller.updateConfig(ospfProcesses); | ||
204 | + assertThat(controller.checkProcess("3.3.3.3"), is(false)); | ||
205 | + assertThat(controller.checkProcess("1.1.1.1"), is(false)); | ||
206 | + } | ||
207 | + | ||
208 | + /** | ||
209 | + * Tests checkInterface() method. | ||
210 | + */ | ||
211 | + @Test | ||
212 | + public void testCheckInterface() throws Exception { | ||
213 | + controller.updateConfig(ospfProcesses); | ||
214 | + assertThat(controller.checkInterface("10.10.10.10", "2.2.2.2", "1.1.1.1"), is(true)); | ||
215 | + } | ||
216 | + | ||
217 | + /** | ||
218 | + * Tests updateAreaInProcess() method. | ||
219 | + */ | ||
220 | + @Test | ||
221 | + public void testUpdateAreaInProcess() throws Exception { | ||
222 | + controller.updateConfig(ospfProcesses); | ||
223 | + controller.updateAreaInProcess("10.10.10.10", "2.2.2.2", ospfArea); | ||
224 | + assertThat(controller, is(notNullValue())); | ||
225 | + } | ||
226 | + | ||
227 | + /** | ||
228 | + * Tests updateConfig() method. | ||
229 | + */ | ||
230 | + @Test | ||
231 | + public void testUpdateConfig() throws Exception { | ||
232 | + controller.updateConfig(ospfProcesses); | ||
233 | + controller.updateConfig(ospfProcesses); | ||
234 | + controller.updateConfig(ospfProcesses); | ||
235 | + assertThat(controller, is(notNullValue())); | ||
236 | + } | ||
237 | + | ||
238 | + /** | ||
239 | + * Tests updateConfig() method. | ||
240 | + */ | ||
241 | + @Test | ||
242 | + public void testUpdateConfig2() throws Exception { | ||
243 | + controller.updateConfig(ospfProcesses); | ||
244 | + controller.updateConfig(ospfProcesses); | ||
245 | + assertThat(controller, is(notNullValue())); | ||
246 | + } | ||
247 | + | ||
248 | + /** | ||
249 | + * Tests updateConfig() method. | ||
250 | + */ | ||
251 | + @Test | ||
252 | + public void testUpdateConfig1() throws Exception { | ||
253 | + ospfProcess = new OspfProcessImpl(); | ||
254 | + ospfArea = new OspfAreaImpl(); | ||
255 | + ospfInterface = new OspfInterfaceImpl(); | ||
256 | + ospfInterfaces = new ArrayList(); | ||
257 | + ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.5")); | ||
258 | + ospfInterfaces.add(ospfInterface); | ||
259 | + ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2")); | ||
260 | + ospfArea.setInterfacesLst(ospfInterfaces); | ||
261 | + ospfProcess.setProcessId("10.10.10.10"); | ||
262 | + ospfAreas = new ArrayList(); | ||
263 | + ospfAreas.add(ospfArea); | ||
264 | + ospfProcess.setAreas(ospfAreas); | ||
265 | + ospfProcesses = new ArrayList(); | ||
266 | + ospfProcesses.add(ospfProcess); | ||
267 | + controller.updateConfig(ospfProcesses); | ||
268 | + assertThat(controller, is(notNullValue())); | ||
269 | + } | ||
270 | + | ||
271 | + /** | ||
272 | + * Tests deleteConfig() method. | ||
273 | + */ | ||
274 | + @Test(expected = Exception.class) | ||
275 | + public void testDeleteConfig() throws Exception { | ||
276 | + controller.updateConfig(ospfProcesses); | ||
277 | + controller.deleteConfig(ospfProcesses, "INTERFACE"); | ||
278 | + assertThat(controller, is(notNullValue())); | ||
279 | + } | ||
280 | + | ||
281 | + /** | ||
282 | + * Tests deleteConfig() method. | ||
283 | + */ | ||
284 | + @Test(expected = Exception.class) | ||
285 | + public void testDeleteConfig1() throws Exception { | ||
286 | + controller.updateConfig(ospfProcesses); | ||
287 | + controller.deleteConfig(ospfProcesses, "AREA"); | ||
288 | + assertThat(controller, is(notNullValue())); | ||
289 | + } | ||
290 | + | ||
291 | + /** | ||
292 | + * Tests deleteConfig() method. | ||
293 | + */ | ||
294 | + | ||
295 | + @Test | ||
296 | + public void testDeleteConfig2() throws Exception { | ||
297 | + controller.updateConfig(ospfProcesses); | ||
298 | + controller.deleteConfig(ospfProcesses, "PROCESS"); | ||
299 | + assertThat(controller, is(notNullValue())); | ||
300 | + } | ||
301 | + | ||
302 | + /** | ||
303 | + * Tests deleteConfig() method. | ||
304 | + */ | ||
305 | + @Test | ||
306 | + public void testDeleteConfig3() throws Exception { | ||
307 | + ospfProcesses = new ArrayList(); | ||
308 | + controller.deleteConfig(ospfProcesses, "PROCESS"); | ||
309 | + assertThat(controller, is(notNullValue())); | ||
310 | + } | ||
311 | + | ||
312 | + /** | ||
313 | + * Tests deleteConfig() method. | ||
314 | + */ | ||
315 | + @Test | ||
316 | + public void testDeleteConfig4() throws Exception { | ||
317 | + controller.updateConfig(ospfProcesses); | ||
318 | + controller.deleteConfig(ospfProcesses, "PROCESS"); | ||
319 | + controller.updateConfig(ospfProcesses); | ||
320 | + assertThat(controller, is(notNullValue())); | ||
321 | + } | ||
322 | + | ||
323 | + /** | ||
324 | + * Tests deleteProcessWhenExists() method. | ||
325 | + */ | ||
326 | + @Test | ||
327 | + public void testDeleteProcessWhenExists() throws Exception { | ||
328 | + controller.updateConfig(ospfProcesses); | ||
329 | + controller.deleteProcessWhenExists(ospfProcesses, "PROCESS"); | ||
330 | + } | ||
331 | + | ||
332 | + /** | ||
333 | + * Tests addLinkDetails() method. | ||
334 | + */ | ||
335 | + @Test | ||
336 | + public void testAddLinkDetails() throws Exception { | ||
337 | + ospfAgent = EasyMock.createMock(OspfAgent.class); | ||
338 | + controller.start(ospfAgent, driverService); | ||
339 | + ospfRouter = new OspfRouterImpl(); | ||
340 | + controller.addLinkDetails(ospfRouter, new OspfLinkTedImpl()); | ||
341 | + assertThat(controller, is(notNullValue())); | ||
342 | + } | ||
343 | + | ||
344 | + /** | ||
345 | + * Tests removeLinkDetails() method. | ||
346 | + */ | ||
347 | + @Test | ||
348 | + public void testRemoveLinkDetails() throws Exception { | ||
349 | + ospfAgent = EasyMock.createMock(OspfAgent.class); | ||
350 | + controller.start(ospfAgent, driverService); | ||
351 | + ospfRouter = new OspfRouterImpl(); | ||
352 | + controller.addLinkDetails(ospfRouter, new OspfLinkTedImpl()); | ||
353 | + controller.removeLinkDetails(ospfRouter); | ||
354 | + assertThat(controller, is(notNullValue())); | ||
355 | + } | ||
356 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/DeviceInformationImplTest.java
0 → 100755
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.impl; | ||
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.junit.Assert.assertThat; | ||
25 | + | ||
26 | +/** | ||
27 | + * Unit test class for DeviceInformationImpl. | ||
28 | + */ | ||
29 | +public class DeviceInformationImplTest { | ||
30 | + | ||
31 | + private DeviceInformationImpl deviceInformation; | ||
32 | + | ||
33 | + @Before | ||
34 | + public void setUp() throws Exception { | ||
35 | + deviceInformation = new DeviceInformationImpl(); | ||
36 | + } | ||
37 | + | ||
38 | + @After | ||
39 | + public void tearDown() throws Exception { | ||
40 | + deviceInformation = null; | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * Tests routerId() getter method. | ||
45 | + */ | ||
46 | + @Test | ||
47 | + public void testRouterId() throws Exception { | ||
48 | + deviceInformation.setRouterId(Ip4Address.valueOf("1.1.1.1")); | ||
49 | + assertThat(deviceInformation.routerId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * Tests routerId() setter method. | ||
54 | + */ | ||
55 | + @Test | ||
56 | + public void testSetRouterId() throws Exception { | ||
57 | + deviceInformation.setRouterId(Ip4Address.valueOf("1.1.1.1")); | ||
58 | + assertThat(deviceInformation.routerId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * Tests deviceId() getter method. | ||
63 | + */ | ||
64 | + @Test | ||
65 | + public void testDeviceId() throws Exception { | ||
66 | + deviceInformation.setDeviceId(Ip4Address.valueOf("1.1.1.1")); | ||
67 | + assertThat(deviceInformation.deviceId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * Tests deviceId() getter method. | ||
72 | + */ | ||
73 | + @Test | ||
74 | + public void testSetDeviceId() throws Exception { | ||
75 | + deviceInformation.setDeviceId(Ip4Address.valueOf("1.1.1.1")); | ||
76 | + assertThat(deviceInformation.deviceId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
77 | + } | ||
78 | + | ||
79 | + /** | ||
80 | + * Tests interfaceId() method. | ||
81 | + */ | ||
82 | + @Test | ||
83 | + public void testInterfaceId() throws Exception { | ||
84 | + deviceInformation.addInterfaceId(Ip4Address.valueOf("1.1.1.1")); | ||
85 | + assertThat(deviceInformation.interfaceId().size(), is(1)); | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * Tests addInterfaceId() method. | ||
90 | + */ | ||
91 | + @Test | ||
92 | + public void testAddInterfaceId() throws Exception { | ||
93 | + deviceInformation.addInterfaceId(Ip4Address.valueOf("1.1.1.1")); | ||
94 | + assertThat(deviceInformation.interfaceId().size(), is(1)); | ||
95 | + } | ||
96 | + | ||
97 | + /** | ||
98 | + * Tests areaId() getter method. | ||
99 | + */ | ||
100 | + @Test | ||
101 | + public void testAreaId() throws Exception { | ||
102 | + deviceInformation.setAreaId(Ip4Address.valueOf("1.1.1.1")); | ||
103 | + assertThat(deviceInformation.areaId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * Tests areaId() setter method. | ||
108 | + */ | ||
109 | + @Test | ||
110 | + public void testSetAreaId() throws Exception { | ||
111 | + deviceInformation.setAreaId(Ip4Address.valueOf("1.1.1.1")); | ||
112 | + assertThat(deviceInformation.areaId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
113 | + } | ||
114 | + | ||
115 | + /** | ||
116 | + * Tests isAlreadyCreated() getter method. | ||
117 | + */ | ||
118 | + @Test | ||
119 | + public void testIsAlreadyCreated() throws Exception { | ||
120 | + deviceInformation.setAlreadyCreated(true); | ||
121 | + assertThat(deviceInformation.isAlreadyCreated(), is(true)); | ||
122 | + } | ||
123 | + | ||
124 | + /** | ||
125 | + * Tests isAlreadyCreated() setter method. | ||
126 | + */ | ||
127 | + @Test | ||
128 | + public void testSetAlreadyCreated() throws Exception { | ||
129 | + deviceInformation.setAlreadyCreated(true); | ||
130 | + assertThat(deviceInformation.isAlreadyCreated(), is(true)); | ||
131 | + } | ||
132 | + | ||
133 | + /** | ||
134 | + * Tests isDr() getter method. | ||
135 | + */ | ||
136 | + @Test | ||
137 | + public void testIsDr() throws Exception { | ||
138 | + deviceInformation.setDr(true); | ||
139 | + assertThat(deviceInformation.isDr(), is(true)); | ||
140 | + } | ||
141 | + | ||
142 | + /** | ||
143 | + * Tests isDr() setter method. | ||
144 | + */ | ||
145 | + @Test | ||
146 | + public void testSetDr() throws Exception { | ||
147 | + deviceInformation.setDr(true); | ||
148 | + assertThat(deviceInformation.isDr(), is(true)); | ||
149 | + } | ||
150 | + | ||
151 | + /** | ||
152 | + * Tests neighborId() getter method. | ||
153 | + */ | ||
154 | + @Test | ||
155 | + public void testNeighborId() throws Exception { | ||
156 | + deviceInformation.setNeighborId(Ip4Address.valueOf("1.1.1.1")); | ||
157 | + assertThat(deviceInformation.neighborId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
158 | + } | ||
159 | + | ||
160 | + /** | ||
161 | + * Tests neighborId() setter method. | ||
162 | + */ | ||
163 | + @Test | ||
164 | + public void testSetNeighborId() throws Exception { | ||
165 | + deviceInformation.setNeighborId(Ip4Address.valueOf("1.1.1.1")); | ||
166 | + assertThat(deviceInformation.neighborId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
167 | + } | ||
168 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/LinkInformationImplTest.java
0 → 100755
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.impl; | ||
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.junit.Assert.assertThat; | ||
25 | + | ||
26 | +/** | ||
27 | + * Unit test class for LinkInformationImpl. | ||
28 | + */ | ||
29 | +public class LinkInformationImplTest { | ||
30 | + | ||
31 | + private LinkInformationImpl linkInformation; | ||
32 | + | ||
33 | + @Before | ||
34 | + public void setUp() throws Exception { | ||
35 | + linkInformation = new LinkInformationImpl(); | ||
36 | + } | ||
37 | + | ||
38 | + @After | ||
39 | + public void tearDown() throws Exception { | ||
40 | + linkInformation = null; | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * Tests linkId() getter method. | ||
45 | + */ | ||
46 | + @Test | ||
47 | + public void testLinkId() throws Exception { | ||
48 | + linkInformation.setLinkId("1.1.1.1"); | ||
49 | + assertThat(linkInformation.linkId(), is("1.1.1.1")); | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * Tests linkId() setter method. | ||
54 | + */ | ||
55 | + @Test | ||
56 | + public void testSetLinkId() throws Exception { | ||
57 | + linkInformation.setLinkId("1.1.1.1"); | ||
58 | + assertThat(linkInformation.linkId(), is("1.1.1.1")); | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * Tests isAlreadyCreated() getter method. | ||
63 | + */ | ||
64 | + @Test | ||
65 | + public void testIsAlreadyCreated() throws Exception { | ||
66 | + linkInformation.setAlreadyCreated(true); | ||
67 | + assertThat(linkInformation.isAlreadyCreated(), is(true)); | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * Tests isAlreadyCreated() setter method. | ||
72 | + */ | ||
73 | + @Test | ||
74 | + public void testSetAlreadyCreated() throws Exception { | ||
75 | + linkInformation.setAlreadyCreated(true); | ||
76 | + assertThat(linkInformation.isAlreadyCreated(), is(true)); | ||
77 | + } | ||
78 | + | ||
79 | + /** | ||
80 | + * Tests isLinkSrcIdNotRouterId() getter method. | ||
81 | + */ | ||
82 | + @Test | ||
83 | + public void testIsLinkSrcIdNotRouterId() throws Exception { | ||
84 | + linkInformation.setLinkSrcIdNotRouterId(true); | ||
85 | + assertThat(linkInformation.isLinkSrcIdNotRouterId(), is(true)); | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * Tests isLinkSrcIdNotRouterId() setter method. | ||
90 | + */ | ||
91 | + @Test | ||
92 | + public void testSetLinkSrcIdNotRouterId() throws Exception { | ||
93 | + linkInformation.setLinkSrcIdNotRouterId(true); | ||
94 | + assertThat(linkInformation.isLinkSrcIdNotRouterId(), is(true)); | ||
95 | + } | ||
96 | + | ||
97 | + /** | ||
98 | + * Tests linkDestinationId() getter method. | ||
99 | + */ | ||
100 | + @Test | ||
101 | + public void testLinkDestinationId() throws Exception { | ||
102 | + linkInformation.setLinkDestinationId(Ip4Address.valueOf("1.1.1.1")); | ||
103 | + assertThat(linkInformation.linkDestinationId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * Tests linkDestinationId() setter method. | ||
108 | + */ | ||
109 | + @Test | ||
110 | + public void testSetLinkDestinationId() throws Exception { | ||
111 | + linkInformation.setLinkDestinationId(Ip4Address.valueOf("1.1.1.1")); | ||
112 | + assertThat(linkInformation.linkDestinationId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
113 | + } | ||
114 | + | ||
115 | + /** | ||
116 | + * Tests linkSourceId() getter method. | ||
117 | + */ | ||
118 | + @Test | ||
119 | + public void testLinkSourceId() throws Exception { | ||
120 | + linkInformation.setLinkSourceId(Ip4Address.valueOf("1.1.1.1")); | ||
121 | + assertThat(linkInformation.linkSourceId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
122 | + } | ||
123 | + | ||
124 | + /** | ||
125 | + * Tests linkSourceId() setter method. | ||
126 | + */ | ||
127 | + @Test | ||
128 | + public void testSetLinkSourceId() throws Exception { | ||
129 | + linkInformation.setLinkSourceId(Ip4Address.valueOf("1.1.1.1")); | ||
130 | + assertThat(linkInformation.linkSourceId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
131 | + } | ||
132 | + | ||
133 | + /** | ||
134 | + * Tests interfaceIp() getter method. | ||
135 | + */ | ||
136 | + @Test | ||
137 | + public void testInterfaceIp() throws Exception { | ||
138 | + linkInformation.setInterfaceIp(Ip4Address.valueOf("1.1.1.1")); | ||
139 | + assertThat(linkInformation.interfaceIp(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
140 | + } | ||
141 | + | ||
142 | + /** | ||
143 | + * Tests interfaceIp() setter method. | ||
144 | + */ | ||
145 | + @Test | ||
146 | + public void testSetInterfaceIp() throws Exception { | ||
147 | + linkInformation.setInterfaceIp(Ip4Address.valueOf("1.1.1.1")); | ||
148 | + assertThat(linkInformation.interfaceIp(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
149 | + } | ||
150 | + | ||
151 | + /** | ||
152 | + * Tests linkSourceIpAddress() getter method. | ||
153 | + */ | ||
154 | + @Test | ||
155 | + public void testLinkSourceIpAddress() throws Exception { | ||
156 | + linkInformation.setLinkSourceIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
157 | + assertThat(linkInformation.linkSourceIpAddress(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
158 | + } | ||
159 | + | ||
160 | + /** | ||
161 | + * Tests linkSourceIpAddress() setter method. | ||
162 | + */ | ||
163 | + @Test | ||
164 | + public void testSetLinkSourceIpAddress() throws Exception { | ||
165 | + linkInformation.setLinkSourceIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
166 | + assertThat(linkInformation.linkSourceIpAddress(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
167 | + } | ||
168 | + | ||
169 | + /** | ||
170 | + * Tests linkDestinationId() getter method. | ||
171 | + */ | ||
172 | + @Test | ||
173 | + public void testLinkDestinationIpAddress() throws Exception { | ||
174 | + linkInformation.setLinkDestinationIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
175 | + assertThat(linkInformation.linkDestinationIpAddress(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
176 | + } | ||
177 | + | ||
178 | + /** | ||
179 | + * Tests linkDestinationId() setter method. | ||
180 | + */ | ||
181 | + @Test | ||
182 | + public void testSetLinkDestinationIpAddress() throws Exception { | ||
183 | + linkInformation.setLinkDestinationIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
184 | + assertThat(linkInformation.linkDestinationIpAddress(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
185 | + } | ||
186 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfControllerImplTest.java
0 → 100755
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.impl; | ||
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.OspfArea; | ||
25 | +import org.onosproject.ospf.controller.OspfInterface; | ||
26 | +import org.onosproject.ospf.controller.OspfLinkListener; | ||
27 | +import org.onosproject.ospf.controller.OspfProcess; | ||
28 | +import org.onosproject.ospf.controller.OspfRouter; | ||
29 | +import org.onosproject.ospf.controller.OspfRouterListener; | ||
30 | +import org.onosproject.ospf.controller.area.OspfAreaImpl; | ||
31 | +import org.onosproject.ospf.controller.area.OspfInterfaceImpl; | ||
32 | +import org.onosproject.ospf.controller.area.OspfProcessImpl; | ||
33 | + | ||
34 | +import java.util.ArrayList; | ||
35 | +import java.util.List; | ||
36 | + | ||
37 | +import static org.hamcrest.CoreMatchers.is; | ||
38 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
39 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
40 | + | ||
41 | +/** | ||
42 | + * Unit test class for OspfRouterId. | ||
43 | + */ | ||
44 | +public class OspfControllerImplTest { | ||
45 | + | ||
46 | + private OspfControllerImpl ospfController; | ||
47 | + private OspfRouterListener ospfRouterListener; | ||
48 | + private OspfLinkListener ospfLinkListener; | ||
49 | + private Controller controller; | ||
50 | + private List<OspfProcess> ospfProcesses; | ||
51 | + private OspfProcess process1; | ||
52 | + private OspfProcess process2; | ||
53 | + private List<OspfArea> areas; | ||
54 | + private OspfAreaImpl ospfArea; | ||
55 | + private List<OspfInterface> ospfInterfaces; | ||
56 | + private OspfInterfaceImpl ospfInterface; | ||
57 | + private OspfProcess ospfProcess; | ||
58 | + private OspfArea ospfArea1; | ||
59 | + private OspfRouter ospfRouter; | ||
60 | + | ||
61 | + @Before | ||
62 | + public void setUp() throws Exception { | ||
63 | + ospfController = new OspfControllerImpl(); | ||
64 | + controller = new Controller(); | ||
65 | + } | ||
66 | + | ||
67 | + @After | ||
68 | + public void tearDown() throws Exception { | ||
69 | + ospfController = null; | ||
70 | + ospfRouterListener = null; | ||
71 | + ospfLinkListener = null; | ||
72 | + controller = null; | ||
73 | + ospfProcesses = null; | ||
74 | + areas = null; | ||
75 | + ospfArea = null; | ||
76 | + ospfInterfaces = null; | ||
77 | + ospfInterface = null; | ||
78 | + ospfProcess = null; | ||
79 | + ospfProcess = null; | ||
80 | + ospfArea1 = null; | ||
81 | + ospfRouter = null; | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * Tests activate() method. | ||
86 | + */ | ||
87 | + @Test | ||
88 | + public void testActivate() throws Exception { | ||
89 | + ospfController.activate(); | ||
90 | + assertThat(ospfController, is(notNullValue())); | ||
91 | + } | ||
92 | + | ||
93 | + @Test(expected = Exception.class) | ||
94 | + public void testDeactivate() throws Exception { | ||
95 | + ospfController.activate(); | ||
96 | + ospfController.deactivate(); | ||
97 | + assertThat(ospfController, is(notNullValue())); | ||
98 | + } | ||
99 | + | ||
100 | + /** | ||
101 | + * Tests addRouterListener() method. | ||
102 | + */ | ||
103 | + @Test | ||
104 | + public void testAddRouterListener() throws Exception { | ||
105 | + ospfRouterListener = EasyMock.createMock(OspfRouterListener.class); | ||
106 | + ospfController.addRouterListener(ospfRouterListener); | ||
107 | + assertThat(ospfController, is(notNullValue())); | ||
108 | + } | ||
109 | + | ||
110 | + /** | ||
111 | + * Tests removeRouterListener() method. | ||
112 | + */ | ||
113 | + @Test | ||
114 | + public void testRemoveRouterListener() throws Exception { | ||
115 | + ospfRouterListener = EasyMock.createMock(OspfRouterListener.class); | ||
116 | + ospfController.addRouterListener(ospfRouterListener); | ||
117 | + ospfController.removeRouterListener(ospfRouterListener); | ||
118 | + assertThat(ospfController, is(notNullValue())); | ||
119 | + } | ||
120 | + | ||
121 | + /** | ||
122 | + * Tests addLinkListener() method. | ||
123 | + */ | ||
124 | + @Test | ||
125 | + public void testAddLinkListener() throws Exception { | ||
126 | + ospfLinkListener = EasyMock.createMock(OspfLinkListener.class); | ||
127 | + ospfController.addLinkListener(ospfLinkListener); | ||
128 | + assertThat(ospfController, is(notNullValue())); | ||
129 | + } | ||
130 | + | ||
131 | + /** | ||
132 | + * Tests removeLinkListener() method. | ||
133 | + */ | ||
134 | + @Test | ||
135 | + public void testRemoveLinkListener() throws Exception { | ||
136 | + ospfLinkListener = EasyMock.createMock(OspfLinkListener.class); | ||
137 | + ospfController.addLinkListener(ospfLinkListener); | ||
138 | + ospfController.removeLinkListener(ospfLinkListener); | ||
139 | + assertThat(ospfController, is(notNullValue())); | ||
140 | + } | ||
141 | + | ||
142 | + /** | ||
143 | + * Tests updateConfig() method. | ||
144 | + */ | ||
145 | + @Test | ||
146 | + public void testUpdateConfig() throws Exception { | ||
147 | + ospfProcess = new OspfProcessImpl(); | ||
148 | + ospfArea = new OspfAreaImpl(); | ||
149 | + ospfInterface = new OspfInterfaceImpl(); | ||
150 | + ospfInterfaces = new ArrayList(); | ||
151 | + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11")); | ||
152 | + ospfInterfaces.add(ospfInterface); | ||
153 | + ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2")); | ||
154 | + ospfArea.setInterfacesLst(ospfInterfaces); | ||
155 | + ospfProcess.setProcessId("10.10.10.10"); | ||
156 | + areas = new ArrayList(); | ||
157 | + areas.add(ospfArea); | ||
158 | + ospfProcess.setAreas(areas); | ||
159 | + ospfProcesses = new ArrayList(); | ||
160 | + ospfProcesses.add(ospfProcess); | ||
161 | + process1 = new OspfProcessImpl(); | ||
162 | + process1.setProcessId("11.11.11.11"); | ||
163 | + ospfArea1 = new OspfAreaImpl(); | ||
164 | + ospfArea1.setAreaId(Ip4Address.valueOf("2.2.2.2")); | ||
165 | + ospfArea1.setInterfacesLst(ospfInterfaces); | ||
166 | + areas.add(ospfArea1); | ||
167 | + process1.setAreas(areas); | ||
168 | + ospfProcesses.add(process1); | ||
169 | + ospfController.updateConfig(ospfProcesses); | ||
170 | + assertThat(ospfController, is(notNullValue())); | ||
171 | + | ||
172 | + } | ||
173 | + | ||
174 | + /** | ||
175 | + * Tests deleteConfig() method. | ||
176 | + */ | ||
177 | + @Test | ||
178 | + public void testDeleteConfig() throws Exception { | ||
179 | + ospfProcess = new OspfProcessImpl(); | ||
180 | + ospfArea = new OspfAreaImpl(); | ||
181 | + ospfInterface = new OspfInterfaceImpl(); | ||
182 | + ospfInterfaces = new ArrayList(); | ||
183 | + ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.5")); | ||
184 | + ospfInterfaces.add(ospfInterface); | ||
185 | + ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2")); | ||
186 | + ospfArea.setInterfacesLst(ospfInterfaces); | ||
187 | + ospfProcess.setProcessId("10.10.10.10"); | ||
188 | + areas = new ArrayList(); | ||
189 | + areas.add(ospfArea); | ||
190 | + ospfProcess.setAreas(areas); | ||
191 | + ospfProcesses = new ArrayList(); | ||
192 | + ospfProcesses.add(ospfProcess); | ||
193 | + process1 = new OspfProcessImpl(); | ||
194 | + process1.setProcessId("11.11.11.11"); | ||
195 | + ospfArea1 = new OspfAreaImpl(); | ||
196 | + ospfArea1.setAreaId(Ip4Address.valueOf("2.2.2.2")); | ||
197 | + ospfArea1.setInterfacesLst(ospfInterfaces); | ||
198 | + areas.add(ospfArea1); | ||
199 | + process1.setAreas(areas); | ||
200 | + ospfProcesses.add(process1); | ||
201 | + ospfController.deleteConfig(ospfProcesses, "INTERFACE"); | ||
202 | + assertThat(ospfController, is(notNullValue())); | ||
203 | + } | ||
204 | + | ||
205 | + /** | ||
206 | + * Tests addLink() method. | ||
207 | + */ | ||
208 | + @Test | ||
209 | + public void testAddLink() throws Exception { | ||
210 | + ospfRouter = new OspfRouterImpl(); | ||
211 | + | ||
212 | + ospfController.agent.addLink(ospfRouter, new OspfLinkTedImpl()); | ||
213 | + assertThat(ospfController, is(notNullValue())); | ||
214 | + } | ||
215 | + | ||
216 | + /** | ||
217 | + * Tests deleteLink() method. | ||
218 | + */ | ||
219 | + @Test | ||
220 | + public void testDeleteLink() throws Exception { | ||
221 | + ospfRouter = new OspfRouterImpl(); | ||
222 | + | ||
223 | + ospfController.agent.addLink(ospfRouter, new OspfLinkTedImpl()); | ||
224 | + ospfController.agent.deleteLink(ospfRouter); | ||
225 | + assertThat(ospfController, is(notNullValue())); | ||
226 | + } | ||
227 | + | ||
228 | + /** | ||
229 | + * Tests listener() method. | ||
230 | + */ | ||
231 | + @Test | ||
232 | + public void testListener() throws Exception { | ||
233 | + assertThat(ospfController.listener().size(), is(0)); | ||
234 | + } | ||
235 | + | ||
236 | + /** | ||
237 | + * Tests linkListener() method. | ||
238 | + */ | ||
239 | + @Test | ||
240 | + public void testLinkListener() throws Exception { | ||
241 | + assertThat(ospfController.linkListener().size(), is(0)); | ||
242 | + } | ||
243 | + | ||
244 | + /** | ||
245 | + * Tests addConnectedRouter() method. | ||
246 | + */ | ||
247 | + @Test | ||
248 | + public void testaddConnectedRouter() throws Exception { | ||
249 | + ospfRouter = new OspfRouterImpl(); | ||
250 | + | ||
251 | + ospfController.agent.addConnectedRouter(ospfRouter); | ||
252 | + assertThat(ospfController, is(notNullValue())); | ||
253 | + } | ||
254 | + | ||
255 | + /** | ||
256 | + * Tests removeConnectedRouter() method. | ||
257 | + */ | ||
258 | + @Test | ||
259 | + public void testRemoveConnectedRouter() throws Exception { | ||
260 | + ospfRouter = new OspfRouterImpl(); | ||
261 | + | ||
262 | + ospfController.agent.addConnectedRouter(ospfRouter); | ||
263 | + ospfController.agent.removeConnectedRouter(ospfRouter); | ||
264 | + assertThat(ospfController, is(notNullValue())); | ||
265 | + } | ||
266 | + | ||
267 | + /** | ||
268 | + * Tests getAllConfiguredProcesses() method. | ||
269 | + */ | ||
270 | + @Test(expected = Exception.class) | ||
271 | + public void testGetAllConfiguredProcesses() throws Exception { | ||
272 | + assertThat(ospfController.getAllConfiguredProcesses().size(), is(0)); | ||
273 | + } | ||
274 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfDeviceTedImplTest.java
0 → 100755
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.impl; | ||
17 | + | ||
18 | +import org.junit.After; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | +import org.onlab.packet.Ip4Address; | ||
22 | +import org.onlab.packet.Ip6Address; | ||
23 | + | ||
24 | +import java.net.InetAddress; | ||
25 | +import java.util.ArrayList; | ||
26 | +import java.util.List; | ||
27 | + | ||
28 | +import static org.hamcrest.CoreMatchers.is; | ||
29 | +import static org.junit.Assert.assertThat; | ||
30 | + | ||
31 | +/** | ||
32 | + * Unit test class for OspfDeviceTedImpl. | ||
33 | + */ | ||
34 | +public class OspfDeviceTedImplTest { | ||
35 | + private OspfDeviceTedImpl ospfDeviceTed; | ||
36 | + | ||
37 | + @Before | ||
38 | + public void setUp() throws Exception { | ||
39 | + ospfDeviceTed = new OspfDeviceTedImpl(); | ||
40 | + } | ||
41 | + | ||
42 | + @After | ||
43 | + public void tearDown() throws Exception { | ||
44 | + ospfDeviceTed = null; | ||
45 | + } | ||
46 | + | ||
47 | + /** | ||
48 | + * Tests ipv4RouterIds() getter method. | ||
49 | + */ | ||
50 | + @Test | ||
51 | + public void testIpv4RouterIds() throws Exception { | ||
52 | + List list = new ArrayList(); | ||
53 | + list.add(Ip4Address.valueOf("1.1.1.1")); | ||
54 | + ospfDeviceTed.setIpv4RouterIds(list); | ||
55 | + assertThat(ospfDeviceTed.ipv4RouterIds().size(), is(1)); | ||
56 | + } | ||
57 | + | ||
58 | + /** | ||
59 | + * Tests ipv4RouterIds() setter method. | ||
60 | + */ | ||
61 | + @Test | ||
62 | + public void testSetIpv4RouterIds() throws Exception { | ||
63 | + List list = new ArrayList(); | ||
64 | + list.add(Ip4Address.valueOf("1.1.1.1")); | ||
65 | + ospfDeviceTed.setIpv4RouterIds(list); | ||
66 | + assertThat(ospfDeviceTed.ipv4RouterIds().size(), is(1)); | ||
67 | + } | ||
68 | + | ||
69 | + /** | ||
70 | + * Tests abr() getter method. | ||
71 | + */ | ||
72 | + @Test | ||
73 | + public void testAbr() throws Exception { | ||
74 | + ospfDeviceTed.setAbr(true); | ||
75 | + assertThat(ospfDeviceTed.abr(), is(true)); | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * Tests abr() setter method. | ||
80 | + */ | ||
81 | + @Test | ||
82 | + public void testSetAbr() throws Exception { | ||
83 | + ospfDeviceTed.setAbr(true); | ||
84 | + assertThat(ospfDeviceTed.abr(), is(true)); | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * Tests asbr() getter method. | ||
89 | + */ | ||
90 | + @Test | ||
91 | + public void testAsbr() throws Exception { | ||
92 | + ospfDeviceTed.setAsbr(true); | ||
93 | + assertThat(ospfDeviceTed.asbr(), is(true)); | ||
94 | + } | ||
95 | + | ||
96 | + /** | ||
97 | + * Tests asbr() setter method. | ||
98 | + */ | ||
99 | + @Test | ||
100 | + public void testSetAsbr() throws Exception { | ||
101 | + ospfDeviceTed.setAsbr(true); | ||
102 | + assertThat(ospfDeviceTed.asbr(), is(true)); | ||
103 | + } | ||
104 | + | ||
105 | + /** | ||
106 | + * Tests topologyIds() getter method. | ||
107 | + */ | ||
108 | + @Test | ||
109 | + public void testTopologyIds() throws Exception { | ||
110 | + List list = new ArrayList(); | ||
111 | + list.add(Ip4Address.valueOf("1.1.1.1")); | ||
112 | + ospfDeviceTed.setTopologyIds(list); | ||
113 | + assertThat(ospfDeviceTed.topologyIds().size(), is(1)); | ||
114 | + } | ||
115 | + | ||
116 | + /** | ||
117 | + * Tests topologyIds() setter method. | ||
118 | + */ | ||
119 | + @Test | ||
120 | + public void testSetTopologyIds() throws Exception { | ||
121 | + List list = new ArrayList(); | ||
122 | + list.add(Ip4Address.valueOf("1.1.1.1")); | ||
123 | + ospfDeviceTed.setTopologyIds(list); | ||
124 | + assertThat(ospfDeviceTed.topologyIds().size(), is(1)); | ||
125 | + } | ||
126 | + | ||
127 | + /** | ||
128 | + * Tests ipv6RouterIds() getter method. | ||
129 | + */ | ||
130 | + @Test(expected = Exception.class) | ||
131 | + public void testIpv6RouterIds() throws Exception { | ||
132 | + List list = new ArrayList(); | ||
133 | + list.add(Ip6Address.valueOf(InetAddress.getLocalHost())); | ||
134 | + ospfDeviceTed.setIpv6RouterIds(list); | ||
135 | + assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1)); | ||
136 | + } | ||
137 | + | ||
138 | + /** | ||
139 | + * Tests ipv6RouterIds() setter method. | ||
140 | + */ | ||
141 | + @Test(expected = Exception.class) | ||
142 | + public void testSetIpv6RouterIds() throws Exception { | ||
143 | + List list = new ArrayList(); | ||
144 | + list.add(Ip6Address.valueOf(InetAddress.getLocalHost())); | ||
145 | + ospfDeviceTed.setIpv6RouterIds(list); | ||
146 | + assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1)); | ||
147 | + } | ||
148 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfLinkTedImplTest.java
0 → 100755
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.impl; | ||
17 | + | ||
18 | +import org.junit.After; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | +import org.onlab.packet.Ip4Address; | ||
22 | +import org.onlab.util.Bandwidth; | ||
23 | + | ||
24 | +import java.net.InetAddress; | ||
25 | +import java.util.ArrayList; | ||
26 | +import java.util.List; | ||
27 | + | ||
28 | +import static org.hamcrest.CoreMatchers.is; | ||
29 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
30 | +import static org.junit.Assert.assertThat; | ||
31 | + | ||
32 | +/** | ||
33 | + * Unit test class for OspfDeviceTedImpl. | ||
34 | + */ | ||
35 | +public class OspfLinkTedImplTest { | ||
36 | + private OspfLinkTedImpl ospfLinkTed; | ||
37 | + | ||
38 | + @Before | ||
39 | + public void setUp() throws Exception { | ||
40 | + ospfLinkTed = new OspfLinkTedImpl(); | ||
41 | + } | ||
42 | + | ||
43 | + @After | ||
44 | + public void tearDown() throws Exception { | ||
45 | + ospfLinkTed = null; | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * Tests maximumLink() getter method. | ||
50 | + */ | ||
51 | + @Test | ||
52 | + public void testMaximumLink() throws Exception { | ||
53 | + | ||
54 | + ospfLinkTed.setMaximumLink(Bandwidth.bps(1234)); | ||
55 | + assertThat(ospfLinkTed.maximumLink(), is(Bandwidth.bps(1234))); | ||
56 | + } | ||
57 | + | ||
58 | + /** | ||
59 | + * Tests maximumLink() setter method. | ||
60 | + */ | ||
61 | + @Test | ||
62 | + public void testSetMaximumLink() throws Exception { | ||
63 | + ospfLinkTed.setMaximumLink(Bandwidth.bps(1234)); | ||
64 | + assertThat(ospfLinkTed.maximumLink(), is(Bandwidth.bps(1234))); | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * Tests ipv6RemRouterId() getter method. | ||
69 | + */ | ||
70 | + @Test | ||
71 | + public void testIpv6RemRouterId() throws Exception { | ||
72 | + List list = new ArrayList(); | ||
73 | + ospfLinkTed.setIpv6RemRouterId(list); | ||
74 | + assertThat(ospfLinkTed.ipv6RemRouterId().size(), is(0)); | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * Tests ipv6RemRouterId() setter method. | ||
79 | + */ | ||
80 | + @Test | ||
81 | + public void testSetIpv6RemRouterId() throws Exception { | ||
82 | + List list = new ArrayList(); | ||
83 | + ospfLinkTed.setIpv6RemRouterId(list); | ||
84 | + assertThat(ospfLinkTed.ipv6RemRouterId().size(), is(0)); | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * Tests ipv4RemRouterId() getter method. | ||
89 | + */ | ||
90 | + @Test | ||
91 | + public void testIpv4RemRouterId() throws Exception { | ||
92 | + List list = new ArrayList(); | ||
93 | + list.add(Ip4Address.valueOf(InetAddress.getLocalHost())); | ||
94 | + ospfLinkTed.setIpv4RemRouterId(list); | ||
95 | + assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1)); | ||
96 | + } | ||
97 | + | ||
98 | + /** | ||
99 | + * Tests ipv4RemRouterId() setter method. | ||
100 | + */ | ||
101 | + @Test | ||
102 | + public void testSetIpv4RemRouterId() throws Exception { | ||
103 | + List list = new ArrayList(); | ||
104 | + list.add(Ip4Address.valueOf(InetAddress.getLocalHost())); | ||
105 | + ospfLinkTed.setIpv4RemRouterId(list); | ||
106 | + assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1)); | ||
107 | + } | ||
108 | + | ||
109 | + /** | ||
110 | + * Tests ipv6LocRouterId() getter method. | ||
111 | + */ | ||
112 | + @Test | ||
113 | + public void testIpv6LocRouterId() throws Exception { | ||
114 | + List list = new ArrayList(); | ||
115 | + ospfLinkTed.setIpv4LocRouterId(list); | ||
116 | + assertThat(ospfLinkTed.ipv6LocRouterId().size(), is(0)); | ||
117 | + } | ||
118 | + | ||
119 | + /** | ||
120 | + * Tests ipv6LocRouterId() setter method. | ||
121 | + */ | ||
122 | + @Test | ||
123 | + public void testSetIpv6LocRouterId() throws Exception { | ||
124 | + List list = new ArrayList(); | ||
125 | + ospfLinkTed.setIpv4LocRouterId(list); | ||
126 | + assertThat(ospfLinkTed.ipv6LocRouterId().size(), is(0)); | ||
127 | + } | ||
128 | + | ||
129 | + /** | ||
130 | + * Tests ipv4LocRouterId() getter method. | ||
131 | + */ | ||
132 | + @Test | ||
133 | + public void testIpv4LocRouterId() throws Exception { | ||
134 | + List list = new ArrayList(); | ||
135 | + list.add(Ip4Address.valueOf(InetAddress.getLocalHost())); | ||
136 | + ospfLinkTed.setIpv4LocRouterId(list); | ||
137 | + assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1)); | ||
138 | + } | ||
139 | + | ||
140 | + /** | ||
141 | + * Tests ipv4LocRouterId() setter method. | ||
142 | + */ | ||
143 | + @Test | ||
144 | + public void testSetIpv4LocRouterId() throws Exception { | ||
145 | + List list = new ArrayList(); | ||
146 | + list.add(Ip4Address.valueOf(InetAddress.getLocalHost())); | ||
147 | + ospfLinkTed.setIpv4LocRouterId(list); | ||
148 | + assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1)); | ||
149 | + } | ||
150 | + | ||
151 | + /** | ||
152 | + * Tests teMetric() getter method. | ||
153 | + */ | ||
154 | + @Test | ||
155 | + public void testTeMetric() throws Exception { | ||
156 | + ospfLinkTed.setTeMetric(1234); | ||
157 | + assertThat(ospfLinkTed.teMetric(), is(1234)); | ||
158 | + } | ||
159 | + | ||
160 | + /** | ||
161 | + * Tests teMetric() setter method. | ||
162 | + */ | ||
163 | + @Test | ||
164 | + public void testSetTeMetric() throws Exception { | ||
165 | + ospfLinkTed.setTeMetric(1234); | ||
166 | + assertThat(ospfLinkTed.teMetric(), is(1234)); | ||
167 | + } | ||
168 | + | ||
169 | + /** | ||
170 | + * Tests maxReserved() getter method. | ||
171 | + */ | ||
172 | + @Test | ||
173 | + public void testMaxReserved() throws Exception { | ||
174 | + ospfLinkTed.setMaxReserved(Bandwidth.bps(1234)); | ||
175 | + assertThat(ospfLinkTed.maxReserved(), is(Bandwidth.bps(1234))); | ||
176 | + } | ||
177 | + | ||
178 | + /** | ||
179 | + * Tests maxReserved() setter method. | ||
180 | + */ | ||
181 | + @Test | ||
182 | + public void testSetMaxReserved() throws Exception { | ||
183 | + ospfLinkTed.setMaxReserved(Bandwidth.bps(1234)); | ||
184 | + assertThat(ospfLinkTed.maxReserved(), is(Bandwidth.bps(1234))); | ||
185 | + } | ||
186 | + | ||
187 | + /** | ||
188 | + * Tests maxUnResBandwidth() getter method. | ||
189 | + */ | ||
190 | + @Test | ||
191 | + public void testMaxUnResBandwidth() throws Exception { | ||
192 | + ospfLinkTed.setMaxUnResBandwidth(Bandwidth.bps(1234)); | ||
193 | + assertThat(ospfLinkTed.maxUnResBandwidth(), is(notNullValue())); | ||
194 | + } | ||
195 | + | ||
196 | + /** | ||
197 | + * Tests maxUnResBandwidth() setter method. | ||
198 | + */ | ||
199 | + @Test | ||
200 | + public void testSetMaxUnResBandwidth() throws Exception { | ||
201 | + ospfLinkTed.setMaxUnResBandwidth(Bandwidth.bps(1234.0)); | ||
202 | + assertThat(ospfLinkTed.maxUnResBandwidth(), is(notNullValue())); | ||
203 | + } | ||
204 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfMessageDecoderTest.java
0 → 100755
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.impl; | ||
17 | + | ||
18 | +import org.easymock.EasyMock; | ||
19 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
20 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
21 | +import org.jboss.netty.channel.Channel; | ||
22 | +import org.jboss.netty.channel.ChannelHandlerContext; | ||
23 | +import org.junit.After; | ||
24 | +import org.junit.Before; | ||
25 | +import org.junit.Test; | ||
26 | + | ||
27 | +import java.net.InetSocketAddress; | ||
28 | +import java.net.SocketAddress; | ||
29 | + | ||
30 | +import static org.hamcrest.CoreMatchers.is; | ||
31 | +import static org.hamcrest.CoreMatchers.nullValue; | ||
32 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
33 | + | ||
34 | +/** | ||
35 | + * Unit test class for OspfMessageDecoder. | ||
36 | + */ | ||
37 | +public class OspfMessageDecoderTest { | ||
38 | + | ||
39 | + private final byte[] hellopacket = {0, 0, 0, 0, 2, 1, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, 39, 59, | ||
40 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 10, 2, 1, 0, 0, 0, | ||
41 | + 40, -64, -88, -86, 8, 0, 0, 0, 0}; | ||
42 | + private final byte[] ddpacket = {0, 0, 0, 0, 2, 2, 0, 32, -64, -88, -86, 8, 0, 0, 0, 1, -96, 82, | ||
43 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119, -87, 126}; | ||
44 | + private final byte[] ddpacket44 = {0, 0, 0, 0, 2, 2, 0, 10, -64, -88}; | ||
45 | + private final byte[] lsAckpacket = {0, 0, 0, 0, 2, 5, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, -30, -12, | ||
46 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 16, 2, 1, -64, -88, -86, 2, -64, | ||
47 | + -88, -86, 2, -128, 0, 0, 1, 74, -114, 0, 48}; | ||
48 | + private final byte[] lsUpdatePacket = {0, 0, 0, 0, 2, 4, 0, 76, -64, -88, -86, 3, 0, 0, 0, 1, 7, 111, | ||
49 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 14, 16, 2, 1, -64, -88, | ||
50 | + -86, 2, -64, -88, -86, 2, -128, 0, 0, 1, 74, -114, 0, 48, 2, 0, 0, 2 | ||
51 | + , -64, -88, -86, 0, -1, -1, -1, 0, 3, 0, 0, 10, -64, -88, -86, 0, -1, -1, -1, 0, 3, 0, 0, 10}; | ||
52 | + private final byte[] lsRequestPacket = {0, 0, 0, 0, 2, 3, 0, 36, -64, -88, -86, 3, 0, 0, 0, 1, -67, -57, | ||
53 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -64, -88, -86, 8, -64, -88, -86, 8}; | ||
54 | + private OspfMessageDecoder ospfMessageDecoder; | ||
55 | + private ChannelHandlerContext ctx; | ||
56 | + private Channel channel; | ||
57 | + private SocketAddress socketAddress; | ||
58 | + private ChannelBuffer channelBuffer; | ||
59 | + | ||
60 | + @Before | ||
61 | + public void setUp() throws Exception { | ||
62 | + ospfMessageDecoder = new OspfMessageDecoder(); | ||
63 | + } | ||
64 | + | ||
65 | + @After | ||
66 | + public void tearDown() throws Exception { | ||
67 | + ospfMessageDecoder = null; | ||
68 | + channel = null; | ||
69 | + socketAddress = null; | ||
70 | + channelBuffer = null; | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * Tests decode() method. | ||
75 | + */ | ||
76 | + @Test | ||
77 | + public void testDecode() throws Exception { | ||
78 | + | ||
79 | + channel = EasyMock.createMock(Channel.class); | ||
80 | + socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 7000); | ||
81 | + channelBuffer = ChannelBuffers.copiedBuffer(hellopacket); | ||
82 | + assertThat(ospfMessageDecoder.decode(ctx, channel, channelBuffer), is(nullValue())); | ||
83 | + | ||
84 | + | ||
85 | + } | ||
86 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfMessageEncoderTest.java
0 → 100755
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.impl; | ||
17 | + | ||
18 | + | ||
19 | +import org.easymock.EasyMock; | ||
20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
21 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
22 | +import org.jboss.netty.channel.Channel; | ||
23 | +import org.jboss.netty.channel.ChannelHandlerContext; | ||
24 | +import org.junit.After; | ||
25 | +import org.junit.Before; | ||
26 | +import org.junit.Test; | ||
27 | +import org.onlab.packet.Ip4Address; | ||
28 | +import org.onosproject.ospf.controller.area.OspfInterfaceImpl; | ||
29 | +import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket; | ||
30 | +import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket; | ||
31 | +import org.onosproject.ospf.protocol.ospfpacket.types.LsAcknowledge; | ||
32 | +import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest; | ||
33 | +import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate; | ||
34 | +import org.onosproject.ospf.protocol.util.OspfInterfaceState; | ||
35 | + | ||
36 | +import java.net.InetSocketAddress; | ||
37 | +import java.net.SocketAddress; | ||
38 | + | ||
39 | +import static org.hamcrest.CoreMatchers.is; | ||
40 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
41 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
42 | + | ||
43 | +/** | ||
44 | + * Created by sdn on 13/1/16. | ||
45 | + */ | ||
46 | +public class OspfMessageEncoderTest { | ||
47 | + private final byte[] hpacket = {2, 1, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, 39, 59, | ||
48 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 10, 2, 1, 0, 0, 0, | ||
49 | + 40, -64, -88, -86, 8, 0, 0, 0, 0}; | ||
50 | + private final byte[] dpacket = {2, 2, 0, 32, -64, -88, -86, 8, 0, 0, 0, 1, -96, 82, | ||
51 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119, -87, 126}; | ||
52 | + private final byte[] lrpacket = {2, 3, 0, 36, -64, -88, -86, 3, 0, 0, 0, 1, -67, -57, | ||
53 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -64, -88, -86, 8, -64, -88, -86, 8}; | ||
54 | + private byte[] lAckpacket = {2, 5, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, -30, -12, | ||
55 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 16, 2, 1, -64, -88, -86, 2, -64, | ||
56 | + -88, -86, 2, -128, 0, 0, 1, 74, -114, 0, 48}; | ||
57 | + private HelloPacket helloPacket; | ||
58 | + private DdPacket ddPacket; | ||
59 | + private LsAcknowledge lsAcknowledge; | ||
60 | + private LsRequest lsRequest; | ||
61 | + private LsUpdate lsUpdate; | ||
62 | + private ChannelHandlerContext ctx; | ||
63 | + private OspfMessageEncoder ospfMessageEncoder; | ||
64 | + private ChannelBuffer buf; | ||
65 | + private SocketAddress socketAddress; | ||
66 | + private Channel channel; | ||
67 | + | ||
68 | + @Before | ||
69 | + public void setUp() throws Exception { | ||
70 | + ospfMessageEncoder = new OspfMessageEncoder(); | ||
71 | + helloPacket = new HelloPacket(); | ||
72 | + ddPacket = new DdPacket(); | ||
73 | + lsAcknowledge = new LsAcknowledge(); | ||
74 | + lsRequest = new LsRequest(); | ||
75 | + lsUpdate = new LsUpdate(); | ||
76 | + helloPacket.setOspftype(1); | ||
77 | + ddPacket.setOspftype(2); | ||
78 | + lsAcknowledge.setOspftype(5); | ||
79 | + lsRequest.setOspftype(3); | ||
80 | + lsUpdate.setOspftype(4); | ||
81 | + OspfInterfaceImpl ospfInterface = new OspfInterfaceImpl(); | ||
82 | + ospfInterface.setState(OspfInterfaceState.DROTHER); | ||
83 | + ospfMessageEncoder = new OspfMessageEncoder(ospfInterface); | ||
84 | + | ||
85 | + } | ||
86 | + | ||
87 | + @After | ||
88 | + public void tearDown() throws Exception { | ||
89 | + helloPacket = null; | ||
90 | + ddPacket = null; | ||
91 | + lsAcknowledge = null; | ||
92 | + lsRequest = null; | ||
93 | + lsUpdate = null; | ||
94 | + ospfMessageEncoder = null; | ||
95 | + buf = null; | ||
96 | + } | ||
97 | + | ||
98 | + /** | ||
99 | + * Tests encode() method. | ||
100 | + */ | ||
101 | + @Test | ||
102 | + public void testEncode() throws Exception { | ||
103 | + socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 8600); | ||
104 | + channel = EasyMock.createMock(Channel.class); | ||
105 | + helloPacket = new HelloPacket(); | ||
106 | + helloPacket.setDestinationIp(Ip4Address.valueOf("15.15.15.15")); | ||
107 | + buf = ChannelBuffers.buffer(hpacket.length); | ||
108 | + buf.writeBytes(hpacket); | ||
109 | + helloPacket.readFrom(buf); | ||
110 | + ospfMessageEncoder.encode(ctx, channel, helloPacket); | ||
111 | + ddPacket = new DdPacket(); | ||
112 | + ddPacket.setDestinationIp(Ip4Address.valueOf("15.15.15.15")); | ||
113 | + buf = ChannelBuffers.buffer(dpacket.length); | ||
114 | + buf.writeBytes(dpacket); | ||
115 | + ddPacket.readFrom(buf); | ||
116 | + ospfMessageEncoder.encode(ctx, channel, ddPacket); | ||
117 | + lsRequest = new LsRequest(); | ||
118 | + lsRequest.setDestinationIp(Ip4Address.valueOf("15.15.15.15")); | ||
119 | + buf = ChannelBuffers.buffer(lrpacket.length); | ||
120 | + buf.writeBytes(lrpacket); | ||
121 | + lsRequest.readFrom(buf); | ||
122 | + ospfMessageEncoder.encode(ctx, channel, lsRequest); | ||
123 | + | ||
124 | + lsAcknowledge = new LsAcknowledge(); | ||
125 | + lsAcknowledge.setDestinationIp(Ip4Address.valueOf("15.15.15.15")); | ||
126 | + buf = ChannelBuffers.buffer(lAckpacket.length); | ||
127 | + buf.writeBytes(lAckpacket); | ||
128 | + lsAcknowledge.readFrom(buf); | ||
129 | + ospfMessageEncoder.encode(ctx, channel, lsAcknowledge); | ||
130 | + assertThat(ospfMessageEncoder, is(notNullValue())); | ||
131 | + } | ||
132 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfPipelineFactoryTest.java
0 → 100755
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.impl; | ||
17 | + | ||
18 | +import org.jboss.netty.channel.ChannelPipeline; | ||
19 | +import org.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.onosproject.ospf.controller.area.OspfAreaImpl; | ||
23 | +import org.onosproject.ospf.controller.area.OspfInterfaceImpl; | ||
24 | + | ||
25 | +import static org.hamcrest.CoreMatchers.*; | ||
26 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
27 | + | ||
28 | +/** | ||
29 | + * Unit test class for OspfPipelineFactory. | ||
30 | + */ | ||
31 | +public class OspfPipelineFactoryTest { | ||
32 | + | ||
33 | + private OspfPipelineFactory ospfPipelineFactory; | ||
34 | + private ChannelPipeline channelPipeline; | ||
35 | + | ||
36 | + @Before | ||
37 | + public void setUp() throws Exception { | ||
38 | + ospfPipelineFactory = new OspfPipelineFactory(new Controller(), new OspfAreaImpl(), new OspfInterfaceImpl()); | ||
39 | + | ||
40 | + } | ||
41 | + | ||
42 | + @After | ||
43 | + public void tearDown() throws Exception { | ||
44 | + ospfPipelineFactory = null; | ||
45 | + channelPipeline = null; | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * Tests getPipeline() method. | ||
50 | + */ | ||
51 | + @Test | ||
52 | + public void testGetPipeline() throws Exception { | ||
53 | + channelPipeline = ospfPipelineFactory.getPipeline(); | ||
54 | + assertThat(channelPipeline, is(notNullValue())); | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * Tests releaseExternalResources() method. | ||
59 | + */ | ||
60 | + @Test | ||
61 | + public void testReleaseExternalResources() throws Exception { | ||
62 | + ospfPipelineFactory.releaseExternalResources(); | ||
63 | + assertThat(channelPipeline, is(nullValue())); | ||
64 | + } | ||
65 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfRouterImplTest.java
0 → 100755
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.impl; | ||
17 | + | ||
18 | +import org.junit.After; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | +import org.onlab.packet.Ip4Address; | ||
22 | +import org.onlab.packet.IpAddress; | ||
23 | +import org.onosproject.ospf.controller.OspfDeviceTed; | ||
24 | + | ||
25 | +import java.util.List; | ||
26 | + | ||
27 | +import static org.hamcrest.CoreMatchers.is; | ||
28 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
29 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
30 | + | ||
31 | +/** | ||
32 | + * Unit test class for OspfRouterImpl. | ||
33 | + */ | ||
34 | +public class OspfRouterImplTest { | ||
35 | + private OspfRouterImpl ospfRouter; | ||
36 | + private OspfDeviceTed ospfDeviceTed; | ||
37 | + private List<OspfDeviceTed> list; | ||
38 | + | ||
39 | + @Before | ||
40 | + public void setUp() throws Exception { | ||
41 | + ospfRouter = new OspfRouterImpl(); | ||
42 | + } | ||
43 | + | ||
44 | + @After | ||
45 | + public void tearDown() throws Exception { | ||
46 | + ospfRouter = null; | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * Tests routerIp() getter method. | ||
51 | + */ | ||
52 | + @Test | ||
53 | + public void testRouterIp() throws Exception { | ||
54 | + ospfRouter.setRouterIp(Ip4Address.valueOf("1.1.1.1")); | ||
55 | + assertThat(ospfRouter.routerIp(), is(IpAddress.valueOf("1.1.1.1"))); | ||
56 | + } | ||
57 | + | ||
58 | + /** | ||
59 | + * Tests routerIp() setter method. | ||
60 | + */ | ||
61 | + @Test | ||
62 | + public void testSetRouterIp() throws Exception { | ||
63 | + ospfRouter.setRouterIp(Ip4Address.valueOf("1.1.1.1")); | ||
64 | + assertThat(ospfRouter.routerIp(), is(IpAddress.valueOf("1.1.1.1"))); | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * Tests areaIdOfInterface() getter method. | ||
69 | + */ | ||
70 | + @Test | ||
71 | + public void testAreaIdOfInterface() throws Exception { | ||
72 | + ospfRouter.setAreaIdOfInterface(Ip4Address.valueOf("1.1.1.1")); | ||
73 | + assertThat(ospfRouter.areaIdOfInterface(), is(IpAddress.valueOf("1.1.1.1"))); | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * Tests areaIdOfInterface() setter method. | ||
78 | + */ | ||
79 | + @Test | ||
80 | + public void testSetAreaIdOfInterface() throws Exception { | ||
81 | + ospfRouter.setAreaIdOfInterface(Ip4Address.valueOf("1.1.1.1")); | ||
82 | + assertThat(ospfRouter.areaIdOfInterface(), is(IpAddress.valueOf("1.1.1.1"))); | ||
83 | + } | ||
84 | + | ||
85 | + /** | ||
86 | + * Tests interfaceId() getter method. | ||
87 | + */ | ||
88 | + @Test | ||
89 | + public void testInterfaceId() throws Exception { | ||
90 | + ospfRouter.setInterfaceId(Ip4Address.valueOf("1.1.1.1")); | ||
91 | + assertThat(ospfRouter.interfaceId(), is(IpAddress.valueOf("1.1.1.1"))); | ||
92 | + } | ||
93 | + | ||
94 | + /** | ||
95 | + * Tests interfaceId() setter method. | ||
96 | + */ | ||
97 | + @Test | ||
98 | + public void testSetInterfaceId() throws Exception { | ||
99 | + ospfRouter.setInterfaceId(Ip4Address.valueOf("1.1.1.1")); | ||
100 | + assertThat(ospfRouter.interfaceId(), is(IpAddress.valueOf("1.1.1.1"))); | ||
101 | + } | ||
102 | + | ||
103 | + /** | ||
104 | + * Tests isDr() setter method. | ||
105 | + */ | ||
106 | + @Test | ||
107 | + public void testSetDr() throws Exception { | ||
108 | + ospfRouter.setDr(true); | ||
109 | + assertThat(ospfRouter.isDr(), is(true)); | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * Tests isDr() getter method. | ||
114 | + */ | ||
115 | + @Test | ||
116 | + public void testIsDr() throws Exception { | ||
117 | + ospfRouter.setDr(true); | ||
118 | + assertThat(ospfRouter.isDr(), is(true)); | ||
119 | + } | ||
120 | + | ||
121 | + /** | ||
122 | + * Tests isOpaque() setter method. | ||
123 | + */ | ||
124 | + @Test | ||
125 | + public void testSetOpaque() throws Exception { | ||
126 | + ospfRouter.setOpaque(true); | ||
127 | + assertThat(ospfRouter.isOpaque(), is(true)); | ||
128 | + } | ||
129 | + | ||
130 | + /** | ||
131 | + * Tests isOpaque() getter method. | ||
132 | + */ | ||
133 | + @Test | ||
134 | + public void testisOpaque() throws Exception { | ||
135 | + ospfRouter.setOpaque(true); | ||
136 | + assertThat(ospfRouter.isOpaque(), is(true)); | ||
137 | + } | ||
138 | + | ||
139 | + /** | ||
140 | + * Tests deviceTed() getter method. | ||
141 | + */ | ||
142 | + @Test | ||
143 | + public void testDeviceTed() throws Exception { | ||
144 | + ospfRouter.setDeviceTed(new OspfDeviceTedImpl()); | ||
145 | + assertThat(ospfRouter.deviceTed(), is(notNullValue())); | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * Tests deviceTed() Setter method. | ||
150 | + */ | ||
151 | + @Test | ||
152 | + public void testSetDeviceTed() throws Exception { | ||
153 | + ospfRouter.setDeviceTed(new OspfDeviceTedImpl()); | ||
154 | + assertThat(ospfRouter.deviceTed(), is(notNullValue())); | ||
155 | + } | ||
156 | + | ||
157 | + /** | ||
158 | + * Tests neighborRouterId() getter method. | ||
159 | + */ | ||
160 | + @Test | ||
161 | + public void testNeighborRouterId() throws Exception { | ||
162 | + ospfRouter.setNeighborRouterId(Ip4Address.valueOf("1.1.1.1")); | ||
163 | + assertThat(ospfRouter.neighborRouterId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
164 | + } | ||
165 | + | ||
166 | + /** | ||
167 | + * Tests neighborRouterId() Setter method. | ||
168 | + */ | ||
169 | + @Test | ||
170 | + public void testSetNeighborRouterId() throws Exception { | ||
171 | + ospfRouter.setNeighborRouterId(Ip4Address.valueOf("1.1.1.1")); | ||
172 | + assertThat(ospfRouter.neighborRouterId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
173 | + } | ||
174 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment