SureshBR
Committed by Gerrit Code Review

UT updated to add javadoc, remove logs and if check

Change-Id: Ie8355c20e0ebb9c5a9136cb3eb98c8b716b61050
...@@ -15,42 +15,30 @@ ...@@ -15,42 +15,30 @@
15 */ 15 */
16 package org.onosproject.pcepio; 16 package org.onosproject.pcepio;
17 17
18 -import java.util.Arrays; 18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.core.Is.is;
20 +import static org.hamcrest.core.IsSame.sameInstance;
19 21
20 import org.jboss.netty.buffer.ChannelBuffer; 22 import org.jboss.netty.buffer.ChannelBuffer;
21 import org.jboss.netty.buffer.ChannelBuffers; 23 import org.jboss.netty.buffer.ChannelBuffers;
22 -import org.junit.After;
23 -import org.junit.Assert;
24 -import org.junit.Before;
25 import org.junit.Test; 24 import org.junit.Test;
26 import org.onosproject.pcepio.exceptions.PcepParseException; 25 import org.onosproject.pcepio.exceptions.PcepParseException;
27 import org.onosproject.pcepio.protocol.PcepFactories; 26 import org.onosproject.pcepio.protocol.PcepFactories;
28 import org.onosproject.pcepio.protocol.PcepMessage; 27 import org.onosproject.pcepio.protocol.PcepMessage;
29 import org.onosproject.pcepio.protocol.PcepMessageReader; 28 import org.onosproject.pcepio.protocol.PcepMessageReader;
30 import org.onosproject.pcepio.protocol.PcepOpenMsg; 29 import org.onosproject.pcepio.protocol.PcepOpenMsg;
31 -import org.slf4j.Logger;
32 -import org.slf4j.LoggerFactory;
33 -
34 /** 30 /**
35 * Test cases for PCEP OPEN Message. 31 * Test cases for PCEP OPEN Message.
36 */ 32 */
37 public class PcepOpenMsgTest { 33 public class PcepOpenMsgTest {
38 34
39 - protected static final Logger log = LoggerFactory.getLogger(PcepOpenMsgTest.class); 35 + /**
40 - 36 + * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV,
41 - @Before 37 + * PCECC-CAPABILITY-TLV in Pcep Open message.
42 - public void startUp() { 38 + */
43 - }
44 -
45 - @After
46 - public void tearDown() {
47 -
48 - }
49 -
50 @Test 39 @Test
51 public void openMessageTest1() throws PcepParseException { 40 public void openMessageTest1() throws PcepParseException {
52 41
53 - // OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV, )
54 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x10, 0x00, 0x20, 0x20, 0x1e, 0x78, (byte) 0xbd, 42 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x10, 0x00, 0x20, 0x20, 0x1e, 0x78, (byte) 0xbd,
55 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY 43 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY
56 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV 44 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV
...@@ -63,38 +51,28 @@ public class PcepOpenMsgTest { ...@@ -63,38 +51,28 @@ public class PcepOpenMsgTest {
63 51
64 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 52 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
65 PcepMessage message = null; 53 PcepMessage message = null;
66 - try { 54 +
67 - message = reader.readFrom(buffer); 55 + message = reader.readFrom(buffer);
68 - } catch (PcepParseException e) { 56 +
69 - e.printStackTrace(); 57 + assertThat(message, sameInstance((PcepOpenMsg) message));
70 - } 58 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
71 - 59 + message.writeTo(buf);
72 - if (message instanceof PcepOpenMsg) { 60 + testOpenMsg = buf.array();
73 - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 61 +
74 - message.writeTo(buf); 62 + int readLen = buf.writerIndex() - 0;
75 - testOpenMsg = buf.array(); 63 + testOpenMsg = new byte[readLen];
76 - 64 + buf.readBytes(testOpenMsg, 0, readLen);
77 - int iReadLen = buf.writerIndex() - 0; 65 +
78 - testOpenMsg = new byte[iReadLen]; 66 + assertThat(testOpenMsg, is(openMsg));
79 - buf.readBytes(testOpenMsg, 0, iReadLen); 67 +
80 -
81 - if (Arrays.equals(openMsg, testOpenMsg)) {
82 - Assert.assertArrayEquals(openMsg, testOpenMsg);
83 - log.debug("openMsg are equal :" + openMsg);
84 - } else {
85 - Assert.fail("test case failed");
86 - log.debug("not equal");
87 - }
88 - } else {
89 - Assert.fail("test case failed");
90 - log.debug("not equal");
91 - }
92 } 68 }
93 69
70 + /**
71 + * This test case checks open object with STATEFUL-PCE-CAPABILITY-TLV in Pcep Open message.
72 + */
94 @Test 73 @Test
95 public void openMessageTest2() throws PcepParseException { 74 public void openMessageTest2() throws PcepParseException {
96 75
97 - // OPEN OBJECT (STATEFUL-PCE-CAPABILITY).
98 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header 76 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header
99 0x01, 0x10, 0x00, 0x10, // common object header 77 0x01, 0x10, 0x00, 0x10, // common object header
100 0x20, 0x1E, 0x78, 0x01, // OPEN object 78 0x20, 0x1E, 0x78, 0x01, // OPEN object
...@@ -105,38 +83,28 @@ public class PcepOpenMsgTest { ...@@ -105,38 +83,28 @@ public class PcepOpenMsgTest {
105 83
106 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 84 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
107 PcepMessage message = null; 85 PcepMessage message = null;
108 - try { 86 +
109 - message = reader.readFrom(buffer); 87 + message = reader.readFrom(buffer);
110 - } catch (PcepParseException e) { 88 +
111 - e.printStackTrace(); 89 + assertThat(message, sameInstance((PcepOpenMsg) message));
112 - } 90 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
113 - 91 + message.writeTo(buf);
114 - if (message instanceof PcepOpenMsg) { 92 + testOpenMsg = buf.array();
115 - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 93 +
116 - message.writeTo(buf); 94 + int readLen = buf.writerIndex() - 0;
117 - testOpenMsg = buf.array(); 95 + testOpenMsg = new byte[readLen];
118 - 96 + buf.readBytes(testOpenMsg, 0, readLen);
119 - int iReadLen = buf.writerIndex() - 0; 97 +
120 - testOpenMsg = new byte[iReadLen]; 98 + assertThat(testOpenMsg, is(openMsg));
121 - buf.readBytes(testOpenMsg, 0, iReadLen); 99 +
122 -
123 - if (Arrays.equals(openMsg, testOpenMsg)) {
124 - Assert.assertArrayEquals(openMsg, testOpenMsg);
125 - log.debug("openMsg are equal :" + openMsg);
126 - } else {
127 - Assert.fail("test case failed");
128 - log.debug("not equal");
129 - }
130 - } else {
131 - Assert.fail("test case failed");
132 - log.debug("not equal");
133 - }
134 } 100 }
135 101
102 + /**
103 + * This test case checks open object with GmplsCapability tlv in Pcep Open message.
104 + */
136 @Test 105 @Test
137 public void openMessageTest3() throws PcepParseException { 106 public void openMessageTest3() throws PcepParseException {
138 107
139 - // OPEN OBJECT (GmplsCapability).
140 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header 108 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header
141 0x01, 0x10, 0x00, 0x10, // common object header 109 0x01, 0x10, 0x00, 0x10, // common object header
142 0x20, 0x1E, 0x78, 0x01, // OPEN object 110 0x20, 0x1E, 0x78, 0x01, // OPEN object
...@@ -148,38 +116,29 @@ public class PcepOpenMsgTest { ...@@ -148,38 +116,29 @@ public class PcepOpenMsgTest {
148 116
149 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 117 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
150 PcepMessage message = null; 118 PcepMessage message = null;
151 - try { 119 +
152 - message = reader.readFrom(buffer); 120 + message = reader.readFrom(buffer);
153 - } catch (PcepParseException e) { 121 +
154 - e.printStackTrace(); 122 + assertThat(message, sameInstance((PcepOpenMsg) message));
155 - } 123 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
156 - 124 + message.writeTo(buf);
157 - if (message instanceof PcepOpenMsg) { 125 + testOpenMsg = buf.array();
158 - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 126 +
159 - message.writeTo(buf); 127 + int readLen = buf.writerIndex() - 0;
160 - testOpenMsg = buf.array(); 128 + testOpenMsg = new byte[readLen];
161 - 129 + buf.readBytes(testOpenMsg, 0, readLen);
162 - int iReadLen = buf.writerIndex() - 0; 130 +
163 - testOpenMsg = new byte[iReadLen]; 131 +
164 - buf.readBytes(testOpenMsg, 0, iReadLen); 132 + assertThat(testOpenMsg, is(openMsg));
165 - 133 +
166 - if (Arrays.equals(openMsg, testOpenMsg)) {
167 - Assert.assertArrayEquals(openMsg, testOpenMsg);
168 - log.debug("openMsg are equal :" + openMsg);
169 - } else {
170 - Assert.fail("test case failed");
171 - log.debug("not equal");
172 - }
173 - } else {
174 - Assert.fail("test case failed");
175 - log.debug("not equal");
176 - }
177 } 134 }
178 135
136 + /**
137 + * This test case checks open object with StatefulLspDbVer Tlv in Pcep Open message.
138 + */
179 @Test 139 @Test
180 public void openMessageTest4() throws PcepParseException { 140 public void openMessageTest4() throws PcepParseException {
181 141
182 - // OPEN OBJECT (StatefulLspDbVerTlv).
183 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x18, 142 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x18,
184 0x01, 0x10, 0x00, 0x14, 0x20, 0x1e, 0x78, 0x20, 143 0x01, 0x10, 0x00, 0x14, 0x20, 0x1e, 0x78, 0x20,
185 0x00, 0x17, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; //StatefulLspDbVerTlv 144 0x00, 0x17, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; //StatefulLspDbVerTlv
...@@ -190,38 +149,28 @@ public class PcepOpenMsgTest { ...@@ -190,38 +149,28 @@ public class PcepOpenMsgTest {
190 149
191 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 150 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
192 PcepMessage message = null; 151 PcepMessage message = null;
193 - try { 152 +
194 - message = reader.readFrom(buffer); 153 + message = reader.readFrom(buffer);
195 - } catch (PcepParseException e) { 154 +
196 - e.printStackTrace(); 155 + assertThat(message, sameInstance((PcepOpenMsg) message));
197 - } 156 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
198 - 157 + message.writeTo(buf);
199 - if (message instanceof PcepOpenMsg) { 158 + testOpenMsg = buf.array();
200 - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 159 +
201 - message.writeTo(buf); 160 + int readLen = buf.writerIndex() - 0;
202 - testOpenMsg = buf.array(); 161 + testOpenMsg = new byte[readLen];
203 - 162 + buf.readBytes(testOpenMsg, 0, readLen);
204 - int iReadLen = buf.writerIndex() - 0; 163 +
205 - testOpenMsg = new byte[iReadLen]; 164 + assertThat(testOpenMsg, is(openMsg));
206 - buf.readBytes(testOpenMsg, 0, iReadLen); 165 +
207 -
208 - if (Arrays.equals(openMsg, testOpenMsg)) {
209 - Assert.assertArrayEquals(openMsg, testOpenMsg);
210 - log.debug("openMsg are equal :" + openMsg);
211 - } else {
212 - Assert.fail("test case failed");
213 - log.debug("not equal");
214 - }
215 - } else {
216 - Assert.fail("test case failed");
217 - log.debug("not equal");
218 - }
219 } 166 }
220 167
168 + /**
169 + * This test case checks open object with no tlv's in Pcep Open message.
170 + */
221 @Test 171 @Test
222 public void openMessageTest5() throws PcepParseException { 172 public void openMessageTest5() throws PcepParseException {
223 173
224 - // OPEN OBJECT (no Tlvs).
225 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x0C, 174 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x0C,
226 0x01, 0x10, 0x00, 0x08, 0x20, 0x1e, 0x78, (byte) 0xbd }; // no Tlvs in open messsage 175 0x01, 0x10, 0x00, 0x08, 0x20, 0x1e, 0x78, (byte) 0xbd }; // no Tlvs in open messsage
227 176
...@@ -231,40 +180,29 @@ public class PcepOpenMsgTest { ...@@ -231,40 +180,29 @@ public class PcepOpenMsgTest {
231 180
232 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 181 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
233 PcepMessage message = null; 182 PcepMessage message = null;
234 - try { 183 +
235 - message = reader.readFrom(buffer); 184 + message = reader.readFrom(buffer);
236 - } catch (PcepParseException e) { 185 +
237 - e.printStackTrace(); 186 + assertThat(message, sameInstance((PcepOpenMsg) message));
238 - } 187 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
239 - 188 + message.writeTo(buf);
240 - if (message instanceof PcepOpenMsg) { 189 + testOpenMsg = buf.array();
241 - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 190 +
242 - message.writeTo(buf); 191 + int readLen = buf.writerIndex() - 0;
243 - testOpenMsg = buf.array(); 192 + testOpenMsg = new byte[readLen];
244 - 193 + buf.readBytes(testOpenMsg, 0, readLen);
245 - int iReadLen = buf.writerIndex() - 0; 194 +
246 - testOpenMsg = new byte[iReadLen]; 195 + assertThat(testOpenMsg, is(openMsg));
247 - buf.readBytes(testOpenMsg, 0, iReadLen); 196 +
248 -
249 - if (Arrays.equals(openMsg, testOpenMsg)) {
250 - Assert.assertArrayEquals(openMsg, testOpenMsg);
251 - log.debug("openMsg are equal :" + openMsg);
252 - } else {
253 - Assert.fail("test case failed");
254 - log.debug("not equal");
255 - }
256 - } else {
257 - Assert.fail("test case failed");
258 - log.debug("not equal");
259 - }
260 } 197 }
261 198
199 + /**
200 + * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV
201 + * with I bit set in Pcep Open message.
202 + */
262 @Test 203 @Test
263 public void openMessageTest6() throws PcepParseException { 204 public void openMessageTest6() throws PcepParseException {
264 205
265 - /* OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV) with
266 - p bit not set & i bit set.
267 - */
268 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x11, 0x00, 0x20, //p bit not set & i bit set 206 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x11, 0x00, 0x20, //p bit not set & i bit set
269 0x20, 0x1e, 0x78, (byte) 0xbd, 207 0x20, 0x1e, 0x78, (byte) 0xbd,
270 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, // STATEFUL-PCE-CAPABILITY 208 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, // STATEFUL-PCE-CAPABILITY
...@@ -278,40 +216,29 @@ public class PcepOpenMsgTest { ...@@ -278,40 +216,29 @@ public class PcepOpenMsgTest {
278 216
279 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 217 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
280 PcepMessage message = null; 218 PcepMessage message = null;
281 - try { 219 +
282 - message = reader.readFrom(buffer); 220 + message = reader.readFrom(buffer);
283 - } catch (PcepParseException e) { 221 +
284 - e.printStackTrace(); 222 + assertThat(message, sameInstance((PcepOpenMsg) message));
285 - } 223 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
286 - 224 + message.writeTo(buf);
287 - if (message instanceof PcepOpenMsg) { 225 + testOpenMsg = buf.array();
288 - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 226 +
289 - message.writeTo(buf); 227 + int readLen = buf.writerIndex() - 0;
290 - testOpenMsg = buf.array(); 228 + testOpenMsg = new byte[readLen];
291 - 229 + buf.readBytes(testOpenMsg, 0, readLen);
292 - int iReadLen = buf.writerIndex() - 0; 230 +
293 - testOpenMsg = new byte[iReadLen]; 231 + assertThat(testOpenMsg, is(openMsg));
294 - buf.readBytes(testOpenMsg, 0, iReadLen); 232 +
295 -
296 - if (Arrays.equals(openMsg, testOpenMsg)) {
297 - Assert.assertArrayEquals(openMsg, testOpenMsg);
298 - log.debug("openMsg are equal :" + openMsg);
299 - } else {
300 - Assert.fail("test case failed");
301 - log.debug("not equal");
302 - }
303 - } else {
304 - Assert.fail("test case failed");
305 - log.debug("not equal");
306 - }
307 } 233 }
308 234
235 + /**
236 + * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV
237 + * with P bit set in Pcep Open message.
238 + */
309 @Test 239 @Test
310 public void openMessageTest7() throws PcepParseException { 240 public void openMessageTest7() throws PcepParseException {
311 241
312 - /* OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV)
313 - with p bit set & i bit not set.
314 - */
315 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x12, 0x00, 0x20, //p bit set & i bit not set 242 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x12, 0x00, 0x20, //p bit set & i bit not set
316 0x20, 0x1e, 0x78, (byte) 0xbd, 243 0x20, 0x1e, 0x78, (byte) 0xbd,
317 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY 244 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY
...@@ -325,34 +252,26 @@ public class PcepOpenMsgTest { ...@@ -325,34 +252,26 @@ public class PcepOpenMsgTest {
325 252
326 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 253 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
327 PcepMessage message = null; 254 PcepMessage message = null;
328 - try { 255 +
329 - message = reader.readFrom(buffer); 256 + message = reader.readFrom(buffer);
330 - } catch (PcepParseException e) { 257 +
331 - e.printStackTrace(); 258 + assertThat(message, sameInstance((PcepOpenMsg) message));
332 - } 259 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
333 - 260 + message.writeTo(buf);
334 - if (message instanceof PcepOpenMsg) { 261 + testOpenMsg = buf.array();
335 - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 262 +
336 - message.writeTo(buf); 263 + int readLen = buf.writerIndex() - 0;
337 - testOpenMsg = buf.array(); 264 + testOpenMsg = new byte[readLen];
338 - 265 + buf.readBytes(testOpenMsg, 0, readLen);
339 - int iReadLen = buf.writerIndex() - 0; 266 +
340 - testOpenMsg = new byte[iReadLen]; 267 + assertThat(testOpenMsg, is(openMsg));
341 - buf.readBytes(testOpenMsg, 0, iReadLen); 268 +
342 -
343 - if (Arrays.equals(openMsg, testOpenMsg)) {
344 - Assert.assertArrayEquals(openMsg, testOpenMsg);
345 - log.debug("openMsg are equal :" + openMsg);
346 - } else {
347 - Assert.fail("test case failed");
348 - log.debug("not equal");
349 - }
350 - } else {
351 - Assert.fail("test case failed");
352 - log.debug("not equal");
353 - }
354 } 269 }
355 270
271 + /**
272 + * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV
273 + * with P & I bits set in Pcep Open message.
274 + */
356 @Test 275 @Test
357 public void openMessageTest8() throws PcepParseException { 276 public void openMessageTest8() throws PcepParseException {
358 277
...@@ -372,40 +291,29 @@ public class PcepOpenMsgTest { ...@@ -372,40 +291,29 @@ public class PcepOpenMsgTest {
372 291
373 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 292 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
374 PcepMessage message = null; 293 PcepMessage message = null;
375 - try { 294 +
376 - message = reader.readFrom(buffer); 295 + message = reader.readFrom(buffer);
377 - } catch (PcepParseException e) { 296 +
378 - e.printStackTrace(); 297 + assertThat(message, sameInstance((PcepOpenMsg) message));
379 - } 298 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
380 - 299 + message.writeTo(buf);
381 - if (message instanceof PcepOpenMsg) { 300 + testOpenMsg = buf.array();
382 - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 301 +
383 - message.writeTo(buf); 302 + int readLen = buf.writerIndex() - 0;
384 - testOpenMsg = buf.array(); 303 + testOpenMsg = new byte[readLen];
385 - 304 + buf.readBytes(testOpenMsg, 0, readLen);
386 - int iReadLen = buf.writerIndex() - 0; 305 +
387 - testOpenMsg = new byte[iReadLen]; 306 + assertThat(testOpenMsg, is(openMsg));
388 - buf.readBytes(testOpenMsg, 0, iReadLen); 307 +
389 -
390 - if (Arrays.equals(openMsg, testOpenMsg)) {
391 - Assert.assertArrayEquals(openMsg, testOpenMsg);
392 - log.debug("openMsg are equal :" + openMsg);
393 - } else {
394 - Assert.fail("test case failed");
395 - log.debug("not equal");
396 - }
397 - } else {
398 - Assert.fail("test case failed");
399 - log.debug("not equal");
400 - }
401 } 308 }
402 309
310 + /**
311 + * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV
312 + * with P & I bits set and invalid session id in Pcep Open message.
313 + */
403 @Test 314 @Test
404 public void openMessageTest9() throws PcepParseException { 315 public void openMessageTest9() throws PcepParseException {
405 316
406 - /* OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV)
407 - with p bit set & i bit set.
408 - */
409 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x13, 0x00, 0x20, //p bit set & i bit set 317 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x13, 0x00, 0x20, //p bit set & i bit set
410 0x20, 0x1e, 0x78, 0x00, //invalid sessionID 318 0x20, 0x1e, 0x78, 0x00, //invalid sessionID
411 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY 319 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY
...@@ -419,38 +327,30 @@ public class PcepOpenMsgTest { ...@@ -419,38 +327,30 @@ public class PcepOpenMsgTest {
419 327
420 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 328 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
421 PcepMessage message = null; 329 PcepMessage message = null;
422 - try { 330 +
423 - message = reader.readFrom(buffer); 331 + message = reader.readFrom(buffer);
424 - } catch (PcepParseException e) { 332 +
425 - e.printStackTrace(); 333 + assertThat(message, sameInstance((PcepOpenMsg) message));
426 - } 334 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
427 - 335 + message.writeTo(buf);
428 - if (message instanceof PcepOpenMsg) { 336 + testOpenMsg = buf.array();
429 - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 337 +
430 - message.writeTo(buf); 338 + int readLen = buf.writerIndex() - 0;
431 - testOpenMsg = buf.array(); 339 + testOpenMsg = new byte[readLen];
432 - 340 + buf.readBytes(testOpenMsg, 0, readLen);
433 - int iReadLen = buf.writerIndex() - 0; 341 +
434 - testOpenMsg = new byte[iReadLen]; 342 +
435 - buf.readBytes(testOpenMsg, 0, iReadLen); 343 + assertThat(testOpenMsg, is(openMsg));
436 - 344 +
437 - if (Arrays.equals(openMsg, testOpenMsg)) {
438 - Assert.assertArrayEquals(openMsg, testOpenMsg);
439 - log.debug("openMsg are equal :" + openMsg);
440 - } else {
441 - Assert.fail("test case failed");
442 - log.debug("not equal");
443 - }
444 - } else {
445 - Assert.fail("test case failed");
446 - log.debug("not equal");
447 - }
448 } 345 }
449 346
347 + /**
348 + * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV
349 + * in Pcep Open message.
350 + */
450 @Test 351 @Test
451 public void openMessageTest10() throws PcepParseException { 352 public void openMessageTest10() throws PcepParseException {
452 353
453 - //OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV).
454 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x1C, // common header 354 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x1C, // common header
455 0x01, 0x10, 0x00, 0x18, // common object header 355 0x01, 0x10, 0x00, 0x18, // common object header
456 0x20, 0x05, 0x1E, 0x01, // OPEN object 356 0x20, 0x05, 0x1E, 0x01, // OPEN object
...@@ -465,38 +365,29 @@ public class PcepOpenMsgTest { ...@@ -465,38 +365,29 @@ public class PcepOpenMsgTest {
465 365
466 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 366 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
467 PcepMessage message = null; 367 PcepMessage message = null;
468 - try { 368 +
469 - message = reader.readFrom(buffer); 369 + message = reader.readFrom(buffer);
470 - } catch (PcepParseException e) { 370 +
471 - e.printStackTrace(); 371 + assertThat(message, sameInstance((PcepOpenMsg) message));
472 - } 372 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
473 - 373 + message.writeTo(buf);
474 - if (message instanceof PcepOpenMsg) { 374 + testOpenMsg = buf.array();
475 - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 375 +
476 - message.writeTo(buf); 376 + int readLen = buf.writerIndex() - 0;
477 - testOpenMsg = buf.array(); 377 + testOpenMsg = new byte[readLen];
478 - 378 + buf.readBytes(testOpenMsg, 0, readLen);
479 - int iReadLen = buf.writerIndex() - 0; 379 +
480 - testOpenMsg = new byte[iReadLen]; 380 + assertThat(testOpenMsg, is(openMsg));
481 - buf.readBytes(testOpenMsg, 0, iReadLen); 381 +
482 -
483 - if (Arrays.equals(openMsg, testOpenMsg)) {
484 - Assert.assertArrayEquals(openMsg, testOpenMsg);
485 - log.debug("openMsg are equal :" + openMsg);
486 - } else {
487 - Assert.fail("test case failed");
488 - log.debug("not equal");
489 - }
490 - } else {
491 - Assert.fail("test case failed");
492 - log.debug("not equal");
493 - }
494 } 382 }
495 383
384 + /**
385 + * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV,
386 + * PCECC-CAPABILITY-TLV, TED Capability TLV in Pcep Open message.
387 + */
496 @Test 388 @Test
497 public void openMessageTest11() throws PcepParseException { 389 public void openMessageTest11() throws PcepParseException {
498 390
499 - //OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV, TED Capability TLV).
500 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x2C, // common header 391 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x2C, // common header
501 0x01, 0x10, 0x00, 0x28, // common object header 392 0x01, 0x10, 0x00, 0x28, // common object header
502 0x20, 0x05, 0x1E, 0x01, // OPEN object 393 0x20, 0x05, 0x1E, 0x01, // OPEN object
...@@ -512,38 +403,29 @@ public class PcepOpenMsgTest { ...@@ -512,38 +403,29 @@ public class PcepOpenMsgTest {
512 403
513 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 404 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
514 PcepMessage message = null; 405 PcepMessage message = null;
515 - try { 406 +
516 - message = reader.readFrom(buffer); 407 + message = reader.readFrom(buffer);
517 - } catch (PcepParseException e) { 408 +
518 - e.printStackTrace(); 409 + assertThat(message, sameInstance((PcepOpenMsg) message));
519 - } 410 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
520 - 411 + message.writeTo(buf);
521 - if (message instanceof PcepOpenMsg) { 412 + testOpenMsg = buf.array();
522 - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 413 +
523 - message.writeTo(buf); 414 + int readLen = buf.writerIndex() - 0;
524 - testOpenMsg = buf.array(); 415 + testOpenMsg = new byte[readLen];
525 - 416 + buf.readBytes(testOpenMsg, 0, readLen);
526 - int iReadLen = buf.writerIndex() - 0; 417 +
527 - testOpenMsg = new byte[iReadLen]; 418 + assertThat(testOpenMsg, is(openMsg));
528 - buf.readBytes(testOpenMsg, 0, iReadLen); 419 +
529 -
530 - if (Arrays.equals(openMsg, testOpenMsg)) {
531 - Assert.assertArrayEquals(openMsg, testOpenMsg);
532 - log.debug("openMsg are equal :" + openMsg);
533 - } else {
534 - Assert.fail("test case failed");
535 - log.debug("not equal");
536 - }
537 - } else {
538 - Assert.fail("test case failed");
539 - log.debug("not equal");
540 - }
541 } 420 }
542 421
422 + /**
423 + * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV,
424 + * PCECC-CAPABILITY-TLV in Pcep Open message.
425 + */
543 @Test 426 @Test
544 public void openMessageTest12() throws PcepParseException { 427 public void openMessageTest12() throws PcepParseException {
545 428
546 - //OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV).
547 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, // common header 429 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, // common header
548 0x01, 0x10, 0x00, 0x20, // common object header 430 0x01, 0x10, 0x00, 0x20, // common object header
549 0x20, 0x05, 0x1E, 0x01, // OPEN object 431 0x20, 0x05, 0x1E, 0x01, // OPEN object
...@@ -558,38 +440,29 @@ public class PcepOpenMsgTest { ...@@ -558,38 +440,29 @@ public class PcepOpenMsgTest {
558 440
559 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 441 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
560 PcepMessage message = null; 442 PcepMessage message = null;
561 - try { 443 +
562 - message = reader.readFrom(buffer); 444 + message = reader.readFrom(buffer);
563 - } catch (PcepParseException e) { 445 +
564 - e.printStackTrace(); 446 + assertThat(message, sameInstance((PcepOpenMsg) message));
565 - } 447 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
566 - 448 + message.writeTo(buf);
567 - if (message instanceof PcepOpenMsg) { 449 + testOpenMsg = buf.array();
568 - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 450 +
569 - message.writeTo(buf); 451 + int readLen = buf.writerIndex() - 0;
570 - testOpenMsg = buf.array(); 452 + testOpenMsg = new byte[readLen];
571 - 453 + buf.readBytes(testOpenMsg, 0, readLen);
572 - int iReadLen = buf.writerIndex() - 0; 454 +
573 - testOpenMsg = new byte[iReadLen]; 455 + assertThat(testOpenMsg, is(openMsg));
574 - buf.readBytes(testOpenMsg, 0, iReadLen); 456 +
575 -
576 - if (Arrays.equals(openMsg, testOpenMsg)) {
577 - Assert.assertArrayEquals(openMsg, testOpenMsg);
578 - log.debug("openMsg are equal :" + openMsg);
579 - } else {
580 - Assert.fail("test case failed");
581 - log.debug("not equal");
582 - }
583 - } else {
584 - Assert.fail("test case failed");
585 - log.debug("not equal");
586 - }
587 } 457 }
588 458
459 + /**
460 + * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV
461 + * in Pcep Open message.
462 + */
589 @Test 463 @Test
590 public void openMessageTest13() throws PcepParseException { 464 public void openMessageTest13() throws PcepParseException {
591 465
592 - //OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV).
593 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x1c, // common header 466 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x1c, // common header
594 0x01, 0x10, 0x00, 0x18, // common object header 467 0x01, 0x10, 0x00, 0x18, // common object header
595 0x20, 0x05, 0x1E, 0x01, // OPEN object 468 0x20, 0x05, 0x1E, 0x01, // OPEN object
...@@ -603,38 +476,29 @@ public class PcepOpenMsgTest { ...@@ -603,38 +476,29 @@ public class PcepOpenMsgTest {
603 476
604 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 477 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
605 PcepMessage message = null; 478 PcepMessage message = null;
606 - try { 479 +
607 - message = reader.readFrom(buffer); 480 + message = reader.readFrom(buffer);
608 - } catch (PcepParseException e) { 481 +
609 - e.printStackTrace(); 482 + assertThat(message, sameInstance((PcepOpenMsg) message));
610 - } 483 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
611 - 484 + message.writeTo(buf);
612 - if (message instanceof PcepOpenMsg) { 485 + testOpenMsg = buf.array();
613 - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 486 +
614 - message.writeTo(buf); 487 + int readLen = buf.writerIndex() - 0;
615 - testOpenMsg = buf.array(); 488 + testOpenMsg = new byte[readLen];
616 - 489 + buf.readBytes(testOpenMsg, 0, readLen);
617 - int iReadLen = buf.writerIndex() - 0; 490 +
618 - testOpenMsg = new byte[iReadLen]; 491 +
619 - buf.readBytes(testOpenMsg, 0, iReadLen); 492 + assertThat(testOpenMsg, is(openMsg));
620 - 493 +
621 - if (Arrays.equals(openMsg, testOpenMsg)) {
622 - Assert.assertArrayEquals(openMsg, testOpenMsg);
623 - log.debug("openMsg are equal :" + openMsg);
624 - } else {
625 - Assert.fail("test case failed");
626 - log.debug("not equal");
627 - }
628 - } else {
629 - Assert.fail("test case failed ");
630 - log.debug("not equal");
631 - }
632 } 494 }
633 495
496 + /**
497 + * This test case checks open object with STATEFUL-PCE-CAPABILITY in Pcep Open message.
498 + */
634 @Test 499 @Test
635 public void openMessageTest14() throws PcepParseException { 500 public void openMessageTest14() throws PcepParseException {
636 501
637 - //OPEN OBJECT (STATEFUL-PCE-CAPABILITY).
638 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header 502 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header
639 0x01, 0x10, 0x00, 0x10, // common object header 503 0x01, 0x10, 0x00, 0x10, // common object header
640 0x20, 0x05, 0x1E, 0x01, // OPEN object 504 0x20, 0x05, 0x1E, 0x01, // OPEN object
...@@ -647,38 +511,28 @@ public class PcepOpenMsgTest { ...@@ -647,38 +511,28 @@ public class PcepOpenMsgTest {
647 511
648 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 512 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
649 PcepMessage message = null; 513 PcepMessage message = null;
650 - try { 514 +
651 - message = reader.readFrom(buffer); 515 + message = reader.readFrom(buffer);
652 - } catch (PcepParseException e) { 516 +
653 - e.printStackTrace(); 517 + assertThat(message, sameInstance((PcepOpenMsg) message));
654 - } 518 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
655 - 519 + message.writeTo(buf);
656 - if (message instanceof PcepOpenMsg) { 520 + testOpenMsg = buf.array();
657 - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 521 +
658 - message.writeTo(buf); 522 + int readLen = buf.writerIndex() - 0;
659 - testOpenMsg = buf.array(); 523 + testOpenMsg = new byte[readLen];
660 - 524 + buf.readBytes(testOpenMsg, 0, readLen);
661 - int iReadLen = buf.writerIndex() - 0; 525 +
662 - testOpenMsg = new byte[iReadLen]; 526 + assertThat(testOpenMsg, is(openMsg));
663 - buf.readBytes(testOpenMsg, 0, iReadLen); 527 +
664 -
665 - if (Arrays.equals(openMsg, testOpenMsg)) {
666 - Assert.assertArrayEquals(openMsg, testOpenMsg);
667 - log.debug("openMsg are equal :" + openMsg);
668 - } else {
669 - Assert.fail("test case failed");
670 - log.debug("not equal");
671 - }
672 - } else {
673 - Assert.fail("test case failed");
674 - log.debug("not equal");
675 - }
676 } 528 }
677 529
530 + /**
531 + * This test case checks open object with no tlv Pcep Open message.
532 + */
678 @Test 533 @Test
679 public void openMessageTest15() throws PcepParseException { 534 public void openMessageTest15() throws PcepParseException {
680 535
681 - // OPEN OBJECT.
682 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x0c, // common header 536 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x0c, // common header
683 0x01, 0x10, 0x00, 0x08, // common object header 537 0x01, 0x10, 0x00, 0x08, // common object header
684 0x20, 0x05, 0x1E, 0x01 // OPEN object 538 0x20, 0x05, 0x1E, 0x01 // OPEN object
...@@ -690,31 +544,19 @@ public class PcepOpenMsgTest { ...@@ -690,31 +544,19 @@ public class PcepOpenMsgTest {
690 544
691 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 545 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
692 PcepMessage message = null; 546 PcepMessage message = null;
693 - try { 547 +
694 - message = reader.readFrom(buffer); 548 + message = reader.readFrom(buffer);
695 - } catch (PcepParseException e) { 549 +
696 - e.printStackTrace(); 550 + assertThat(message, sameInstance((PcepOpenMsg) message));
697 - } 551 +
698 - 552 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
699 - if (message instanceof PcepOpenMsg) { 553 + message.writeTo(buf);
700 - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 554 + testOpenMsg = buf.array();
701 - message.writeTo(buf); 555 +
702 - testOpenMsg = buf.array(); 556 + int readLen = buf.writerIndex() - 0;
703 - 557 + testOpenMsg = new byte[readLen];
704 - int iReadLen = buf.writerIndex() - 0; 558 + buf.readBytes(testOpenMsg, 0, readLen);
705 - testOpenMsg = new byte[iReadLen]; 559 + assertThat(testOpenMsg, is(openMsg));
706 - buf.readBytes(testOpenMsg, 0, iReadLen); 560 +
707 -
708 - if (Arrays.equals(openMsg, testOpenMsg)) {
709 - Assert.assertArrayEquals(openMsg, testOpenMsg);
710 - log.debug("openMsg are equal :" + openMsg);
711 - } else {
712 - Assert.fail("test case failed");
713 - log.debug("not equal");
714 - }
715 - } else {
716 - Assert.fail("test case failed");
717 - log.debug("not equal");
718 - }
719 } 561 }
720 } 562 }
......