chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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.isis.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.MacAddress; |
| 23 | import org.onosproject.isis.controller.IsisInterface; |
| 24 | import org.onosproject.isis.controller.IsisInterfaceState; |
| 25 | import org.onosproject.isis.controller.IsisMessage; |
| 26 | import org.onosproject.isis.controller.IsisRouterType; |
| 27 | import org.onosproject.isis.io.isispacket.IsisHeader; |
| 28 | import org.onosproject.isis.io.isispacket.pdu.HelloPdu; |
| 29 | import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu; |
| 30 | |
| 31 | import static org.hamcrest.CoreMatchers.is; |
| 32 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 33 | import static org.junit.Assert.assertThat; |
| 34 | |
| 35 | /** |
| 36 | * Unit test class for DefaultIsisNeighbor. |
| 37 | */ |
| 38 | public class DefaultIsisNeighborTest { |
| 39 | |
| 40 | private final String areaId = "490001"; |
| 41 | private final String systemId = "2929.2929.2929"; |
| 42 | private final String lanId = "0000.0000.0000.00"; |
| 43 | private DefaultIsisNeighbor isisNeighbor; |
| 44 | private IsisInterface isisInterface; |
| 45 | private IsisMessage isisMessage; |
| 46 | private IsisHeader isisHeader; |
| 47 | private int result; |
| 48 | private String result1; |
| 49 | private Ip4Address interfaceIp = Ip4Address.valueOf("10.10.10.10"); |
| 50 | private Ip4Address result2; |
| 51 | private MacAddress macAddress = MacAddress.valueOf("a4:23:05:00:00:00"); |
| 52 | private MacAddress result3; |
| 53 | private IsisRouterType isisRouterType; |
| 54 | private IsisInterfaceState isisInterfaceState; |
| 55 | private byte result4; |
| 56 | |
| 57 | @Before |
| 58 | public void setUp() throws Exception { |
| 59 | isisHeader = new IsisHeader(); |
| 60 | isisMessage = new L1L2HelloPdu(isisHeader); |
| 61 | isisInterface = new DefaultIsisInterface(); |
| 62 | isisNeighbor = new DefaultIsisNeighbor((HelloPdu) isisMessage, isisInterface); |
| 63 | } |
| 64 | |
| 65 | @After |
| 66 | public void tearDown() throws Exception { |
| 67 | isisHeader = null; |
| 68 | isisMessage = null; |
| 69 | isisInterface = null; |
| 70 | isisNeighbor = null; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Tests localExtendedCircuitId() getter method. |
| 75 | */ |
| 76 | @Test |
| 77 | public void testLocalExtendedCircuitId() throws Exception { |
| 78 | isisNeighbor.setLocalExtendedCircuitId(1); |
| 79 | result = isisNeighbor.localExtendedCircuitId(); |
| 80 | assertThat(result, is(1)); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Tests localExtendedCircuitId() setter method. |
| 85 | */ |
| 86 | @Test |
| 87 | public void testSetLocalExtendedCircuitId() throws Exception { |
| 88 | isisNeighbor.setLocalExtendedCircuitId(1); |
| 89 | result = isisNeighbor.localExtendedCircuitId(); |
| 90 | assertThat(result, is(1)); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Tests neighborAreaId() getter method. |
| 95 | */ |
| 96 | @Test |
| 97 | public void testNeighborAreaId() throws Exception { |
| 98 | isisNeighbor.setNeighborAreaId(areaId); |
| 99 | result1 = isisNeighbor.neighborAreaId(); |
| 100 | assertThat(result1, is(areaId)); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Tests neighborAreaId() setter method. |
| 105 | */ |
| 106 | @Test |
| 107 | public void testSetNeighborAreaId() throws Exception { |
| 108 | isisNeighbor.setNeighborAreaId(areaId); |
| 109 | result1 = isisNeighbor.neighborAreaId(); |
| 110 | assertThat(result1, is(areaId)); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Tests neighborSystemId() getter method. |
| 115 | */ |
| 116 | @Test |
| 117 | public void testNeighborSystemId() throws Exception { |
| 118 | isisNeighbor.setNeighborSystemId(systemId); |
| 119 | result1 = isisNeighbor.neighborSystemId(); |
| 120 | assertThat(result1, is(systemId)); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Tests neighborSystemId() setter method. |
| 125 | */ |
| 126 | @Test |
| 127 | public void testSetNeighborSystemId() throws Exception { |
| 128 | isisNeighbor.setNeighborSystemId(systemId); |
| 129 | result1 = isisNeighbor.neighborSystemId(); |
| 130 | assertThat(result1, is(systemId)); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Tests interfaceIp() getter method. |
| 135 | */ |
| 136 | @Test |
| 137 | public void testInterfaceIp() throws Exception { |
| 138 | isisNeighbor.setInterfaceIp(interfaceIp); |
| 139 | result2 = isisNeighbor.interfaceIp(); |
| 140 | assertThat(result2, is(interfaceIp)); |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Tests interfaceIp() setter method. |
| 145 | */ |
| 146 | @Test |
| 147 | public void testSetInterfaceIp() throws Exception { |
| 148 | isisNeighbor.setInterfaceIp(interfaceIp); |
| 149 | result2 = isisNeighbor.interfaceIp(); |
| 150 | assertThat(result2, is(interfaceIp)); |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Tests neighborMacAddress() getter method. |
| 155 | */ |
| 156 | @Test |
| 157 | public void testNeighborMacAddress() throws Exception { |
| 158 | isisNeighbor.setNeighborMacAddress(macAddress); |
| 159 | result3 = isisNeighbor.neighborMacAddress(); |
| 160 | assertThat(result3, is(macAddress)); |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Tests neighborMacAddress() setter method. |
| 165 | */ |
| 166 | @Test |
| 167 | public void testSetNeighborMacAddress() throws Exception { |
| 168 | isisNeighbor.setNeighborMacAddress(macAddress); |
| 169 | result3 = isisNeighbor.neighborMacAddress(); |
| 170 | assertThat(result3, is(macAddress)); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Tests holdingTime() getter method. |
| 175 | */ |
| 176 | @Test |
| 177 | public void testHoldingTime() throws Exception { |
| 178 | isisNeighbor.setHoldingTime(1); |
| 179 | result = isisNeighbor.holdingTime(); |
| 180 | assertThat(result, is(1)); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Tests holdingTime() setter method. |
| 185 | */ |
| 186 | @Test |
| 187 | public void testSetHoldingTime() throws Exception { |
| 188 | isisNeighbor.setHoldingTime(1); |
| 189 | result = isisNeighbor.holdingTime(); |
| 190 | assertThat(result, is(1)); |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Tests routerType() getter method. |
| 195 | */ |
| 196 | @Test |
| 197 | public void testRouterType() throws Exception { |
| 198 | isisNeighbor.setRouterType(IsisRouterType.L1); |
| 199 | isisRouterType = isisNeighbor.routerType(); |
| 200 | assertThat(isisRouterType, is(IsisRouterType.L1)); |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Tests routerType() setter method. |
| 205 | */ |
| 206 | @Test |
| 207 | public void testSetRouterType() throws Exception { |
| 208 | isisNeighbor.setRouterType(IsisRouterType.L1); |
| 209 | isisRouterType = isisNeighbor.routerType(); |
| 210 | assertThat(isisRouterType, is(IsisRouterType.L1)); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Tests l1LanId() getter method. |
| 215 | */ |
| 216 | @Test |
| 217 | public void testL1LanId() throws Exception { |
| 218 | isisNeighbor.setL1LanId(systemId); |
| 219 | result1 = isisNeighbor.l1LanId(); |
| 220 | assertThat(result1, is(systemId)); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Tests l1LanId() setter method. |
| 225 | */ |
| 226 | @Test |
| 227 | public void testSetL1LanId() throws Exception { |
| 228 | isisNeighbor.setL1LanId(lanId); |
| 229 | result1 = isisNeighbor.l1LanId(); |
| 230 | assertThat(result1, is(lanId)); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Tests l2LanId() getter method. |
| 235 | */ |
| 236 | @Test |
| 237 | public void testL2LanId() throws Exception { |
| 238 | isisNeighbor.setL2LanId(lanId); |
| 239 | result1 = isisNeighbor.l2LanId(); |
| 240 | assertThat(result1, is(lanId)); |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Tests l2LanId() setter method. |
| 245 | */ |
| 246 | @Test |
| 247 | public void testSetL2LanId() throws Exception { |
| 248 | isisNeighbor.setL2LanId(lanId); |
| 249 | result1 = isisNeighbor.l2LanId(); |
| 250 | assertThat(result1, is(lanId)); |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Tests neighborState() getter method. |
| 255 | */ |
| 256 | @Test |
| 257 | public void testInterfaceState() throws Exception { |
| 258 | isisNeighbor.setNeighborState(IsisInterfaceState.DOWN); |
| 259 | isisInterfaceState = isisNeighbor.neighborState(); |
| 260 | assertThat(isisInterfaceState, is(IsisInterfaceState.DOWN)); |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Tests neighborState() setter method. |
| 265 | */ |
| 266 | @Test |
| 267 | public void testSetNeighborState() throws Exception { |
| 268 | isisNeighbor.setNeighborState(IsisInterfaceState.DOWN); |
| 269 | isisInterfaceState = isisNeighbor.neighborState(); |
| 270 | assertThat(isisInterfaceState, is(IsisInterfaceState.DOWN)); |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Tests localCircuitId() getter method. |
| 275 | */ |
| 276 | @Test |
| 277 | public void testLocalCircuitId() throws Exception { |
| 278 | isisNeighbor.setLocalCircuitId((byte) 1); |
| 279 | result4 = isisNeighbor.localCircuitId(); |
| 280 | assertThat(result4, is((byte) 1)); |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Tests localCircuitId() setter method. |
| 285 | */ |
| 286 | @Test |
| 287 | public void testSetLocalCircuitId() throws Exception { |
| 288 | isisNeighbor.setLocalCircuitId((byte) 1); |
| 289 | result4 = isisNeighbor.localCircuitId(); |
| 290 | assertThat(result4, is((byte) 1)); |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Tests neighborState() getter method. |
| 295 | */ |
| 296 | @Test |
| 297 | public void testNeighborState() throws Exception { |
| 298 | isisNeighbor.setNeighborState(IsisInterfaceState.DOWN); |
| 299 | isisInterfaceState = isisNeighbor.neighborState(); |
| 300 | assertThat(isisInterfaceState, is(IsisInterfaceState.DOWN)); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Tests startHoldingTimeCheck() method. |
| 305 | */ |
| 306 | @Test |
| 307 | public void testStartHoldingTimeCheck() throws Exception { |
| 308 | isisNeighbor.startHoldingTimeCheck(); |
| 309 | assertThat(isisNeighbor, is(notNullValue())); |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * Tests stopHoldingTimeCheck() method. |
| 314 | */ |
| 315 | @Test |
| 316 | public void testStopHoldingTimeCheck() throws Exception { |
| 317 | isisNeighbor.stopHoldingTimeCheck(); |
| 318 | assertThat(isisNeighbor, is(notNullValue())); |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Tests startInactivityTimeCheck() method. |
| 323 | */ |
| 324 | @Test(expected = Exception.class) |
| 325 | public void testStartInactivityTimeCheck() throws Exception { |
| 326 | isisNeighbor.startInactivityTimeCheck(); |
| 327 | assertThat(isisNeighbor, is(notNullValue())); |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * Tests startInactivityTimeCheck() method. |
| 332 | */ |
| 333 | @Test(expected = Exception.class) |
| 334 | public void testStopInactivityTimeCheck() throws Exception { |
| 335 | isisNeighbor.startInactivityTimeCheck(); |
| 336 | assertThat(isisNeighbor, is(notNullValue())); |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Tests neighborDown() method. |
| 341 | */ |
| 342 | @Test(expected = Exception.class) |
| 343 | public void testNeighborDown() throws Exception { |
| 344 | isisNeighbor.neighborDown(); |
| 345 | assertThat(isisNeighbor, is(notNullValue())); |
| 346 | } |
| 347 | } |