nicklesh adlakha | 90bfa6a | 2016-04-28 20:38:33 +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.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.onosproject.isis.io.isispacket.IsisHeader; |
| 25 | |
| 26 | import static org.hamcrest.CoreMatchers.is; |
| 27 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 28 | import static org.hamcrest.MatcherAssert.assertThat; |
| 29 | |
| 30 | /** |
| 31 | * Unit test class for L1L2HelloPdu. |
| 32 | */ |
| 33 | public class L1L2HelloPduTest { |
| 34 | private final String lanId = "1111.1111.1111"; |
| 35 | private final byte[] helloL1L2 = { |
| 36 | 1, 34, 34, 34, 34, 34, 34, 0, |
| 37 | 30, 5, -39, 64, 34, 34, 34, 34, 34, 34, 1, -127, 1, -52, 1, |
| 38 | 4, 3, 73, 0, 10, -124, 4, 10, 0, 10, 2, -45, 3, 0, 0, 0, |
| 39 | 8, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 40 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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
| 95 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, -93, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 96 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 97 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 98 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 99 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 100 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 101 | 0, 0, 0, 0, 0, 0, 0, 0, 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 |
| 103 | }; |
| 104 | private L1L2HelloPdu l1L2HelloPdu; |
| 105 | private IsisHeader isisHeader; |
| 106 | private String resultStr; |
| 107 | private byte resultByte; |
| 108 | private int resultInt; |
| 109 | private ChannelBuffer channelBuffer; |
| 110 | private byte[] result; |
| 111 | |
| 112 | @Before |
| 113 | public void setUp() throws Exception { |
| 114 | isisHeader = new IsisHeader(); |
| 115 | isisHeader.setIsisPduType(15); |
| 116 | l1L2HelloPdu = new L1L2HelloPdu(isisHeader); |
| 117 | channelBuffer = EasyMock.createMock(ChannelBuffer.class); |
| 118 | } |
| 119 | |
| 120 | @After |
| 121 | public void tearDown() throws Exception { |
| 122 | isisHeader = null; |
| 123 | l1L2HelloPdu = null; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Tests setLanId() getter method. |
| 128 | */ |
| 129 | @Test |
| 130 | public void testLanId() throws Exception { |
| 131 | l1L2HelloPdu.setLanId(lanId); |
| 132 | resultStr = l1L2HelloPdu.lanId(); |
| 133 | assertThat(resultStr, is(lanId)); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Tests setLanId() setter method. |
| 138 | */ |
| 139 | @Test |
| 140 | public void testSetLanId() throws Exception { |
| 141 | l1L2HelloPdu.setLanId(lanId); |
| 142 | resultStr = l1L2HelloPdu.lanId(); |
| 143 | assertThat(resultStr, is(lanId)); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Tests priority() getter method. |
| 148 | */ |
| 149 | @Test |
| 150 | public void testPriority() throws Exception { |
| 151 | l1L2HelloPdu.setPriority((byte) 1); |
| 152 | resultByte = l1L2HelloPdu.priority(); |
| 153 | assertThat(resultByte, is((byte) 1)); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Tests priority() setter method. |
| 158 | */ |
| 159 | @Test |
| 160 | public void testSetPriority() throws Exception { |
| 161 | l1L2HelloPdu.setPriority((byte) 1); |
| 162 | resultByte = l1L2HelloPdu.priority(); |
| 163 | assertThat(resultByte, is((byte) 1)); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Tests readFrom() method. |
| 168 | */ |
| 169 | @Test |
| 170 | public void testReadFrom() throws Exception { |
| 171 | channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); |
| 172 | l1L2HelloPdu.readFrom(channelBuffer); |
| 173 | assertThat(l1L2HelloPdu, is(notNullValue())); |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Tests asByte() method. |
| 178 | */ |
| 179 | @Test |
| 180 | public void testAsBytes() throws Exception { |
| 181 | channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); |
| 182 | l1L2HelloPdu.readFrom(channelBuffer); |
| 183 | result = l1L2HelloPdu.asBytes(); |
| 184 | assertThat(l1L2HelloPdu, is(notNullValue())); |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Tests l1l2IsisPduHeader() method. |
| 189 | */ |
| 190 | @Test |
| 191 | public void testL1l2IsisPduHeader() throws Exception { |
| 192 | result = l1L2HelloPdu.l1l2IsisPduHeader(); |
| 193 | assertThat(l1L2HelloPdu, is(notNullValue())); |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Tests l1l2HelloPduBody() method. |
| 198 | */ |
| 199 | @Test |
| 200 | public void testL1l2HelloPduBody() throws Exception { |
| 201 | channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); |
| 202 | l1L2HelloPdu.readFrom(channelBuffer); |
| 203 | result = l1L2HelloPdu.l1l2HelloPduBody(); |
| 204 | assertThat(result, is(notNullValue())); |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Tests toString() method. |
| 209 | */ |
| 210 | @Test |
| 211 | public void testToString() throws Exception { |
| 212 | assertThat(l1L2HelloPdu.toString(), is(notNullValue())); |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Tests equals() method. |
| 217 | */ |
| 218 | @Test |
| 219 | public void testEquals() throws Exception { |
| 220 | assertThat(l1L2HelloPdu.equals(new L1L2HelloPdu(new IsisHeader())), is(true)); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Tests hashCode() method. |
| 225 | */ |
| 226 | @Test |
| 227 | public void testHashCode() throws Exception { |
| 228 | resultInt = l1L2HelloPdu.hashCode(); |
| 229 | assertThat(resultInt, is(notNullValue())); |
| 230 | } |
| 231 | } |