Kalyankumar Asangi | 19f6449 | 2016-02-17 17:34:16 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.ospf.controller.lsdb; |
| 17 | |
| 18 | import org.easymock.EasyMock; |
| 19 | import org.junit.After; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
| 22 | import org.onosproject.ospf.controller.OspfLsaType; |
| 23 | import org.onosproject.ospf.controller.area.OspfAreaImpl; |
| 24 | import org.onosproject.ospf.controller.area.OspfInterfaceImpl; |
| 25 | import org.onosproject.ospf.protocol.lsa.LsaHeader; |
| 26 | import org.onosproject.ospf.protocol.lsa.types.RouterLsa; |
| 27 | |
| 28 | import static org.hamcrest.CoreMatchers.*; |
| 29 | import static org.hamcrest.MatcherAssert.assertThat; |
| 30 | |
| 31 | /** |
| 32 | * Unit test class for LsaWrapperImpl. |
| 33 | */ |
| 34 | public class LsaWrapperImplTest { |
| 35 | |
| 36 | private LsaWrapperImpl lsaWrapper; |
| 37 | private LsdbAgeImpl lsdbAge; |
| 38 | private LsaHeader header; |
| 39 | private OspfInterfaceImpl ospfInterfaceImpl; |
| 40 | |
| 41 | @Before |
| 42 | public void setUp() throws Exception { |
| 43 | lsaWrapper = new LsaWrapperImpl(); |
| 44 | } |
| 45 | |
| 46 | @After |
| 47 | public void tearDown() throws Exception { |
| 48 | lsaWrapper = null; |
| 49 | header = null; |
| 50 | lsdbAge = null; |
| 51 | ospfInterfaceImpl = null; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Tests lsaType() getter method. |
| 56 | */ |
| 57 | @Test |
| 58 | public void testGetLsaType() throws Exception { |
| 59 | lsaWrapper.setLsaType(OspfLsaType.ROUTER); |
| 60 | assertThat(lsaWrapper.lsaType(), is(OspfLsaType.ROUTER)); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Tests lsaType() setter method. |
| 65 | */ |
| 66 | @Test |
| 67 | public void testSetLsaType() throws Exception { |
| 68 | lsaWrapper.setLsaType(OspfLsaType.ROUTER); |
| 69 | assertThat(lsaWrapper.lsaType(), is(OspfLsaType.ROUTER)); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Tests isSelfOriginated() getter method. |
| 74 | */ |
| 75 | @Test |
| 76 | public void testIsSelfOriginated() throws Exception { |
| 77 | lsaWrapper.setIsSelfOriginated(true); |
| 78 | assertThat(lsaWrapper.isSelfOriginated(), is(true)); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Tests isSelfOriginated() setter method. |
| 83 | */ |
| 84 | @Test |
| 85 | public void testSetIsSelfOriginated() throws Exception { |
| 86 | lsaWrapper.setIsSelfOriginated(true); |
| 87 | assertThat(lsaWrapper.isSelfOriginated(), is(true)); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Tests addLsa() method. |
| 92 | */ |
| 93 | @Test |
sunish vk | aa48da8 | 2016-03-02 23:17:06 +0530 | [diff] [blame] | 94 | public void testAddLsa() throws Exception { |
Kalyankumar Asangi | 19f6449 | 2016-02-17 17:34:16 +0530 | [diff] [blame] | 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 |
sunish vk | aa48da8 | 2016-03-02 23:17:06 +0530 | [diff] [blame] | 219 | public void testIsSentReplyForOlderLsa() throws Exception { |
Kalyankumar Asangi | 19f6449 | 2016-02-17 17:34:16 +0530 | [diff] [blame] | 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 | /** |
Kalyankumar Asangi | 19f6449 | 2016-02-17 17:34:16 +0530 | [diff] [blame] | 234 | * Tests isSentReplyForOlderLsa() getter method. |
| 235 | */ |
| 236 | @Test |
| 237 | public void testSetSentReplyForOlderLsa() throws Exception { |
| 238 | lsaWrapper.setSentReplyForOlderLsa(true); |
| 239 | assertThat(lsaWrapper.isSentReplyForOlderLsa(), is(true)); |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Tests isSentReplyForOlderLsa() setter method. |
| 244 | */ |
| 245 | @Test |
| 246 | public void testSetCheckAge() throws Exception { |
| 247 | lsaWrapper.setCheckAge(true); |
| 248 | assertThat(lsaWrapper.isCheckAge(), is(true)); |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Tests isAging() getter method. |
| 253 | */ |
| 254 | @Test |
| 255 | public void testIsAging() throws Exception { |
| 256 | lsaWrapper.setIsAging(true); |
| 257 | assertThat(lsaWrapper.isAging(), is(true)); |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Tests isAging() setter method. |
| 262 | */ |
| 263 | @Test |
| 264 | public void testSetIsAging() throws Exception { |
| 265 | lsaWrapper.setIsAging(true); |
| 266 | assertThat(lsaWrapper.isAging(), is(true)); |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Tests currentAge() method. |
| 271 | */ |
| 272 | @Test |
| 273 | public void testGetCurrentAge() throws Exception { |
| 274 | lsdbAge = new LsdbAgeImpl(new OspfAreaImpl()); |
| 275 | lsdbAge.ageLsaAndFlood(); |
| 276 | lsaWrapper.setLsdbAge(lsdbAge); |
| 277 | assertThat(lsaWrapper.currentAge(), is(notNullValue())); |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Tests ageCounterWhenReceived() getter method. |
| 282 | */ |
| 283 | @Test |
| 284 | public void testGetAgeCounterWhenReceived() throws Exception { |
| 285 | lsaWrapper.setAgeCounterWhenReceived(10); |
| 286 | assertThat(lsaWrapper.ageCounterWhenReceived(), is(10)); |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * Tests ageCounterWhenReceived() setter method. |
| 291 | */ |
| 292 | @Test |
| 293 | public void testSetAgeCounterWhenReceived() throws Exception { |
| 294 | lsaWrapper.setAgeCounterWhenReceived(10); |
| 295 | assertThat(lsaWrapper.ageCounterWhenReceived(), is(10)); |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Tests lsaProcessing() getter method. |
| 300 | */ |
| 301 | @Test |
| 302 | public void testGetLsaProcessing() throws Exception { |
| 303 | lsaWrapper.setLsaProcessing("router"); |
| 304 | assertThat(lsaWrapper.lsaProcessing(), is("router")); |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Tests lsaProcessing() setter method. |
| 309 | */ |
| 310 | @Test |
| 311 | public void testSetLsaProcessing() throws Exception { |
| 312 | lsaWrapper.setLsaProcessing("router"); |
| 313 | assertThat(lsaWrapper.lsaProcessing(), is("router")); |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * Tests binNumber() getter method. |
| 318 | */ |
| 319 | @Test |
| 320 | public void testGetBinNumber() throws Exception { |
| 321 | lsaWrapper.setBinNumber(10); |
| 322 | assertThat(lsaWrapper.binNumber(), is(10)); |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Tests binNumber() setter method. |
| 327 | */ |
| 328 | @Test |
| 329 | public void testSetBinNumber() throws Exception { |
| 330 | lsaWrapper.setBinNumber(10); |
| 331 | assertThat(lsaWrapper.binNumber(), is(10)); |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Tests ospfInterface() getter method. |
| 336 | */ |
| 337 | @Test |
| 338 | public void testGetOspfInterface() throws Exception { |
| 339 | ospfInterfaceImpl = EasyMock.createMock(OspfInterfaceImpl.class); |
| 340 | lsaWrapper.setOspfInterface(ospfInterfaceImpl); |
| 341 | assertThat(lsaWrapper.ospfInterface(), is(notNullValue())); |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Tests ospfInterface() setter method. |
| 346 | */ |
| 347 | @Test |
| 348 | public void testSetOspfInterface() throws Exception { |
| 349 | ospfInterfaceImpl = EasyMock.createMock(OspfInterfaceImpl.class); |
| 350 | lsaWrapper.setOspfInterface(ospfInterfaceImpl); |
| 351 | assertThat(lsaWrapper.ospfInterface(), is(notNullValue())); |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Tests getLsdbAge() method. |
| 356 | */ |
| 357 | @Test |
| 358 | public void testGetLsdbAge() throws Exception { |
| 359 | assertThat(lsaWrapper.getLsdbAge(), is(nullValue())); |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * Tests to string method. |
| 364 | */ |
| 365 | @Test |
| 366 | public void testToString() throws Exception { |
| 367 | assertThat(lsaWrapper.toString(), is(notNullValue())); |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * Tests equals() method. |
| 372 | */ |
| 373 | @Test |
| 374 | public void testEquals() throws Exception { |
| 375 | assertThat(lsaWrapper.equals(new LsaWrapperImpl()), is(true)); |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Tests hashCode() method. |
| 380 | */ |
| 381 | @Test |
| 382 | public void testHashCode() throws Exception { |
| 383 | int hashCode = lsaWrapper.hashCode(); |
| 384 | assertThat(hashCode, is(notNullValue())); |
| 385 | } |
| 386 | } |