blob: 5a19f2c895719299e20f3408736a12793bda31e4 [file] [log] [blame]
nicklesh adlakha90bfa6a2016-04-28 20:38:33 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
nicklesh adlakha90bfa6a2016-04-28 20:38:33 +05303 *
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
17package org.onosproject.isis.io.isispacket.pdu;
18
19import org.easymock.EasyMock;
20import org.jboss.netty.buffer.ChannelBuffer;
21import org.jboss.netty.buffer.ChannelBuffers;
22import org.junit.After;
23import org.junit.Before;
24import org.junit.Test;
25import org.onosproject.isis.controller.IsisPduType;
26import org.onosproject.isis.io.isispacket.IsisHeader;
27import org.onosproject.isis.io.isispacket.tlv.HostNameTlv;
28import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
29
30import static org.hamcrest.CoreMatchers.is;
31import static org.hamcrest.CoreMatchers.notNullValue;
32import static org.hamcrest.MatcherAssert.assertThat;
33
34/**
35 * Unit test class for LsPdu.
36 */
37public class LsPduTest {
38 private final String lspId = "1111.1111.1111";
39 private final byte[] l1Lsp = {
40 0, 86, 4, -81, 34, 34, 34, 34, 34, 34, 0, 0, 0, 0, 0, 9, 99, 11, 1, 1, 4, 3, 73,
41 0, 10, -127, 1, -52, -119, 2, 82, 50, -124, 4, -64, -88, 10, 1, -128, 24, 10,
42 -128, -128, -128, 10, 0, 10, 0, -1, -1, -1, -4, 10, -128, -128, -128, -64, -88,
43 10, 0, -1, -1, -1, 0, 2, 12, 0, 10, -128, -128, -128, 51, 51, 51, 51, 51, 51, 2
44 };
45 private LsPdu lsPdu;
46 private IsisHeader isisHeader;
47 private TlvHeader tlvHeader;
48 private int resultInt;
49 private boolean resultBool;
50 private byte resultByte;
51 private AttachedToOtherAreas resultObj;
52 private String resultStr;
53 private ChannelBuffer channelBuffer;
54 private byte[] result;
55
56 @Before
57 public void setUp() throws Exception {
58 isisHeader = new IsisHeader();
59 tlvHeader = new TlvHeader();
60 isisHeader.setIsisPduType(IsisPduType.L1LSPDU.value());
61 lsPdu = new LsPdu(isisHeader);
62 channelBuffer = EasyMock.createMock(ChannelBuffer.class);
63 }
64
65 @After
66 public void tearDown() throws Exception {
67 isisHeader = null;
68 lsPdu = null;
69 tlvHeader = null;
70 channelBuffer = null;
71 }
72
73 /**
74 * Tests addTlv() method.
75 */
76 @Test
77 public void testAddTlv() throws Exception {
78 lsPdu.addTlv(new HostNameTlv(tlvHeader));
79 assertThat(lsPdu, is(notNullValue()));
80 }
81
82 /**
83 * Tests remainingLifeTime() getter method.
84 */
85 @Test
86 public void testRemainingLifeTime() throws Exception {
87 lsPdu.setRemainingLifeTime(10);
88 resultInt = lsPdu.remainingLifeTime();
89 assertThat(resultInt, is(10));
90 }
91
92 /**
93 * Tests remainingLifeTime() setter method.
94 */
95 @Test
96 public void testSetRemainingLifeTime() throws Exception {
97 lsPdu.setRemainingLifeTime(10);
98 resultInt = lsPdu.remainingLifeTime();
99 assertThat(resultInt, is(10));
100 }
101
102 /**
103 * Tests lspDbol() getter method.
104 */
105 @Test
106 public void testLspDbol() throws Exception {
107 lsPdu.setLspDbol(true);
108 resultBool = lsPdu.lspDbol();
109 assertThat(resultBool, is(true));
110 }
111
112 /**
113 * Tests lspDbol() setter method.
114 */
115 @Test
116 public void testSetLspDbol() throws Exception {
117 lsPdu.setLspDbol(true);
118 resultBool = lsPdu.lspDbol();
119 assertThat(resultBool, is(true));
120 }
121
122 /**
123 * Tests typeBlock() getter method.
124 */
125 @Test
126 public void testTypeBlock() throws Exception {
127 lsPdu.setTypeBlock((byte) 1);
128 resultByte = lsPdu.typeBlock();
129 assertThat(resultByte, is((byte) 1));
130 }
131
132 /**
133 * Tests typeBlock() setter method.
134 */
135 @Test
136 public void testSetTypeBlock() throws Exception {
137 lsPdu.setTypeBlock((byte) 1);
138 resultByte = lsPdu.typeBlock();
139 assertThat(resultByte, is((byte) 1));
140 }
141
142 /**
143 * Tests sequenceNumber() getter method.
144 */
145 @Test
146 public void testSequenceNumber() throws Exception {
147 lsPdu.setSequenceNumber(1);
148 resultInt = lsPdu.sequenceNumber();
149 assertThat(resultInt, is(1));
150 }
151
152 /**
153 * Tests sequenceNumber() setter method.
154 */
155 @Test
156 public void testSetSequenceNumber() throws Exception {
157 lsPdu.setSequenceNumber(1);
158 resultInt = lsPdu.sequenceNumber();
159 assertThat(resultInt, is(1));
160 }
161
162 /**
163 * Tests checkSum() getter method.
164 */
165 @Test
166 public void testCheckSum() throws Exception {
167 lsPdu.setCheckSum(1);
168 resultInt = lsPdu.checkSum();
169 assertThat(resultInt, is(1));
170 }
171
172 /**
173 * Tests checkSum() setter method.
174 */
175 @Test
176 public void testSetCheckSum() throws Exception {
177 lsPdu.setCheckSum(1);
178 resultInt = lsPdu.checkSum();
179 assertThat(resultInt, is(1));
180 }
181
182 /**
183 * Tests partitionRepair() getter method.
184 */
185 @Test
186 public void testPartitionRepair() throws Exception {
187 lsPdu.setPartitionRepair(true);
188 resultBool = lsPdu.partitionRepair();
189 assertThat(resultBool, is(true));
190 }
191
192 /**
193 * Tests partitionRepair() setter method.
194 */
195 @Test
196 public void testSetPartitionRepair() throws Exception {
197 lsPdu.setPartitionRepair(true);
198 resultBool = lsPdu.partitionRepair();
199 assertThat(resultBool, is(true));
200 }
201
202 /**
203 * Tests attachedToOtherAreas() getter method.
204 */
205 @Test
206 public void testAttachedToOtherAreas() throws Exception {
207 lsPdu.setAttachedToOtherAreas(AttachedToOtherAreas.DEFAULTMETRIC);
208 resultObj = lsPdu.attachedToOtherAreas();
209 assertThat(resultObj, is(AttachedToOtherAreas.DEFAULTMETRIC));
210 }
211
212 /**
213 * Tests attachedToOtherAreas() setter method.
214 */
215 @Test
216 public void testSetAttachedToOtherAreas() throws Exception {
217 lsPdu.setAttachedToOtherAreas(AttachedToOtherAreas.DEFAULTMETRIC);
218 resultObj = lsPdu.attachedToOtherAreas();
219 assertThat(resultObj, is(AttachedToOtherAreas.DEFAULTMETRIC));
220 }
221
222 /**
223 * Tests intermediateSystemType() getter method.
224 */
225 @Test
226 public void testIntermediateSystemType() throws Exception {
227 lsPdu.setIntermediateSystemType((byte) 1);
228 resultByte = lsPdu.intermediateSystemType();
229 assertThat(resultByte, is((byte) 1));
230 }
231
232 /**
233 * Tests intermediateSystemType() setter method.
234 */
235 @Test
236 public void testSetIntermediateSystemType() throws Exception {
237 lsPdu.setIntermediateSystemType((byte) 1);
238 resultByte = lsPdu.intermediateSystemType();
239 assertThat(resultByte, is((byte) 1));
240 }
241
242 /**
243 * Tests lspId() getter method.
244 */
245 @Test
246 public void testLspId() throws Exception {
247 lsPdu.setLspId(lspId);
248 resultStr = lsPdu.lspId();
249 assertThat(resultStr, is(lspId));
250 }
251
252 /**
253 * Tests lspId() setter method.
254 */
255 @Test
256 public void testSetLspId() throws Exception {
257 lsPdu.setLspId(lspId);
258 resultStr = lsPdu.lspId();
259 assertThat(resultStr, is(lspId));
260 }
261
262 /**
263 * Tests pduLength() getter method.
264 */
265 @Test
266 public void testPduLength() throws Exception {
267 lsPdu.setPduLength(10);
268 resultInt = lsPdu.pduLength();
269 assertThat(resultInt, is(10));
270 }
271
272 /**
273 * Tests pduLength() setter method.
274 */
275 @Test
276 public void testSetPduLength() throws Exception {
277 lsPdu.setPduLength(10);
278 resultInt = lsPdu.pduLength();
279 assertThat(resultInt, is(10));
280 }
281
282 /**
283 * Tests readFrom() method.
284 */
285 @Test
286 public void testReadFrom() throws Exception {
287 channelBuffer = ChannelBuffers.copiedBuffer(l1Lsp);
288 lsPdu.readFrom(channelBuffer);
289 assertThat(lsPdu, is(notNullValue()));
290 }
291
292 /**
293 * Tests asBytes() method.
294 */
295 @Test
296 public void testAsBytes() throws Exception {
297 channelBuffer = ChannelBuffers.copiedBuffer(l1Lsp);
298 lsPdu.readFrom(channelBuffer);
299 result = lsPdu.asBytes();
300 assertThat(result, is(notNullValue()));
301 }
302
303 /**
304 * Tests l1l2IsisPduHeader() method.
305 */
306 @Test
307 public void testL1l2IsisPduHeader() throws Exception {
308 result = lsPdu.l1l2IsisPduHeader();
309 assertThat(result, is(notNullValue()));
310 }
311
312 /**
313 * Tests l1l2LsPduBody() method.
314 */
315 @Test
316 public void testL1l2LsPduBody() throws Exception {
317 channelBuffer = ChannelBuffers.copiedBuffer(l1Lsp);
318 lsPdu.readFrom(channelBuffer);
319 result = lsPdu.l1l2LsPduBody();
320 assertThat(result, is(notNullValue()));
321 }
322
323 /**
324 * Tests toString() method.
325 */
326 @Test
327 public void testToString() throws Exception {
328 assertThat(lsPdu.toString(), is(notNullValue()));
329 }
330
331 /**
332 * Tests equals() method.
333 */
334 @Test
335 public void testEquals() throws Exception {
336 assertThat(lsPdu.equals(new LsPdu(new IsisHeader())), is(true));
337 }
338
339 /**
340 * Tests hashCode() method.
341 */
342 @Test
343 public void testHashCode() throws Exception {
344 resultInt = lsPdu.hashCode();
345 assertThat(resultInt, is(notNullValue()));
346 }
347}