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; |
| 17 | |
| 18 | import org.easymock.EasyMock; |
| 19 | import org.jboss.netty.buffer.ChannelBuffer; |
| 20 | import org.junit.After; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | import org.onlab.packet.MacAddress; |
| 24 | import org.onosproject.isis.controller.IsisPduType; |
| 25 | |
| 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | import static org.hamcrest.Matchers.is; |
| 28 | import static org.hamcrest.Matchers.notNullValue; |
| 29 | |
| 30 | /** |
| 31 | * Unit test class for IsisHeader. |
| 32 | */ |
| 33 | public class IsisHeaderTest { |
| 34 | |
| 35 | private IsisHeader isisHeader; |
| 36 | private MacAddress macAddress = MacAddress.valueOf("a4:23:05:00:00:00"); |
| 37 | private int result; |
| 38 | private MacAddress result1; |
| 39 | private byte result2; |
| 40 | private IsisPduType result3; |
| 41 | private ChannelBuffer channelBuffer; |
| 42 | |
| 43 | @Before |
| 44 | public void setUp() throws Exception { |
| 45 | isisHeader = new IsisHeader(); |
| 46 | channelBuffer = EasyMock.createMock(ChannelBuffer.class); |
| 47 | } |
| 48 | |
| 49 | @After |
| 50 | public void tearDown() throws Exception { |
| 51 | isisHeader = null; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Tests interfaceIndex() getter method. |
| 56 | */ |
| 57 | @Test |
| 58 | public void testInterfaceIndex() throws Exception { |
| 59 | isisHeader.setInterfaceIndex(1); |
| 60 | result = isisHeader.interfaceIndex(); |
| 61 | assertThat(result, is(1)); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Tests interfaceIndex() setter method. |
| 66 | */ |
| 67 | @Test |
| 68 | public void testSetInterfaceIndex() throws Exception { |
| 69 | isisHeader.setInterfaceIndex(1); |
| 70 | result = isisHeader.interfaceIndex(); |
| 71 | assertThat(result, is(1)); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Tests interfaceMac() getter method. |
| 76 | */ |
| 77 | @Test |
| 78 | public void testInterfaceMac() throws Exception { |
| 79 | isisHeader.setInterfaceMac(macAddress); |
| 80 | result1 = isisHeader.interfaceMac(); |
| 81 | assertThat(result1, is(macAddress)); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Tests sourceMac() getter method. |
| 86 | */ |
| 87 | @Test |
| 88 | public void testSourceMac() throws Exception { |
| 89 | isisHeader.setSourceMac(macAddress); |
| 90 | result1 = isisHeader.sourceMac(); |
| 91 | assertThat(result1, is(macAddress)); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Tests sourceMac() setter method. |
| 96 | */ |
| 97 | @Test |
| 98 | public void testSetSourceMac() throws Exception { |
| 99 | isisHeader.setSourceMac(macAddress); |
| 100 | result1 = isisHeader.sourceMac(); |
| 101 | assertThat(result1, is(macAddress)); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Tests interfaceMac() setter method. |
| 106 | */ |
| 107 | @Test |
| 108 | public void testSetInterfaceMac() throws Exception { |
| 109 | isisHeader.setSourceMac(macAddress); |
| 110 | result1 = isisHeader.sourceMac(); |
| 111 | assertThat(result1, is(macAddress)); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Tests version2() getter method. |
| 116 | */ |
| 117 | @Test |
| 118 | public void testVersion2() throws Exception { |
| 119 | isisHeader.setVersion2((byte) 1); |
| 120 | result2 = isisHeader.version2(); |
| 121 | assertThat(result2, is((byte) 1)); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Tests version2() setter method. |
| 126 | */ |
| 127 | @Test |
| 128 | public void testSetVersion2() throws Exception { |
| 129 | isisHeader.setVersion2((byte) 1); |
| 130 | result2 = isisHeader.version2(); |
| 131 | assertThat(result2, is((byte) 1)); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Tests maximumAreaAddresses() getter method. |
| 136 | */ |
| 137 | @Test |
| 138 | public void testMaximumAreaAddresses() throws Exception { |
| 139 | isisHeader.setMaximumAreaAddresses((byte) 1); |
| 140 | result2 = isisHeader.maximumAreaAddresses(); |
| 141 | assertThat(result2, is((byte) 1)); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Tests maximumAreaAddresses() setter method. |
| 146 | */ |
| 147 | @Test |
| 148 | public void testSetMaximumAreaAddresses() throws Exception { |
| 149 | isisHeader.setMaximumAreaAddresses((byte) 1); |
| 150 | result2 = isisHeader.maximumAreaAddresses(); |
| 151 | assertThat(result2, is((byte) 1)); |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Tests reserved() getter method. |
| 156 | */ |
| 157 | @Test |
| 158 | public void testReserved() throws Exception { |
| 159 | isisHeader.setReserved((byte) 1); |
| 160 | result2 = isisHeader.reserved(); |
| 161 | assertThat(result2, is((byte) 1)); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Tests reserved() setter method. |
| 166 | */ |
| 167 | @Test |
| 168 | public void testSetReserved() throws Exception { |
| 169 | isisHeader.setReserved((byte) 1); |
| 170 | result2 = isisHeader.reserved(); |
| 171 | assertThat(result2, is((byte) 1)); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Tests version() getter method. |
| 176 | */ |
| 177 | @Test |
| 178 | public void testVersion() throws Exception { |
| 179 | isisHeader.setVersion((byte) 1); |
| 180 | result2 = isisHeader.version(); |
| 181 | assertThat(result2, is((byte) 1)); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Tests version() setter method. |
| 186 | */ |
| 187 | @Test |
| 188 | public void testSetVersion() throws Exception { |
| 189 | isisHeader.setVersion((byte) 1); |
| 190 | result2 = isisHeader.version(); |
| 191 | assertThat(result2, is((byte) 1)); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Tests idLength() getter method. |
| 196 | */ |
| 197 | @Test |
| 198 | public void testIdLength() throws Exception { |
| 199 | isisHeader.setIdLength((byte) 1); |
| 200 | result2 = isisHeader.idLength(); |
| 201 | assertThat(result2, is((byte) 1)); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Tests idLength() setter method. |
| 206 | */ |
| 207 | @Test |
| 208 | public void testSetIdLength() throws Exception { |
| 209 | isisHeader.setIdLength((byte) 1); |
| 210 | result2 = isisHeader.idLength(); |
| 211 | assertThat(result2, is((byte) 1)); |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Tests pduType() getter method. |
| 216 | */ |
| 217 | @Test |
| 218 | public void testPduType() throws Exception { |
| 219 | isisHeader.setIsisPduType(1); |
| 220 | result = isisHeader.pduType(); |
| 221 | assertThat(result, is(1)); |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Tests pduType() setter method. |
| 226 | */ |
| 227 | @Test |
| 228 | public void testSetIsisPduType() throws Exception { |
| 229 | isisHeader.setIsisPduType(1); |
| 230 | result = isisHeader.pduType(); |
| 231 | assertThat(result, is(1)); |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Tests pduHeaderLength() getter method. |
| 236 | */ |
| 237 | @Test |
| 238 | public void testPduHeaderLength() throws Exception { |
| 239 | isisHeader.setPduHeaderLength((byte) 1); |
| 240 | result2 = isisHeader.pduHeaderLength(); |
| 241 | assertThat(result2, is((byte) 1)); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Tests pduHeaderLength() setter method. |
| 246 | */ |
| 247 | @Test |
| 248 | public void testSetPduHeaderLength() throws Exception { |
| 249 | isisHeader.setPduHeaderLength((byte) 1); |
| 250 | result2 = isisHeader.pduHeaderLength(); |
| 251 | assertThat(result2, is((byte) 1)); |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Tests irpDiscriminator() getter method. |
| 256 | */ |
| 257 | @Test |
| 258 | public void testIrpDiscriminator() throws Exception { |
| 259 | isisHeader.setIrpDiscriminator((byte) 1); |
| 260 | result2 = isisHeader.irpDiscriminator(); |
| 261 | assertThat(result2, is((byte) 1)); |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Tests irpDiscriminator() setter method. |
| 266 | */ |
| 267 | @Test |
| 268 | public void testSetIrpDiscriminator() throws Exception { |
| 269 | isisHeader.setIrpDiscriminator((byte) 1); |
| 270 | result2 = isisHeader.irpDiscriminator(); |
| 271 | assertThat(result2, is((byte) 1)); |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Tests irpDiscriminator() setter method. |
| 276 | */ |
| 277 | @Test |
| 278 | public void testIsisPduType() throws Exception { |
| 279 | isisHeader.setIsisPduType(IsisPduType.L1HELLOPDU.value()); |
| 280 | result3 = isisHeader.isisPduType(); |
| 281 | assertThat(result3, is(IsisPduType.L1HELLOPDU)); |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Tests readFrom() method. |
| 286 | */ |
| 287 | @Test |
| 288 | public void testReadFrom() throws Exception { |
| 289 | isisHeader.readFrom(channelBuffer); |
| 290 | assertThat(isisHeader, is(notNullValue())); |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Tests asBytes() method. |
| 295 | */ |
| 296 | @Test |
| 297 | public void testAsBytes() throws Exception { |
| 298 | isisHeader.asBytes(); |
| 299 | assertThat(isisHeader, is(notNullValue())); |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Tests populateHeader() method. |
| 304 | */ |
| 305 | @Test |
| 306 | public void testPopulateHeader() throws Exception { |
| 307 | isisHeader.populateHeader(new IsisHeader()); |
| 308 | assertThat(isisHeader, is(notNullValue())); |
| 309 | } |
| 310 | } |