nicklesh adlakha | 90bfa6a | 2016-04-28 20:38:33 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
nicklesh adlakha | 90bfa6a | 2016-04-28 20:38:33 +0530 | [diff] [blame] | 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.io.isispacket.pdu; |
| 17 | |
| 18 | import org.easymock.EasyMock; |
| 19 | import org.jboss.netty.buffer.ChannelBuffer; |
| 20 | import org.jboss.netty.buffer.ChannelBuffers; |
| 21 | import org.junit.After; |
| 22 | import org.junit.Before; |
| 23 | import org.junit.Test; |
| 24 | import org.onlab.packet.Ip4Address; |
| 25 | import org.onlab.packet.MacAddress; |
| 26 | import org.onosproject.isis.controller.IsisInterfaceState; |
| 27 | import org.onosproject.isis.io.isispacket.IsisHeader; |
| 28 | import org.onosproject.isis.io.isispacket.tlv.AdjacencyStateTlv; |
| 29 | import org.onosproject.isis.io.isispacket.tlv.IsisTlv; |
| 30 | import org.onosproject.isis.io.isispacket.tlv.TlvHeader; |
| 31 | |
| 32 | import java.util.List; |
| 33 | |
| 34 | import static org.hamcrest.CoreMatchers.*; |
| 35 | import static org.hamcrest.MatcherAssert.assertThat; |
| 36 | |
| 37 | /** |
| 38 | * Unit test class for HelloPdu. |
| 39 | */ |
| 40 | public class HelloPduTest { |
| 41 | |
| 42 | private final byte[] macAddr = new byte[]{ |
| 43 | (byte) 0xa4, (byte) 0x22, (byte) 0xc2, 0x00, 0x00, 0x00 |
| 44 | }; |
| 45 | private final String srcId = "1111.1111.1111"; |
| 46 | private final byte[] helloL1L2 = { |
| 47 | 1, 34, 34, 34, 34, 34, 34, 0, |
| 48 | 30, 5, -39, 64, 34, 34, 34, 34, 34, 34, 1, -127, 1, -52, 1, |
| 49 | 4, 3, 73, 0, 10, -124, 4, 10, 0, 10, 2, -45, 3, 0, 0, 0, |
| 50 | 8, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 51 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 52 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 53 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 54 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 55 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 56 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 57 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 58 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 59 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 60 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 102 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 103 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 104 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 105 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 106 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, -93, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 107 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 108 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 109 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 110 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 111 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 112 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 113 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 114 | }; |
| 115 | |
| 116 | private HelloPdu helloPdu; |
| 117 | private IsisHeader isisHeader; |
| 118 | private IsisTlv isisTlv; |
| 119 | private TlvHeader tlvHeader; |
| 120 | private MacAddress macAddress; |
| 121 | private List<IsisTlv> resultList; |
| 122 | private List<String> resultListStr; |
| 123 | private List<Ip4Address> resultListIPv4; |
| 124 | private List<MacAddress> resultListMac; |
| 125 | private IsisInterfaceState resultAdjState; |
| 126 | private String resultStr; |
| 127 | private int resultInt; |
| 128 | private byte resultByte; |
| 129 | private ChannelBuffer channelBuffer; |
| 130 | private HelloPdu pdu; |
| 131 | |
| 132 | @Before |
| 133 | public void setUp() throws Exception { |
| 134 | isisHeader = new IsisHeader(); |
| 135 | helloPdu = new L1L2HelloPdu(isisHeader); |
| 136 | tlvHeader = new TlvHeader(); |
| 137 | isisTlv = new AdjacencyStateTlv(tlvHeader); |
| 138 | macAddress = new MacAddress(macAddr); |
| 139 | channelBuffer = EasyMock.createMock(ChannelBuffer.class); |
| 140 | pdu = helloPdu; |
| 141 | } |
| 142 | |
| 143 | @After |
| 144 | public void tearDown() throws Exception { |
| 145 | isisHeader = null; |
| 146 | helloPdu = null; |
| 147 | isisTlv = null; |
| 148 | tlvHeader = null; |
| 149 | macAddress = null; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Tests addTlv() getter method. |
| 154 | */ |
| 155 | @Test |
| 156 | public void testAddTlv() throws Exception { |
| 157 | helloPdu.addTlv(isisTlv); |
| 158 | resultList = helloPdu.tlvs(); |
| 159 | assertThat(resultList.size(), is(1)); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Tests tlvs() method. |
| 164 | */ |
| 165 | @Test |
| 166 | public void testTlvs() throws Exception { |
| 167 | helloPdu.addTlv(isisTlv); |
| 168 | resultList = helloPdu.tlvs(); |
| 169 | assertThat(resultList.size(), is(1)); |
| 170 | } |
| 171 | |
| 172 | /** |
Ray Milkey | c108a6b | 2017-08-23 15:23:50 -0700 | [diff] [blame] | 173 | * Tests areaAddress() method. |
nicklesh adlakha | 90bfa6a | 2016-04-28 20:38:33 +0530 | [diff] [blame] | 174 | */ |
| 175 | @Test |
| 176 | public void testAreaAddress() throws Exception { |
| 177 | channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); |
| 178 | helloPdu.readFrom(channelBuffer); |
| 179 | resultListStr = helloPdu.areaAddress(); |
| 180 | assertThat(resultListStr.size(), is(1)); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Tests interfaceIpAddresse() method. |
| 185 | */ |
| 186 | @Test |
| 187 | public void testInterfaceIpAddresses() throws Exception { |
| 188 | channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); |
| 189 | helloPdu.readFrom(channelBuffer); |
| 190 | resultListIPv4 = helloPdu.interfaceIpAddresses(); |
| 191 | assertThat(resultListIPv4.size(), is(1)); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Tests neighborList() method. |
| 196 | */ |
| 197 | @Test |
| 198 | public void testNeighborList() throws Exception { |
| 199 | channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); |
| 200 | helloPdu.readFrom(channelBuffer); |
| 201 | resultListMac = helloPdu.neighborList(); |
| 202 | assertThat(resultListMac, is(nullValue())); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Tests adjacencyState() method. |
| 207 | */ |
| 208 | @Test |
| 209 | public void testAdjacencyState() throws Exception { |
| 210 | channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); |
| 211 | helloPdu.readFrom(channelBuffer); |
| 212 | resultAdjState = helloPdu.adjacencyState(); |
| 213 | assertThat(resultAdjState, is(nullValue())); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Tests sourceId() getter method. |
| 218 | */ |
| 219 | @Test |
| 220 | public void testSourceId() throws Exception { |
| 221 | helloPdu.setSourceId(srcId); |
| 222 | resultStr = helloPdu.sourceId(); |
| 223 | assertThat(resultStr, is(srcId)); |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Tests sourceId() setter method. |
| 228 | */ |
| 229 | @Test |
| 230 | public void testSetSourceId() throws Exception { |
| 231 | helloPdu.setSourceId(srcId); |
| 232 | resultStr = helloPdu.sourceId(); |
| 233 | assertThat(resultStr, is(srcId)); |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Tests pduLength() getter method. |
| 238 | */ |
| 239 | @Test |
| 240 | public void testPduLength() throws Exception { |
| 241 | helloPdu.setPduLength(10); |
| 242 | resultInt = helloPdu.pduLength(); |
| 243 | assertThat(resultInt, is(10)); |
| 244 | |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Tests pduLength() setter method. |
| 249 | */ |
| 250 | @Test |
| 251 | public void testSetPduLength() throws Exception { |
| 252 | helloPdu.setPduLength(10); |
| 253 | resultInt = helloPdu.pduLength(); |
| 254 | assertThat(resultInt, is(10)); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Tests holdingTime() getter method. |
| 259 | */ |
| 260 | @Test |
| 261 | public void testHoldingTime() throws Exception { |
| 262 | helloPdu.setHoldingTime(10); |
| 263 | resultInt = helloPdu.holdingTime(); |
| 264 | assertThat(resultInt, is(10)); |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Tests holdingTime() setter method. |
| 269 | */ |
| 270 | @Test |
| 271 | public void testSetHoldingTime() throws Exception { |
| 272 | helloPdu.setHoldingTime(10); |
| 273 | resultInt = helloPdu.holdingTime(); |
| 274 | assertThat(resultInt, is(10)); |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Tests circuitType() getter method. |
| 279 | */ |
| 280 | @Test |
| 281 | public void testCircuitType() throws Exception { |
| 282 | helloPdu.setCircuitType((byte) 1); |
| 283 | resultByte = helloPdu.circuitType(); |
| 284 | assertThat(resultByte, is((byte) 1)); |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Tests circuitType() setter method. |
| 289 | */ |
| 290 | @Test |
| 291 | public void testSetCircuitType() throws Exception { |
| 292 | helloPdu.setCircuitType((byte) 1); |
| 293 | resultByte = helloPdu.circuitType(); |
| 294 | assertThat(resultByte, is((byte) 1)); |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Tests toString() getter method. |
| 299 | */ |
| 300 | @Test |
| 301 | public void testToString() throws Exception { |
| 302 | pdu = helloPdu; |
| 303 | assertThat(pdu.toString(), is(notNullValue())); |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Tests equals() method. |
| 308 | */ |
| 309 | @Test |
| 310 | public void testEquals() throws Exception { |
| 311 | pdu = helloPdu; |
| 312 | assertThat(pdu.equals(new L1L2HelloPdu(new IsisHeader())), is(true)); |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Tests hashCode() method. |
| 317 | */ |
| 318 | @Test |
| 319 | public void testHashCode() throws Exception { |
| 320 | pdu = helloPdu; |
| 321 | resultInt = pdu.hashCode(); |
| 322 | assertThat(resultInt, is(notNullValue())); |
| 323 | } |
Ray Milkey | c108a6b | 2017-08-23 15:23:50 -0700 | [diff] [blame] | 324 | } |