Chidambar babu | 86b3b1a | 2016-02-16 17:39:52 +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.protocol.lsa; |
| 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.onosproject.ospf.controller.OspfLsaType; |
| 23 | |
| 24 | import static org.hamcrest.MatcherAssert.assertThat; |
| 25 | import static org.hamcrest.Matchers.*; |
| 26 | |
| 27 | /** |
| 28 | * Unit test class for LsaHeader. |
| 29 | */ |
| 30 | public class LsaHeaderTest { |
| 31 | |
| 32 | private LsaHeader lsaHeader; |
| 33 | private int result; |
| 34 | private Ip4Address result1; |
| 35 | private long result2; |
| 36 | private OspfLsaType ospflsaType; |
| 37 | private LsaHeader header; |
| 38 | private byte[] result3; |
| 39 | private LsaHeader lsaHeader1; |
| 40 | private String result4; |
| 41 | |
| 42 | @Before |
| 43 | public void setUp() throws Exception { |
| 44 | lsaHeader = new LsaHeader(); |
| 45 | } |
| 46 | |
| 47 | @After |
| 48 | public void tearDown() throws Exception { |
| 49 | lsaHeader = null; |
| 50 | result1 = null; |
| 51 | ospflsaType = null; |
| 52 | header = null; |
| 53 | result3 = null; |
| 54 | lsaHeader1 = null; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Tests equals() method. |
| 59 | */ |
| 60 | @Test |
| 61 | public void testEquals() throws Exception { |
| 62 | assertThat(lsaHeader.equals(new LsaHeader()), is(true)); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Tests hashCode() method. |
| 67 | */ |
| 68 | @Test |
| 69 | public void testHashCode() throws Exception { |
| 70 | result = lsaHeader.hashCode(); |
| 71 | assertThat(result, is(notNullValue())); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Tests age() getter method. |
| 76 | */ |
| 77 | @Test |
| 78 | public void testGetAge() throws Exception { |
| 79 | lsaHeader.setAge(10); |
| 80 | result = lsaHeader.age(); |
| 81 | assertThat(result, is(10)); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Tests age() setter method. |
| 86 | */ |
| 87 | @Test |
| 88 | public void testSetAge() throws Exception { |
| 89 | lsaHeader.setAge(10); |
| 90 | result = lsaHeader.age(); |
| 91 | assertThat(result, is(10)); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Tests options() getter method. |
| 96 | */ |
| 97 | @Test |
| 98 | public void testGetOptions() throws Exception { |
| 99 | lsaHeader.setOptions(2); |
| 100 | result = lsaHeader.options(); |
| 101 | assertThat(result, is(2)); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Tests options() setter method. |
| 106 | */ |
| 107 | @Test |
| 108 | public void testSetOptions() throws Exception { |
| 109 | lsaHeader.setOptions(2); |
| 110 | result = lsaHeader.options(); |
| 111 | assertThat(result, is(2)); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Tests lsType() getter method. |
| 116 | */ |
| 117 | @Test |
| 118 | public void testGetLsType() throws Exception { |
| 119 | lsaHeader.setLsType(1); |
| 120 | result = lsaHeader.lsType(); |
| 121 | assertThat(result, is(1)); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Tests lsType() setter method. |
| 126 | */ |
| 127 | @Test |
| 128 | public void testSetLsType() throws Exception { |
| 129 | lsaHeader.setLsType(1); |
| 130 | result = lsaHeader.lsType(); |
| 131 | assertThat(result, is(1)); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Tests linkStateId() getter method. |
| 136 | */ |
| 137 | @Test |
| 138 | public void testGetLinkStateId() throws Exception { |
| 139 | lsaHeader.setLinkStateId("10.226.165.164"); |
| 140 | result4 = lsaHeader.linkStateId(); |
| 141 | assertThat(result4, is("10.226.165.164")); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Tests linkStateId() setter method. |
| 146 | */ |
| 147 | @Test |
| 148 | public void testSetLinkStateId() throws Exception { |
| 149 | lsaHeader.setLinkStateId("10.226.165.164"); |
| 150 | result4 = lsaHeader.linkStateId(); |
| 151 | assertThat(result4, is("10.226.165.164")); |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Tests advertisingRouter() setter method. |
| 156 | */ |
| 157 | @Test |
| 158 | public void testGetAdvertisingRouter() throws Exception { |
| 159 | lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("10.226.165.164")); |
| 160 | result1 = lsaHeader.advertisingRouter(); |
| 161 | assertThat(result1, is(Ip4Address.valueOf("10.226.165.164"))); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Tests advertisingRouter() setter method. |
| 166 | */ |
| 167 | @Test |
| 168 | public void testSetAdvertisingRouter() throws Exception { |
| 169 | lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("10.226.165.164")); |
| 170 | result1 = lsaHeader.advertisingRouter(); |
| 171 | assertThat(result1, is(Ip4Address.valueOf("10.226.165.164"))); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Tests lsSequenceNo() getter method. |
| 176 | */ |
| 177 | @Test |
| 178 | public void testGetLsSequenceNo() throws Exception { |
| 179 | lsaHeader.setLsSequenceNo(222); |
| 180 | result2 = lsaHeader.lsSequenceNo(); |
| 181 | assertThat(result2, is(222L)); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Tests lsSequenceNo() setter method. |
| 186 | */ |
| 187 | @Test |
| 188 | public void testSetLsSequenceNo() throws Exception { |
| 189 | lsaHeader.setLsSequenceNo(222); |
| 190 | result2 = lsaHeader.lsSequenceNo(); |
| 191 | assertThat(result2, is(222L)); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Tests lsCheckSum() getter method. |
| 196 | */ |
| 197 | @Test |
| 198 | public void testGetLsChecksum() throws Exception { |
| 199 | lsaHeader.setLsCheckSum(2); |
| 200 | result = lsaHeader.lsCheckSum(); |
| 201 | assertThat(result, is(2)); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Tests lsCheckSum() setter method. |
| 206 | */ |
| 207 | @Test |
| 208 | public void testSetLsChecksum() throws Exception { |
| 209 | lsaHeader.setLsCheckSum(2); |
| 210 | result = lsaHeader.lsCheckSum(); |
| 211 | assertThat(result, is(2)); |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Tests lsPacketLen() getter method. |
| 216 | */ |
| 217 | @Test |
| 218 | public void testGetLsPacketLen() throws Exception { |
| 219 | lsaHeader.setLsPacketLen(48); |
| 220 | result = lsaHeader.lsPacketLen(); |
| 221 | assertThat(result, is(48)); |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Tests lsPacketLen() getter method. |
| 226 | */ |
| 227 | @Test |
| 228 | public void testSetLsPacketLen() throws Exception { |
| 229 | lsaHeader.setLsPacketLen(48); |
| 230 | result = lsaHeader.lsPacketLen(); |
| 231 | assertThat(result, is(48)); |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Tests getOspfLsaType() getter method. |
| 236 | */ |
| 237 | @Test |
| 238 | public void testGetOspfLsaType() throws Exception { |
| 239 | lsaHeader.setLsType(1); |
| 240 | ospflsaType = lsaHeader.getOspfLsaType(); |
| 241 | assertThat(ospflsaType, is(notNullValue())); |
| 242 | assertThat(ospflsaType, is(OspfLsaType.ROUTER)); |
| 243 | lsaHeader.setLsType(2); |
| 244 | ospflsaType = lsaHeader.getOspfLsaType(); |
| 245 | assertThat(ospflsaType, is(notNullValue())); |
| 246 | assertThat(ospflsaType, is(OspfLsaType.NETWORK)); |
| 247 | lsaHeader.setLsType(3); |
| 248 | ospflsaType = lsaHeader.getOspfLsaType(); |
| 249 | assertThat(ospflsaType, is(notNullValue())); |
| 250 | assertThat(ospflsaType, is(OspfLsaType.SUMMARY)); |
| 251 | lsaHeader.setLsType(4); |
| 252 | ospflsaType = lsaHeader.getOspfLsaType(); |
| 253 | assertThat(ospflsaType, is(notNullValue())); |
| 254 | assertThat(ospflsaType, is(OspfLsaType.ASBR_SUMMARY)); |
| 255 | lsaHeader.setLsType(5); |
| 256 | ospflsaType = lsaHeader.getOspfLsaType(); |
| 257 | assertThat(ospflsaType, is(notNullValue())); |
| 258 | assertThat(ospflsaType, is(OspfLsaType.EXTERNAL_LSA)); |
| 259 | lsaHeader.setLsType(6); |
| 260 | ospflsaType = lsaHeader.getOspfLsaType(); |
| 261 | assertThat(ospflsaType, is(notNullValue())); |
| 262 | assertThat(ospflsaType, is(OspfLsaType.UNDEFINED)); |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Tests lsaHeader() getter method. |
| 267 | */ |
| 268 | @Test |
| 269 | public void testGetLsaHeader() throws Exception { |
| 270 | header = (LsaHeader) lsaHeader.lsaHeader(); |
| 271 | assertThat(header, instanceOf(LsaHeader.class)); |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Tests getLsaHeaderAsByteArray() method. |
| 276 | */ |
| 277 | @Test |
| 278 | public void testGetLsaHeaderAsByteArray() throws Exception { |
| 279 | result3 = lsaHeader.getLsaHeaderAsByteArray(); |
| 280 | assertThat(result3, is(notNullValue())); |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Tests to string method. |
| 285 | */ |
| 286 | @Test |
| 287 | public void testToString() throws Exception { |
| 288 | assertThat(lsaHeader.toString(), is(notNullValue())); |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Tests populateHeader() method. |
| 293 | */ |
| 294 | @Test |
| 295 | public void testPopulateHeader() throws Exception { |
| 296 | lsaHeader1 = new LsaHeader(); |
| 297 | lsaHeader1.setLsPacketLen(10); |
| 298 | lsaHeader1.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1")); |
| 299 | lsaHeader1.setOptions(2); |
| 300 | lsaHeader1.setAge(20); |
| 301 | lsaHeader1.setLsType(3); |
| 302 | lsaHeader1.setLinkStateId("2.2.2.2"); |
| 303 | lsaHeader1.setLsCheckSum(1234); |
| 304 | lsaHeader1.setLsSequenceNo(456789); |
| 305 | lsaHeader.populateHeader(lsaHeader1); |
| 306 | assertThat(lsaHeader1, is(notNullValue())); |
| 307 | } |
| 308 | } |