blob: b8d95c7bdca92fff79c5e2d3cd55510378a8092d [file] [log] [blame]
Kalyankumar Asangi19f64492016-02-17 17:34:16 +05301/*
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 */
16package org.onosproject.ospf.controller.lsdb;
17
18import org.easymock.EasyMock;
19import org.junit.After;
20import org.junit.Before;
21import org.junit.Test;
22import org.onosproject.ospf.controller.OspfLsaType;
23import org.onosproject.ospf.controller.area.OspfAreaImpl;
24import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
25import org.onosproject.ospf.protocol.lsa.LsaHeader;
26import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
27
28import static org.hamcrest.CoreMatchers.*;
29import static org.hamcrest.MatcherAssert.assertThat;
30
31/**
32 * Unit test class for LsaWrapperImpl.
33 */
34public class LsaWrapperImplTest {
35
36 private LsaWrapperImpl lsaWrapper;
37 private LsdbAgeImpl lsdbAge;
38 private LsaHeader header;
39 private OspfInterfaceImpl ospfInterfaceImpl;
40
41 @Before
42 public void setUp() throws Exception {
43 lsaWrapper = new LsaWrapperImpl();
44 }
45
46 @After
47 public void tearDown() throws Exception {
48 lsaWrapper = null;
49 header = null;
50 lsdbAge = null;
51 ospfInterfaceImpl = null;
52 }
53
54 /**
55 * Tests lsaType() getter method.
56 */
57 @Test
58 public void testGetLsaType() throws Exception {
59 lsaWrapper.setLsaType(OspfLsaType.ROUTER);
60 assertThat(lsaWrapper.lsaType(), is(OspfLsaType.ROUTER));
61 }
62
63 /**
64 * Tests lsaType() setter method.
65 */
66 @Test
67 public void testSetLsaType() throws Exception {
68 lsaWrapper.setLsaType(OspfLsaType.ROUTER);
69 assertThat(lsaWrapper.lsaType(), is(OspfLsaType.ROUTER));
70 }
71
72 /**
73 * Tests isSelfOriginated() getter method.
74 */
75 @Test
76 public void testIsSelfOriginated() throws Exception {
77 lsaWrapper.setIsSelfOriginated(true);
78 assertThat(lsaWrapper.isSelfOriginated(), is(true));
79 }
80
81 /**
82 * Tests isSelfOriginated() setter method.
83 */
84 @Test
85 public void testSetIsSelfOriginated() throws Exception {
86 lsaWrapper.setIsSelfOriginated(true);
87 assertThat(lsaWrapper.isSelfOriginated(), is(true));
88 }
89
90 /**
91 * Tests addLsa() method.
92 */
93 @Test
94 public void testAddLSA() throws Exception {
95 lsaWrapper.addLsa(OspfLsaType.ROUTER, new RouterLsa());
96 assertThat(lsaWrapper, is(notNullValue()));
97 }
98
99 /**
100 * Tests lsaAgeReceived() getter method.
101 */
102 @Test
103 public void testGetLsaAgeReceived() throws Exception {
104 lsaWrapper.setLsaAgeReceived(10);
105 assertThat(lsaWrapper.lsaAgeReceived(), is(10));
106 }
107
108 /**
109 * Tests lsaAgeReceived() setter method.
110 */
111 @Test
112 public void testSetLsaAgeReceived() throws Exception {
113 lsaWrapper.setLsaAgeReceived(10);
114 assertThat(lsaWrapper.lsaAgeReceived(), is(10));
115 }
116
117 /**
118 * Tests lsaHeader() getter method.
119 */
120 @Test
121 public void testGetLsaHeader() throws Exception {
122 lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
123 lsdbAge.ageLsaAndFlood();
124 lsaWrapper.setLsdbAge(lsdbAge);
125 header = new LsaHeader();
126 lsaWrapper.setLsaHeader(header);
127 assertThat(lsaWrapper.lsaHeader(), instanceOf(LsaHeader.class));
128 }
129
130 /**
131 * Tests lsaHeader() setter method.
132 */
133 @Test
134 public void testSetLsaHeader() throws Exception {
135 lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
136 lsdbAge.ageLsaAndFlood();
137 lsaWrapper.setLsdbAge(lsdbAge);
138 header = new LsaHeader();
139 lsaWrapper.setLsaHeader(header);
140 assertThat(lsaWrapper.lsaHeader(), instanceOf(LsaHeader.class));
141 }
142
143 /**
144 * Tests setOspfLsa() setter method.
145 */
146 @Test
147 public void testSetOspfLsa() throws Exception {
148 lsaWrapper.setOspfLsa(new RouterLsa());
149 assertThat(lsaWrapper, is(notNullValue()));
150 }
151
152 /**
153 * Tests noReTransmissionLists() getter method.
154 */
155 @Test
156 public void testGetNoReTransmissionLists() throws Exception {
157 lsaWrapper.setNoReTransmissionLists(10);
158 assertThat(lsaWrapper.noReTransmissionLists(), is(10));
159 }
160
161 /**
162 * Tests noReTransmissionLists() setter method.
163 */
164 @Test
165 public void testSetNoReTransmissionLists() throws Exception {
166 lsaWrapper.setNoReTransmissionLists(10);
167 assertThat(lsaWrapper.noReTransmissionLists(), is(10));
168 }
169
170 /**
171 * Tests isInAnAgeBin() getter method.
172 */
173 @Test
174 public void testIsInAnAgeBin() throws Exception {
175 lsaWrapper.setInAnAgeBin(true);
176 assertThat(lsaWrapper.isInAnAgeBin(), is(true));
177 }
178
179 /**
180 * Tests isInAnAgeBin() setter method.
181 */
182 @Test
183 public void testSetInAnAgeBin() throws Exception {
184 lsaWrapper.setInAnAgeBin(true);
185 assertThat(lsaWrapper.isInAnAgeBin(), is(true));
186 }
187
188 /**
189 * Tests isChangedSinceLastFlood() getter method.
190 */
191 @Test
192 public void testIsChangedSinceLastFlood() throws Exception {
193 lsaWrapper.setChangedSinceLastFlood(true);
194 assertThat(lsaWrapper.isChangedSinceLastFlood(), is(true));
195 }
196
197 /**
198 * Tests isChangedSinceLastFlood() setter method.
199 */
200 @Test
201 public void testSetChangedSinceLastFlood() throws Exception {
202 lsaWrapper.setChangedSinceLastFlood(true);
203 assertThat(lsaWrapper.isChangedSinceLastFlood(), is(true));
204 }
205
206 /**
207 * Tests isSequenceRollOver() method.
208 */
209 @Test
210 public void testIsSequenceRollOver() throws Exception {
211 lsaWrapper.setIsSequenceRollOver(true);
212 assertThat(lsaWrapper.isSequenceRollOver(), is(true));
213 }
214
215 /**
216 * Tests isSentReplyForOlderLsa() method.
217 */
218 @Test
219 public void testIsSentReplyForOlderLSA() throws Exception {
220 lsaWrapper.setSentReplyForOlderLsa(true);
221 assertThat(lsaWrapper.isSentReplyForOlderLsa(), is(true));
222 }
223
224 /**
225 * Tests isCheckAge() getter method.
226 */
227 @Test
228 public void testIsCheckAge() throws Exception {
229 lsaWrapper.setCheckAge(true);
230 assertThat(lsaWrapper.isCheckAge(), is(true));
231 }
232
233 /**
234 * Tests isCheckAge() setter method.
235 */
236 @Test
237 public void testIsSentReplyForOlderLsa() throws Exception {
238 lsaWrapper.setIsSequenceRollOver(true);
239 assertThat(lsaWrapper.isSequenceRollOver(), is(true));
240 }
241
242 /**
243 * Tests isSentReplyForOlderLsa() getter method.
244 */
245 @Test
246 public void testSetSentReplyForOlderLsa() throws Exception {
247 lsaWrapper.setSentReplyForOlderLsa(true);
248 assertThat(lsaWrapper.isSentReplyForOlderLsa(), is(true));
249 }
250
251 /**
252 * Tests isSentReplyForOlderLsa() setter method.
253 */
254 @Test
255 public void testSetCheckAge() throws Exception {
256 lsaWrapper.setCheckAge(true);
257 assertThat(lsaWrapper.isCheckAge(), is(true));
258 }
259
260 /**
261 * Tests isAging() getter method.
262 */
263 @Test
264 public void testIsAging() throws Exception {
265 lsaWrapper.setIsAging(true);
266 assertThat(lsaWrapper.isAging(), is(true));
267 }
268
269 /**
270 * Tests isAging() setter method.
271 */
272 @Test
273 public void testSetIsAging() throws Exception {
274 lsaWrapper.setIsAging(true);
275 assertThat(lsaWrapper.isAging(), is(true));
276 }
277
278 /**
279 * Tests currentAge() method.
280 */
281 @Test
282 public void testGetCurrentAge() throws Exception {
283 lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
284 lsdbAge.ageLsaAndFlood();
285 lsaWrapper.setLsdbAge(lsdbAge);
286 assertThat(lsaWrapper.currentAge(), is(notNullValue()));
287 }
288
289 /**
290 * Tests ageCounterWhenReceived() getter method.
291 */
292 @Test
293 public void testGetAgeCounterWhenReceived() throws Exception {
294 lsaWrapper.setAgeCounterWhenReceived(10);
295 assertThat(lsaWrapper.ageCounterWhenReceived(), is(10));
296 }
297
298 /**
299 * Tests ageCounterWhenReceived() setter method.
300 */
301 @Test
302 public void testSetAgeCounterWhenReceived() throws Exception {
303 lsaWrapper.setAgeCounterWhenReceived(10);
304 assertThat(lsaWrapper.ageCounterWhenReceived(), is(10));
305 }
306
307 /**
308 * Tests lsaProcessing() getter method.
309 */
310 @Test
311 public void testGetLsaProcessing() throws Exception {
312 lsaWrapper.setLsaProcessing("router");
313 assertThat(lsaWrapper.lsaProcessing(), is("router"));
314 }
315
316 /**
317 * Tests lsaProcessing() setter method.
318 */
319 @Test
320 public void testSetLsaProcessing() throws Exception {
321 lsaWrapper.setLsaProcessing("router");
322 assertThat(lsaWrapper.lsaProcessing(), is("router"));
323 }
324
325 /**
326 * Tests binNumber() getter method.
327 */
328 @Test
329 public void testGetBinNumber() throws Exception {
330 lsaWrapper.setBinNumber(10);
331 assertThat(lsaWrapper.binNumber(), is(10));
332 }
333
334 /**
335 * Tests binNumber() setter method.
336 */
337 @Test
338 public void testSetBinNumber() throws Exception {
339 lsaWrapper.setBinNumber(10);
340 assertThat(lsaWrapper.binNumber(), is(10));
341 }
342
343 /**
344 * Tests ospfInterface() getter method.
345 */
346 @Test
347 public void testGetOspfInterface() throws Exception {
348 ospfInterfaceImpl = EasyMock.createMock(OspfInterfaceImpl.class);
349 lsaWrapper.setOspfInterface(ospfInterfaceImpl);
350 assertThat(lsaWrapper.ospfInterface(), is(notNullValue()));
351 }
352
353 /**
354 * Tests ospfInterface() setter method.
355 */
356 @Test
357 public void testSetOspfInterface() throws Exception {
358 ospfInterfaceImpl = EasyMock.createMock(OspfInterfaceImpl.class);
359 lsaWrapper.setOspfInterface(ospfInterfaceImpl);
360 assertThat(lsaWrapper.ospfInterface(), is(notNullValue()));
361 }
362
363 /**
364 * Tests getLsdbAge() method.
365 */
366 @Test
367 public void testGetLsdbAge() throws Exception {
368 assertThat(lsaWrapper.getLsdbAge(), is(nullValue()));
369 }
370
371 /**
372 * Tests to string method.
373 */
374 @Test
375 public void testToString() throws Exception {
376 assertThat(lsaWrapper.toString(), is(notNullValue()));
377 }
378
379 /**
380 * Tests equals() method.
381 */
382 @Test
383 public void testEquals() throws Exception {
384 assertThat(lsaWrapper.equals(new LsaWrapperImpl()), is(true));
385 }
386
387 /**
388 * Tests hashCode() method.
389 */
390 @Test
391 public void testHashCode() throws Exception {
392 int hashCode = lsaWrapper.hashCode();
393 assertThat(hashCode, is(notNullValue()));
394 }
395}