blob: 7d71fd8d2facb1ac93f7a86376fe5c91a9a39996 [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 */
16package org.onosproject.isis.io.isispacket.pdu;
17
18import org.easymock.EasyMock;
19import org.jboss.netty.buffer.ChannelBuffer;
20import org.jboss.netty.buffer.ChannelBuffers;
21import org.junit.After;
22import org.junit.Before;
23import org.junit.Test;
24import org.onosproject.isis.controller.IsisPduType;
25import org.onosproject.isis.io.isispacket.IsisHeader;
26import org.onosproject.isis.io.isispacket.tlv.AdjacencyStateTlv;
27import org.onosproject.isis.io.isispacket.tlv.IsisTlv;
28import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
29
30import java.util.List;
31
32import static org.hamcrest.CoreMatchers.is;
33import static org.hamcrest.CoreMatchers.notNullValue;
34import static org.hamcrest.MatcherAssert.assertThat;
35
36/**
37 * Unit test class for Psnp.
38 */
39public class PsnpTest {
40 private final String srcId = "1111.1111.1111";
41 private final byte[] psnpPkt = {
42 0, 35, 41, 41, 41, 41, 41, 41, 0, 9, 16, 4, -81, 18, 52, 18,
43 52, 0, 18, 0, 0, 0, 0, 0, 42, -94, -29
44 };
45 private Psnp psnp;
46 private IsisHeader isisHeader;
47 private ChannelBuffer channelBuffer;
48 private IsisTlv isisTlv;
49 private TlvHeader tlvHeader;
50 private List<IsisTlv> resultList;
51 private String resultStr;
52 private int resultInt;
53 private byte[] result;
54
55 @Before
56 public void setUp() throws Exception {
57 isisHeader = new IsisHeader();
58 isisHeader.setIsisPduType(IsisPduType.L1PSNP.value());
59 psnp = new Psnp(isisHeader);
60 tlvHeader = new TlvHeader();
61 channelBuffer = EasyMock.createMock(ChannelBuffer.class);
62 isisTlv = new AdjacencyStateTlv(tlvHeader);
63
64 }
65
66 @After
67 public void tearDown() throws Exception {
68 isisHeader = null;
69 psnp = null;
70 channelBuffer = null;
71 tlvHeader = null;
72 isisTlv = null;
73 tlvHeader = null;
74 }
75
76 /**
77 * Tests addTlv() method.
78 */
79 @Test
80 public void testAddTlv() throws Exception {
81 psnp.addTlv(isisTlv);
82 resultList = psnp.getAllTlv();
83 assertThat(resultList.size(), is(1));
84
85 }
86
87 /**
88 * Tests getAllTlv() method.
89 */
90 @Test
91 public void testGetAllTlv() throws Exception {
92 psnp.addTlv(isisTlv);
93 resultList = psnp.getAllTlv();
94 assertThat(resultList.size(), is(1));
95
96 }
97
98 /**
99 * Tests sourceId() getter method.
100 */
101 @Test
102 public void testSourceId() throws Exception {
103 psnp.setSourceId(srcId);
104 resultStr = psnp.sourceId();
105 assertThat(resultStr, is(srcId));
106 }
107
108 /**
109 * Tests sourceId() setter method.
110 */
111 @Test
112 public void testSetSourceId() throws Exception {
113 psnp.setSourceId(srcId);
114 resultStr = psnp.sourceId();
115 assertThat(resultStr, is(srcId));
116 }
117
118 /**
119 * Tests pduLength() getter method.
120 */
121 @Test
122 public void testPduLength() throws Exception {
123 psnp.setPduLength(10);
124 resultInt = psnp.pduLength();
125 assertThat(resultInt, is(10));
126 }
127
128 /**
129 * Tests pduLength() setter method.
130 */
131 @Test
132 public void testSetPduLength() throws Exception {
133 psnp.setPduLength(10);
134 resultInt = psnp.pduLength();
135 assertThat(resultInt, is(10));
136 }
137
138 /**
139 * Tests readFrom() method.
140 */
141 @Test
142 public void testReadFrom() throws Exception {
143 channelBuffer = ChannelBuffers.copiedBuffer(psnpPkt);
144 psnp.readFrom(channelBuffer);
145 assertThat(psnp, is(notNullValue()));
146 }
147
148 /**
149 * Tests lasBytes() method.
150 */
151 @Test
152 public void testAsBytes() throws Exception {
153 channelBuffer = ChannelBuffers.copiedBuffer(psnpPkt);
154 psnp.readFrom(channelBuffer);
155 result = psnp.asBytes();
156 assertThat(result, is(notNullValue()));
157 }
158
159 /**
160 * Tests isisPduHeader() method.
161 */
162 @Test
163 public void testIsisPduHeader() throws Exception {
164 result = psnp.isisPduHeader();
165 assertThat(result, is(notNullValue()));
166 }
167
168 /**
169 * Tests partialSequenceNumberPduBody() method.
170 */
171 @Test
172 public void testPartialSequenceNumberPduBody() throws Exception {
173 channelBuffer = ChannelBuffers.copiedBuffer(psnpPkt);
174 psnp.readFrom(channelBuffer);
175 result = psnp.partialSequenceNumberPduBody();
176 assertThat(result, is(notNullValue()));
177 }
178
179 /**
180 * Tests toString() method.
181 */
182 @Test
183 public void testToString() throws Exception {
184 assertThat((psnp.toString()), is(notNullValue()));
185 }
186
187 /**
188 * Tests equals() method.
189 */
190 @Test
191 public void testEquals() throws Exception {
192 assertThat(psnp.equals(new Psnp(new IsisHeader())), is(true));
193 }
194
195 /**
196 * Tests hashCode() method.
197 */
198 @Test
199 public void testHashCode() throws Exception {
200 int hashCode = psnp.hashCode();
201 assertThat(hashCode, is(notNullValue()));
202 }
203}