Mahesh Poojary
Committed by Gerrit Code Review

UT for PcLabelUpd message updated with assertThat

Change-Id: I3ba10245e56576e04413dbfc874d0431c5cf8de2
...@@ -17,13 +17,16 @@ package org.onosproject.pcepio; ...@@ -17,13 +17,16 @@ package org.onosproject.pcepio;
17 17
18 import org.jboss.netty.buffer.ChannelBuffer; 18 import org.jboss.netty.buffer.ChannelBuffer;
19 import org.jboss.netty.buffer.ChannelBuffers; 19 import org.jboss.netty.buffer.ChannelBuffers;
20 -import org.junit.Assert;
21 import org.junit.Test; 20 import org.junit.Test;
22 import org.onosproject.pcepio.exceptions.PcepParseException; 21 import org.onosproject.pcepio.exceptions.PcepParseException;
23 import org.onosproject.pcepio.protocol.PcepFactories; 22 import org.onosproject.pcepio.protocol.PcepFactories;
23 +import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg;
24 import org.onosproject.pcepio.protocol.PcepMessage; 24 import org.onosproject.pcepio.protocol.PcepMessage;
25 import org.onosproject.pcepio.protocol.PcepMessageReader; 25 import org.onosproject.pcepio.protocol.PcepMessageReader;
26 -import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg; 26 +
27 +import static org.hamcrest.MatcherAssert.assertThat;
28 +import static org.hamcrest.Matchers.instanceOf;
29 +import static org.hamcrest.Matchers.is;
27 30
28 public class PcepLabelUpdateMsgTest { 31 public class PcepLabelUpdateMsgTest {
29 32
...@@ -31,13 +34,11 @@ public class PcepLabelUpdateMsgTest { ...@@ -31,13 +34,11 @@ public class PcepLabelUpdateMsgTest {
31 * This test case checks for 34 * This test case checks for
32 * <pce-label-download> SRP, LSP, LABEL Object. 35 * <pce-label-download> SRP, LSP, LABEL Object.
33 * in PcepLabelUpdate message. 36 * in PcepLabelUpdate message.
34 - *
35 - * @throws PcepParseException while parsing PCEP message
36 */ 37 */
37 @Test 38 @Test
38 public void labelUpdateMessageTest1() throws PcepParseException { 39 public void labelUpdateMessageTest1() throws PcepParseException {
39 40
40 - byte[] labelUpdate = new byte[] {0x20, 0x0D, 0x00, 0x24, // common header 41 + byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x24, // common header
41 0x21, 0x10, 0x00, 0x0C, // SRP Object Header 42 0x21, 0x10, 0x00, 0x0C, // SRP Object Header
42 0x00, 0x00, 0x00, 0x00, 43 0x00, 0x00, 0x00, 0x00,
43 0x00, 0x00, 0x00, 0x10, 44 0x00, 0x00, 0x00, 0x10,
...@@ -56,29 +57,28 @@ public class PcepLabelUpdateMsgTest { ...@@ -56,29 +57,28 @@ public class PcepLabelUpdateMsgTest {
56 message = reader.readFrom(buffer); 57 message = reader.readFrom(buffer);
57 58
58 byte[] testLabelUpdateMsg = {0}; 59 byte[] testLabelUpdateMsg = {0};
60 + assertThat(message, instanceOf(PcepLabelUpdateMsg.class));
61 +
59 62
60 - Assert.assertTrue("PcepMessage is not instance of PcepLabelUpdate", message instanceof PcepLabelUpdateMsg);
61 ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 63 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
62 message.writeTo(buf); 64 message.writeTo(buf);
63 65
64 - int readLen = buf.writerIndex() - 0; 66 + int readLen = buf.writerIndex();
65 testLabelUpdateMsg = new byte[readLen]; 67 testLabelUpdateMsg = new byte[readLen];
66 buf.readBytes(testLabelUpdateMsg, 0, readLen); 68 buf.readBytes(testLabelUpdateMsg, 0, readLen);
67 69
68 - Assert.assertArrayEquals("PcepLabelUpdate messages are not equal", labelUpdate, testLabelUpdateMsg); 70 + assertThat(testLabelUpdateMsg, is(labelUpdate));
69 } 71 }
70 72
71 /** 73 /**
72 * This test case checks for 74 * This test case checks for
73 * <pce-label-download> SRP, LSP, LABEL Object, LABEL Object. 75 * <pce-label-download> SRP, LSP, LABEL Object, LABEL Object.
74 * in PcepLabelUpdate message. 76 * in PcepLabelUpdate message.
75 - *
76 - * @throws PcepParseException while parsing PCEP message
77 */ 77 */
78 @Test 78 @Test
79 public void labelUpdateMessageTest2() throws PcepParseException { 79 public void labelUpdateMessageTest2() throws PcepParseException {
80 80
81 - byte[] labelUpdate = new byte[] {0x20, 0x0D, 0x00, 0x30, // common header 81 + byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x30, // common header
82 0x21, 0x10, 0x00, 0x0C, // SRP Object Header 82 0x21, 0x10, 0x00, 0x0C, // SRP Object Header
83 0x00, 0x00, 0x00, 0x00, 83 0x00, 0x00, 0x00, 0x00,
84 0x00, 0x00, 0x00, 0x10, 84 0x00, 0x00, 0x00, 0x10,
...@@ -100,28 +100,26 @@ public class PcepLabelUpdateMsgTest { ...@@ -100,28 +100,26 @@ public class PcepLabelUpdateMsgTest {
100 message = reader.readFrom(buffer); 100 message = reader.readFrom(buffer);
101 101
102 byte[] testLabelUpdateMsg = {0}; 102 byte[] testLabelUpdateMsg = {0};
103 - Assert.assertTrue("PcepMessage is not instance of PcepLabelUpdate", message instanceof PcepLabelUpdateMsg); 103 + assertThat(message, instanceOf(PcepLabelUpdateMsg.class));
104 ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 104 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
105 message.writeTo(buf); 105 message.writeTo(buf);
106 106
107 - int readLen = buf.writerIndex() - 0; 107 + int readLen = buf.writerIndex();
108 testLabelUpdateMsg = new byte[readLen]; 108 testLabelUpdateMsg = new byte[readLen];
109 buf.readBytes(testLabelUpdateMsg, 0, readLen); 109 buf.readBytes(testLabelUpdateMsg, 0, readLen);
110 110
111 - Assert.assertArrayEquals("PcepLabelUpdate messages are not equal", labelUpdate, testLabelUpdateMsg); 111 + assertThat(testLabelUpdateMsg, is(labelUpdate));
112 } 112 }
113 113
114 /** 114 /**
115 * This test case checks for 115 * This test case checks for
116 * <pce-label-map> SRP, LABEL, FEC Object. 116 * <pce-label-map> SRP, LABEL, FEC Object.
117 * in PcepLabelUpdate message. 117 * in PcepLabelUpdate message.
118 - *
119 - * @throws PcepParseException while parsing PCEP message
120 */ 118 */
121 @Test 119 @Test
122 public void labelUpdateMessageTest3() throws PcepParseException { 120 public void labelUpdateMessageTest3() throws PcepParseException {
123 121
124 - byte[] labelUpdate = new byte[] {0x20, 0x0D, 0x00, 0x24, // common header 122 + byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x24, // common header
125 0x21, 0x10, 0x00, 0x0C, // SRP Object Header 123 0x21, 0x10, 0x00, 0x0C, // SRP Object Header
126 0x00, 0x00, 0x00, 0x00, 124 0x00, 0x00, 0x00, 0x00,
127 0x00, 0x00, 0x00, 0x10, 125 0x00, 0x00, 0x00, 0x10,
...@@ -140,28 +138,26 @@ public class PcepLabelUpdateMsgTest { ...@@ -140,28 +138,26 @@ public class PcepLabelUpdateMsgTest {
140 message = reader.readFrom(buffer); 138 message = reader.readFrom(buffer);
141 139
142 byte[] testLabelUpdateMsg = {0}; 140 byte[] testLabelUpdateMsg = {0};
143 - Assert.assertTrue("PcepMessage is not instance of PcepLabelUpdate", message instanceof PcepLabelUpdateMsg); 141 + assertThat(message, instanceOf(PcepLabelUpdateMsg.class));
144 ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 142 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
145 message.writeTo(buf); 143 message.writeTo(buf);
146 144
147 - int readLen = buf.writerIndex() - 0; 145 + int readLen = buf.writerIndex();
148 testLabelUpdateMsg = new byte[readLen]; 146 testLabelUpdateMsg = new byte[readLen];
149 buf.readBytes(testLabelUpdateMsg, 0, readLen); 147 buf.readBytes(testLabelUpdateMsg, 0, readLen);
150 148
151 - Assert.assertArrayEquals("PcepLabelUpdate messages are not equal", labelUpdate, testLabelUpdateMsg); 149 + assertThat(testLabelUpdateMsg, is(labelUpdate));
152 } 150 }
153 151
154 /** 152 /**
155 * This test case checks for 153 * This test case checks for
156 * <pce-label-download> SRP, LSP, LABEL, LABEL, <pce-label-download> SRP, LSP, LABEL 154 * <pce-label-download> SRP, LSP, LABEL, LABEL, <pce-label-download> SRP, LSP, LABEL
157 * in PcepLabelUpdate message. 155 * in PcepLabelUpdate message.
158 - *
159 - * @throws PcepParseException while parsing PCEP message
160 */ 156 */
161 @Test 157 @Test
162 public void labelUpdateMessageTest4() throws PcepParseException { 158 public void labelUpdateMessageTest4() throws PcepParseException {
163 159
164 - byte[] labelUpdate = new byte[] {0x20, 0x0D, 0x00, 0x50, // common header 160 + byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x50, // common header
165 0x21, 0x10, 0x00, 0x0C, // SRP Object Header 161 0x21, 0x10, 0x00, 0x0C, // SRP Object Header
166 0x00, 0x00, 0x00, 0x00, 162 0x00, 0x00, 0x00, 0x00,
167 0x00, 0x00, 0x00, 0x10, 163 0x00, 0x00, 0x00, 0x10,
...@@ -191,28 +187,26 @@ public class PcepLabelUpdateMsgTest { ...@@ -191,28 +187,26 @@ public class PcepLabelUpdateMsgTest {
191 message = reader.readFrom(buffer); 187 message = reader.readFrom(buffer);
192 188
193 byte[] testLabelUpdateMsg = {0}; 189 byte[] testLabelUpdateMsg = {0};
194 - Assert.assertTrue("PcepMessage is not instance of PcepLabelUpdate", message instanceof PcepLabelUpdateMsg); 190 + assertThat(message, instanceOf(PcepLabelUpdateMsg.class));
195 ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 191 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
196 message.writeTo(buf); 192 message.writeTo(buf);
197 193
198 - int readLen = buf.writerIndex() - 0; 194 + int readLen = buf.writerIndex();
199 testLabelUpdateMsg = new byte[readLen]; 195 testLabelUpdateMsg = new byte[readLen];
200 buf.readBytes(testLabelUpdateMsg, 0, readLen); 196 buf.readBytes(testLabelUpdateMsg, 0, readLen);
201 197
202 - Assert.assertArrayEquals("PcepLabelUpdate messages are not equal", labelUpdate, testLabelUpdateMsg); 198 + assertThat(testLabelUpdateMsg, is(labelUpdate));
203 } 199 }
204 200
205 /** 201 /**
206 * This test case checks for 202 * This test case checks for
207 * <pce-label-map> SRP, LABEL, FEC, <pce-label-map> SRP, LABEL, FEC. 203 * <pce-label-map> SRP, LABEL, FEC, <pce-label-map> SRP, LABEL, FEC.
208 * in PcepLabelUpdate message. 204 * in PcepLabelUpdate message.
209 - *
210 - * @throws PcepParseException while parsing PCEP message
211 */ 205 */
212 @Test 206 @Test
213 public void labelUpdateMessageTest5() throws PcepParseException { 207 public void labelUpdateMessageTest5() throws PcepParseException {
214 208
215 - byte[] labelUpdate = new byte[] {0x20, 0x0D, 0x00, 0x44, // common header 209 + byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x44, // common header
216 0x21, 0x10, 0x00, 0x0C, // SRP Object Header 210 0x21, 0x10, 0x00, 0x0C, // SRP Object Header
217 0x00, 0x00, 0x00, 0x00, 211 0x00, 0x00, 0x00, 0x00,
218 0x00, 0x00, 0x00, 0x10, 212 0x00, 0x00, 0x00, 0x10,
...@@ -239,28 +233,26 @@ public class PcepLabelUpdateMsgTest { ...@@ -239,28 +233,26 @@ public class PcepLabelUpdateMsgTest {
239 message = reader.readFrom(buffer); 233 message = reader.readFrom(buffer);
240 234
241 byte[] testLabelUpdateMsg = {0}; 235 byte[] testLabelUpdateMsg = {0};
242 - Assert.assertTrue("PcepMessage is not instance of PcepLabelUpdate", message instanceof PcepLabelUpdateMsg); 236 + assertThat(message, instanceOf(PcepLabelUpdateMsg.class));
243 ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 237 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
244 message.writeTo(buf); 238 message.writeTo(buf);
245 239
246 - int readLen = buf.writerIndex() - 0; 240 + int readLen = buf.writerIndex();
247 testLabelUpdateMsg = new byte[readLen]; 241 testLabelUpdateMsg = new byte[readLen];
248 buf.readBytes(testLabelUpdateMsg, 0, readLen); 242 buf.readBytes(testLabelUpdateMsg, 0, readLen);
249 243
250 - Assert.assertArrayEquals("PcepLabelUpdate messages are not equal", labelUpdate, testLabelUpdateMsg); 244 + assertThat(testLabelUpdateMsg, is(labelUpdate));
251 } 245 }
252 246
253 /** 247 /**
254 * This test case checks for 248 * This test case checks for
255 * <pce-label-download> SRP, LSP, LABEL, LABEL, <pce-label-download> SRP, LABEL, FEC. 249 * <pce-label-download> SRP, LSP, LABEL, LABEL, <pce-label-download> SRP, LABEL, FEC.
256 * in PcepLabelUpdate message. 250 * in PcepLabelUpdate message.
257 - *
258 - * @throws PcepParseException while parsing PCEP message
259 */ 251 */
260 @Test 252 @Test
261 public void labelUpdateMessageTest6() throws PcepParseException { 253 public void labelUpdateMessageTest6() throws PcepParseException {
262 254
263 - byte[] labelUpdate = new byte[] {0x20, 0x0D, 0x00, 0x50, // common header 255 + byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x50, // common header
264 0x21, 0x10, 0x00, 0x0C, // SRP Object Header 256 0x21, 0x10, 0x00, 0x0C, // SRP Object Header
265 0x00, 0x00, 0x00, 0x00, 257 0x00, 0x00, 0x00, 0x00,
266 0x00, 0x00, 0x00, 0x10, 258 0x00, 0x00, 0x00, 0x10,
...@@ -290,28 +282,26 @@ public class PcepLabelUpdateMsgTest { ...@@ -290,28 +282,26 @@ public class PcepLabelUpdateMsgTest {
290 message = reader.readFrom(buffer); 282 message = reader.readFrom(buffer);
291 283
292 byte[] testLabelUpdateMsg = {0}; 284 byte[] testLabelUpdateMsg = {0};
293 - Assert.assertTrue("PcepMessage is not instance of PcepLabelUpdate", message instanceof PcepLabelUpdateMsg); 285 + assertThat(message, instanceOf(PcepLabelUpdateMsg.class));
294 ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 286 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
295 message.writeTo(buf); 287 message.writeTo(buf);
296 288
297 - int readLen = buf.writerIndex() - 0; 289 + int readLen = buf.writerIndex();
298 testLabelUpdateMsg = new byte[readLen]; 290 testLabelUpdateMsg = new byte[readLen];
299 buf.readBytes(testLabelUpdateMsg, 0, readLen); 291 buf.readBytes(testLabelUpdateMsg, 0, readLen);
300 292
301 - Assert.assertArrayEquals("PcepLabelUpdate messages are not equal", labelUpdate, testLabelUpdateMsg); 293 + assertThat(testLabelUpdateMsg, is(labelUpdate));
302 } 294 }
303 295
304 /** 296 /**
305 * This test case checks for 297 * This test case checks for
306 - * <pce-label-download> SRP, LABEL, FEC, <pce-label-download> SRP, LSP, LABEL, LABEL. 298 + * <pce-label-download> SRP, LABEL, FEC, <pce-label-download> SRP, LSP, LABEL, LABEL.
307 * in PcepLabelUpdate message. 299 * in PcepLabelUpdate message.
308 - *
309 - * @throws PcepParseException while parsing PCEP message
310 */ 300 */
311 @Test 301 @Test
312 public void labelUpdateMessageTest7() throws PcepParseException { 302 public void labelUpdateMessageTest7() throws PcepParseException {
313 303
314 - byte[] labelUpdate = new byte[] {0x20, 0x0D, 0x00, 0x50, // common header 304 + byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x50, // common header
315 0x21, 0x10, 0x00, 0x0C, // SRP Object Header 305 0x21, 0x10, 0x00, 0x0C, // SRP Object Header
316 0x00, 0x00, 0x00, 0x00, 306 0x00, 0x00, 0x00, 0x00,
317 0x00, 0x00, 0x00, 0x12, 307 0x00, 0x00, 0x00, 0x12,
...@@ -341,15 +331,15 @@ public class PcepLabelUpdateMsgTest { ...@@ -341,15 +331,15 @@ public class PcepLabelUpdateMsgTest {
341 message = reader.readFrom(buffer); 331 message = reader.readFrom(buffer);
342 332
343 byte[] testLabelUpdateMsg = {0}; 333 byte[] testLabelUpdateMsg = {0};
344 - Assert.assertTrue("PcepMessage is not instance of PcepLabelUpdate", message instanceof PcepLabelUpdateMsg); 334 + assertThat(message, instanceOf(PcepLabelUpdateMsg.class));
345 ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 335 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
346 message.writeTo(buf); 336 message.writeTo(buf);
347 337
348 - int readLen = buf.writerIndex() - 0; 338 + int readLen = buf.writerIndex();
349 testLabelUpdateMsg = new byte[readLen]; 339 testLabelUpdateMsg = new byte[readLen];
350 buf.readBytes(testLabelUpdateMsg, 0, readLen); 340 buf.readBytes(testLabelUpdateMsg, 0, readLen);
351 341
352 - Assert.assertArrayEquals("PcepLabelUpdate messages are not equal", labelUpdate, testLabelUpdateMsg); 342 + assertThat(testLabelUpdateMsg, is(labelUpdate));
353 } 343 }
354 344
355 /** 345 /**
...@@ -357,13 +347,11 @@ public class PcepLabelUpdateMsgTest { ...@@ -357,13 +347,11 @@ public class PcepLabelUpdateMsgTest {
357 * <pce-label-download> SRP, LABEL, FEC, <pce-label-download> SRP, LSP, LABEL, LABEL. 347 * <pce-label-download> SRP, LABEL, FEC, <pce-label-download> SRP, LSP, LABEL, LABEL.
358 * <pce-label-download> SRP, LSP, LABEL, LABEL. 348 * <pce-label-download> SRP, LSP, LABEL, LABEL.
359 * in PcepLabelUpdate message. 349 * in PcepLabelUpdate message.
360 - *
361 - * @throws PcepParseException while parsing PCEP message
362 */ 350 */
363 @Test 351 @Test
364 public void labelUpdateMessageTest8() throws PcepParseException { 352 public void labelUpdateMessageTest8() throws PcepParseException {
365 353
366 - byte[] labelUpdate = new byte[] {0x20, 0x0D, 0x00, 0x7C, // common header 354 + byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x7C, // common header
367 0x21, 0x10, 0x00, 0x0C, // SRP Object Header 355 0x21, 0x10, 0x00, 0x0C, // SRP Object Header
368 0x00, 0x00, 0x00, 0x00, 356 0x00, 0x00, 0x00, 0x00,
369 0x00, 0x00, 0x00, 0x12, 357 0x00, 0x00, 0x00, 0x12,
...@@ -405,14 +393,14 @@ public class PcepLabelUpdateMsgTest { ...@@ -405,14 +393,14 @@ public class PcepLabelUpdateMsgTest {
405 393
406 byte[] testLabelUpdateMsg = {0}; 394 byte[] testLabelUpdateMsg = {0};
407 395
408 - Assert.assertTrue("PcepMessage is not instance of PcepLabelUpdate", message instanceof PcepLabelUpdateMsg); 396 + assertThat(message, instanceOf(PcepLabelUpdateMsg.class));
409 ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 397 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
410 message.writeTo(buf); 398 message.writeTo(buf);
411 399
412 - int readLen = buf.writerIndex() - 0; 400 + int readLen = buf.writerIndex();
413 testLabelUpdateMsg = new byte[readLen]; 401 testLabelUpdateMsg = new byte[readLen];
414 buf.readBytes(testLabelUpdateMsg, 0, readLen); 402 buf.readBytes(testLabelUpdateMsg, 0, readLen);
415 403
416 - Assert.assertArrayEquals("PcepLabelUpdate messages are not equal", labelUpdate, testLabelUpdateMsg); 404 + assertThat(testLabelUpdateMsg, is(labelUpdate));
417 } 405 }
418 } 406 }
......