BUG-730 : added null checks to tests to increase branch coverage 35/11035/2
authorDana Kutenicsova <dkutenic@cisco.com>
Thu, 11 Sep 2014 11:50:45 +0000 (13:50 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Thu, 11 Sep 2014 12:06:50 +0000 (14:06 +0200)
Change-Id: I2dc01d2c3cedc8af32f85cfc482c4466bdc6f597
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/LabelSubobjectParserTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPRROSubobjectParserTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParserTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPXROSubobjectParserTest.java
pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/UtilsTest.java
util/src/test/java/org/opendaylight/protocol/util/IPAddressesAndPrefixesTest.java

index 16227d75c25cfd6e6d3d61070faf5a4995755ad2..71f1b804c3f61a3bf25234ec0af25f7e96913bb2 100644 (file)
@@ -9,9 +9,10 @@ package org.opendaylight.protocol.pcep.impl;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.junit.Test;
 import org.opendaylight.protocol.pcep.impl.subobject.GeneralizedLabelParser;
 import org.opendaylight.protocol.pcep.impl.subobject.Type1LabelParser;
@@ -44,6 +45,20 @@ public class LabelSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeLabel(true, false, builder.build(), buff);
         assertArrayEquals(generalizedLabelBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseLabel(null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+
+        try {
+            parser.parseLabel(Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -58,6 +73,19 @@ public class LabelSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeLabel(false, true, builder.build(), buff);
         assertArrayEquals(wavebandLabelBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseLabel(null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseLabel(Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -70,5 +98,18 @@ public class LabelSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeLabel(true, true,  builder.build(), buff);
         assertArrayEquals(typeOneLabelBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseLabel(null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseLabel(Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 }
index 7633506428431a3d36712e915540cb8210be6091..1543da29d9a68855f923b4b4f096d7aeea4a6a07 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.pcep.impl;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
 import com.google.common.collect.Lists;
 import io.netty.buffer.ByteBuf;
@@ -88,6 +89,19 @@ public class PCEPEROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(ip4PrefixBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -104,6 +118,19 @@ public class PCEPEROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(ip6PrefixBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -116,6 +143,19 @@ public class PCEPEROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(asNumberBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -129,6 +169,19 @@ public class PCEPEROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(unnumberedBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -144,6 +197,19 @@ public class PCEPEROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(pathKey32Bytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -160,6 +226,19 @@ public class PCEPEROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(pathKey128Bytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -177,6 +256,19 @@ public class PCEPEROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(labelBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -194,5 +286,18 @@ public class PCEPEROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(exrsBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 }
index 057175f1e7da6bdb91a17118eca8074f16d12389..f5d277b7e0e3d49270a0c0cdd8927707d86209f2 100644 (file)
@@ -12,6 +12,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import com.google.common.collect.Lists;
 import com.google.common.primitives.UnsignedBytes;
@@ -150,9 +151,22 @@ public class PCEPObjectParserTest {
         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().build());
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -167,9 +181,22 @@ public class PCEPObjectParserTest {
         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder().build());
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -184,9 +211,22 @@ public class PCEPObjectParserTest {
         builder.setMinBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -212,9 +252,16 @@ public class PCEPObjectParserTest {
         builder.setSubobject(subs);
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null.", e.getMessage());
+        }
     }
 
     @Test
@@ -242,9 +289,22 @@ public class PCEPObjectParserTest {
         builder.setSubobject(subs);
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -276,9 +336,22 @@ public class PCEPObjectParserTest {
         builder.setSubobject(subs);
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -292,9 +365,22 @@ public class PCEPObjectParserTest {
         builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -308,9 +394,22 @@ public class PCEPObjectParserTest {
         builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -329,9 +428,22 @@ public class PCEPObjectParserTest {
                         Ipv4Util.addressForBytes(destIPBytes)).build()).build());
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -352,9 +464,22 @@ public class PCEPObjectParserTest {
                         Ipv6Util.addressForBytes(destIPBytes)).build()).build());
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -383,6 +508,19 @@ public class PCEPObjectParserTest {
         buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -419,6 +557,19 @@ public class PCEPObjectParserTest {
         buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -450,6 +601,19 @@ public class PCEPObjectParserTest {
         buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -483,6 +647,19 @@ public class PCEPObjectParserTest {
         buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -512,6 +689,19 @@ public class PCEPObjectParserTest {
         buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -558,6 +748,19 @@ public class PCEPObjectParserTest {
         buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -602,6 +805,19 @@ public class PCEPObjectParserTest {
         buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -615,9 +831,22 @@ public class PCEPObjectParserTest {
         builder.setClassType(new ClassType((short) 4));
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -639,9 +868,22 @@ public class PCEPObjectParserTest {
         builder.setSubobject(subs);
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -658,9 +900,22 @@ public class PCEPObjectParserTest {
         builder.setPathKeys(list);
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -675,9 +930,22 @@ public class PCEPObjectParserTest {
         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.of.TlvsBuilder().build());
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -695,9 +963,22 @@ public class PCEPObjectParserTest {
         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.gc.TlvsBuilder().build());
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -725,7 +1006,7 @@ public class PCEPObjectParserTest {
     @Test
     public void testLspaObjectSerializerDefence() throws IOException, PCEPDeserializerException {
         final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
-        ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
+        final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
 
         final LspaBuilder builder = new LspaBuilder();
         builder.setProcessingRule(true);
index 78dc99dc9c450b7830e56ca534aa948f88dc4660..365eb1e8fc02eaeecf65f3b1d39faab9736265ab 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.pcep.impl;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -67,6 +68,19 @@ public class PCEPRROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(ip4PrefixBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -84,6 +98,19 @@ public class PCEPRROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(ip6PrefixBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -98,6 +125,19 @@ public class PCEPRROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(unnumberedBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -112,6 +152,19 @@ public class PCEPRROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(pathKey32Bytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -127,6 +180,19 @@ public class PCEPRROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(pathKey128Bytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -145,6 +211,19 @@ public class PCEPRROSubobjectParserTest {
             final ByteBuf buff = Unpooled.buffer();
             parser.serializeSubobject(subs.build(), buff);
             assertArrayEquals(labelBytes, ByteArray.getAllBytes(buff));
+
+            try {
+                parser.parseSubobject(null);
+                fail();
+            } catch (final IllegalArgumentException e) {
+                assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+            }
+            try {
+                parser.parseSubobject(Unpooled.EMPTY_BUFFER);
+                fail();
+            } catch (final IllegalArgumentException e) {
+                assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+            }
         }
     }
 }
index e9fdd2e73fee5876a868eb2cc2a20deb5d8ce736..c35c0575b1437feb4d7b92f923e78c706878f38a 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.pcep.impl;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 
 import com.google.common.collect.Lists;
 import io.netty.buffer.ByteBuf;
@@ -97,6 +98,7 @@ public class PCEPTlvParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeTlv(tlv, buff);
         assertArrayEquals(noPathVectorBytes, ByteArray.getAllBytes(buff));
+        assertNull(parser.parseTlv(null));
     }
 
     @Test
@@ -107,6 +109,7 @@ public class PCEPTlvParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeTlv(tlv, buff);
         assertArrayEquals(overloadedBytes, ByteArray.getAllBytes(buff));
+        assertNull(parser.parseTlv(null));
     }
 
     @Test
@@ -117,6 +120,7 @@ public class PCEPTlvParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeTlv(tlv, buff);
         assertArrayEquals(reqMissingBytes, ByteArray.getAllBytes(buff));
+        assertNull(parser.parseTlv(null));
     }
 
     @Test
@@ -127,6 +131,7 @@ public class PCEPTlvParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeTlv(tlv, buff);
         assertArrayEquals(orderBytes, ByteArray.getAllBytes(buff));
+        assertNull(parser.parseTlv(null));
     }
 
     @Test
@@ -140,6 +145,7 @@ public class PCEPTlvParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeTlv(tlv, buff);
         assertArrayEquals(ofListBytes, ByteArray.getAllBytes(buff));
+        assertNull(parser.parseTlv(null));
     }
 
     @Test
@@ -149,6 +155,7 @@ public class PCEPTlvParserTest {
         final ByteBuf buff = Unpooled.buffer();
         this.vsParser.serializeTlv(tlv, buff);
         assertArrayEquals(vsTlvBytes, ByteArray.getAllBytes(buff));
+        assertNull(this.vsParser.parseTlv(null));
     }
 
     @Test
@@ -164,5 +171,6 @@ public class PCEPTlvParserTest {
         final ByteBuf buff = Unpooled.buffer(VENDOR_INFO_BYTES.length);
         parser.serializeTlv(viTlv, buff);
         assertArrayEquals(VENDOR_INFO_BYTES, ByteArray.getAllBytes(buff));
+        assertNull(parser.parseTlv(null));
     }
 }
index 264430730207d07ff31b894012cd778082b7ffd9..27096cc67363ee6d17b23393f5bb448b8761b2e2 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.pcep.impl;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
 import com.google.common.collect.Lists;
 import io.netty.buffer.ByteBuf;
@@ -96,6 +97,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success._case.success.Paths;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.PcreqMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Requests;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.SegmentComputationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.P2pBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
@@ -276,6 +278,13 @@ public class PCEPValidatorTest {
         final ByteBuf buf = Unpooled.buffer(result.readableBytes());
         parser.serializeMessage(new OpenBuilder().setOpenMessage(builder.build()).build(), buf);
         assertArrayEquals(result.array(), buf.array());
+
+        try {
+            parser.serializeMessage(new OpenBuilder().setOpenMessage(new OpenMessageBuilder().build()).build(), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Open Object must be present in Open Message.", e.getMessage());
+        }
     }
 
     @Test
@@ -302,6 +311,13 @@ public class PCEPValidatorTest {
         final ByteBuf buf = Unpooled.buffer(result.readableBytes());
         parser.serializeMessage(builder.build(), buf);
         assertArrayEquals(result.array(), buf.array());
+
+        try {
+            parser.serializeMessage(new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().build()).build(), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Close Object must be present in Close Message.", e.getMessage());
+        }
     }
 
     @Test
@@ -345,6 +361,19 @@ public class PCEPValidatorTest {
         buf = Unpooled.buffer(result.readableBytes());
         parser.serializeMessage(new PcreqBuilder().setPcreqMessage(builder.build()).build(), buf);
         assertArrayEquals(result.array(), buf.array());
+
+        try {
+            parser.serializeMessage(new PcreqBuilder().setPcreqMessage(new PcreqMessageBuilder().build()).build(), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Requests cannot be null or empty.", e.getMessage());
+        }
+        try {
+            parser.serializeMessage(new PcreqBuilder().setPcreqMessage(new PcreqMessageBuilder().setRequests(Collections.<Requests> emptyList()).build()).build(), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Requests cannot be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -424,6 +453,19 @@ public class PCEPValidatorTest {
         buf = Unpooled.buffer(result.readableBytes());
         parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
         assertArrayEquals(result.array(), buf.array());
+
+        try {
+            parser.serializeMessage(new PcrepBuilder().setPcrepMessage(new PcrepMessageBuilder().build()).build(), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Replies cannot be null or empty.", e.getMessage());
+        }
+        try {
+            parser.serializeMessage(new PcrepBuilder().setPcrepMessage(new PcrepMessageBuilder().setReplies(Collections.<Replies> emptyList()).build()).build(), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Replies cannot be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -511,6 +553,19 @@ public class PCEPValidatorTest {
         buf = Unpooled.buffer(result.readableBytes());
         parser.serializeMessage(new PcerrBuilder().setPcerrMessage(builder.build()).build(), buf);
         assertArrayEquals(result.array(), buf.array());
+
+        try {
+            parser.serializeMessage(new PcerrBuilder().setPcerrMessage(new PcerrMessageBuilder().build()).build(), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Errors should not be empty.", e.getMessage());
+        }
+        try {
+            parser.serializeMessage(new PcerrBuilder().setPcerrMessage(new PcerrMessageBuilder().setErrors(Collections.<Errors> emptyList()).build()).build(), null);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Errors should not be empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -533,7 +588,7 @@ public class PCEPValidatorTest {
 
         assertEquals(new PcreqBuilder().setPcreqMessage(builder.build()).build(), parser.parseMessage(result.slice(4,
             result.readableBytes() - 4), Collections.<Message> emptyList()));
-        ByteBuf buf = Unpooled.buffer(result.readableBytes());
+        final ByteBuf buf = Unpooled.buffer(result.readableBytes());
         parser.serializeMessage(new PcreqBuilder().setPcreqMessage(builder.build()).build(), buf);
 
         assertArrayEquals(result.array(), buf.array());
index de553ec8d4e868fe8a411899e4db660472865740..a69e84ac8e7b58d41d1046470a0565e25adc5487 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.pcep.impl;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -71,6 +72,19 @@ public class PCEPXROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(ip4PrefixBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -88,6 +102,19 @@ public class PCEPXROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(ip6PrefixBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -101,6 +128,19 @@ public class PCEPXROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(srlgBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -115,6 +155,19 @@ public class PCEPXROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(unnumberedBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -127,6 +180,19 @@ public class PCEPXROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(asNumberBytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -142,6 +208,19 @@ public class PCEPXROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(pathKey32Bytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 
     @Test
@@ -158,5 +237,18 @@ public class PCEPXROSubobjectParserTest {
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeSubobject(subs.build(), buff);
         assertArrayEquals(pathKey128Bytes, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
     }
 }
index ad05acf8623b92dd967928e3e45ccdfa4f9f4ae7..96c2de0c5d04b3eb05543592f91bd00b907d05e1 100644 (file)
@@ -22,45 +22,54 @@ public class UtilsTest {
 
     @Test
     public void testLabelUtil() {
-        byte[] expected = { (byte) 0x81, 0x04, 0x01, 0x02, 0x03, 0x04 };
-        ByteBuf out = Unpooled.buffer();
-        ByteBuf body = Unpooled.copiedBuffer(new byte[] { 1, 2, 3, 4 });
+        final byte[] expected = { (byte) 0x81, 0x04, 0x01, 0x02, 0x03, 0x04 };
+        final ByteBuf out = Unpooled.buffer();
+        final ByteBuf body = Unpooled.copiedBuffer(new byte[] { 1, 2, 3, 4 });
         LabelUtil.formatLabel(4, true, true, body, out);
-        assertArrayEquals(expected, ByteArray.getAllBytes(out));
+        assertArrayEquals(expected, ByteArray.readAllBytes(out));
+
+        final byte[] ex = { 0, 0x05, 0x01, 0x02, 0x03, 0x04 };
+        body.resetReaderIndex();
+        LabelUtil.formatLabel(5, null, null, body, out);
+        assertArrayEquals(ex, ByteArray.getAllBytes(out));
     }
 
     @Test
     public void testMessageUtil() {
-        byte[] expected = { (byte) 0x20, 0x08, 0, 0x0a, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
-        ByteBuf out = Unpooled.buffer();
-        ByteBuf body = Unpooled.copiedBuffer(new byte[] { 1, 2, 3, 4, 5, 6 });
+        final byte[] expected = { (byte) 0x20, 0x08, 0, 0x0a, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+        final ByteBuf out = Unpooled.buffer();
+        final ByteBuf body = Unpooled.copiedBuffer(new byte[] { 1, 2, 3, 4, 5, 6 });
         MessageUtil.formatMessage(8, body, out);
         assertArrayEquals(expected, ByteArray.getAllBytes(out));
     }
 
     @Test
     public void testObjectUtil() {
-        byte[] expected = { 0x08, 0x13, 0, 0x06, 0x01, 0x02 };
-        ByteBuf out = Unpooled.buffer();
-        ByteBuf body = Unpooled.copiedBuffer(new byte[] { 1, 2 });
+        final byte[] expected = { 0x08, 0x13, 0, 0x06, 0x01, 0x02 };
+        final ByteBuf out = Unpooled.buffer();
+        final ByteBuf body = Unpooled.copiedBuffer(new byte[] { 1, 2 });
         ObjectUtil.formatSubobject(1, 8, true, true, body, out);
         assertArrayEquals(expected, ByteArray.getAllBytes(out));
     }
 
     @Test
     public void testObjectUtilFalse() {
-        byte[] expected = { 0x08, 0x10, 0, 0x06, 0x01, 0x02 };
-        ByteBuf out = Unpooled.buffer();
+        final byte[] expected = { 0x08, 0x10, 0, 0x06, 0x01, 0x02 };
+        final ByteBuf out = Unpooled.buffer();
         ByteBuf body = Unpooled.copiedBuffer(new byte[] { 1, 2 });
         ObjectUtil.formatSubobject(1, 8, false, false, body, out);
+        assertArrayEquals(expected, ByteArray.readAllBytes(out));
+
+        body = Unpooled.copiedBuffer(new byte[] { 1, 2 });
+        ObjectUtil.formatSubobject(1, 8, null, null, body, out);
         assertArrayEquals(expected, ByteArray.getAllBytes(out));
     }
 
     @Test
     public void testXROSubobjectUtil() {
         byte[] expected = { (byte) 0x82, 6, 0, 1, 2, 3 };
-        ByteBuf out = Unpooled.buffer();
-        ByteBuf body = Unpooled.copiedBuffer(new byte[] { 0, 1, 2, 3 });
+        final ByteBuf out = Unpooled.buffer();
+        final ByteBuf body = Unpooled.copiedBuffer(new byte[] { 0, 1, 2, 3 });
         body.markReaderIndex();
         XROSubobjectUtil.formatSubobject(2, true, body, out);
         assertArrayEquals(expected, ByteArray.getAllBytes(out));
@@ -70,12 +79,17 @@ public class UtilsTest {
         body.resetReaderIndex();
         XROSubobjectUtil.formatSubobject(2, false, body, out);
         assertArrayEquals(expected, ByteArray.getAllBytes(out));
+
+        out.clear();
+        body.resetReaderIndex();
+        XROSubobjectUtil.formatSubobject(2, null, body, out);
+        assertArrayEquals(expected, ByteArray.getAllBytes(out));
     }
 
     @Test
     public void testTlvUtil() {
         byte[] expected = { 0, 4, 0, 4, 1, 2, 3, 4 };
-        ByteBuf out = Unpooled.buffer();
+        final ByteBuf out = Unpooled.buffer();
         ByteBuf body = Unpooled.copiedBuffer(new byte[] { 1, 2, 3, 4 });
         TlvUtil.formatTlv(4, body, out);
         assertArrayEquals(expected, ByteArray.getAllBytes(out));
@@ -89,9 +103,9 @@ public class UtilsTest {
 
     @Test
     public void testRROSubobjectUtil() {
-        byte[] expected = { 4, 6, 1, 2, 3, 4 };
-        ByteBuf out = Unpooled.buffer();
-        ByteBuf body = Unpooled.copiedBuffer(new byte[] { 1, 2, 3, 4 });
+        final byte[] expected = { 4, 6, 1, 2, 3, 4 };
+        final ByteBuf out = Unpooled.buffer();
+        final ByteBuf body = Unpooled.copiedBuffer(new byte[] { 1, 2, 3, 4 });
         RROSubobjectUtil.formatSubobject(4, body, out);
         assertArrayEquals(expected, ByteArray.getAllBytes(out));
     }
@@ -99,8 +113,8 @@ public class UtilsTest {
     @Test
     public void testEROSubobjectUtil() {
         byte[] expected = { (byte) 0x82, 6, 0, 1, 2, 3 };
-        ByteBuf out = Unpooled.buffer();
-        ByteBuf body = Unpooled.copiedBuffer(new byte[] { 0, 1, 2, 3 });
+        final ByteBuf out = Unpooled.buffer();
+        final ByteBuf body = Unpooled.copiedBuffer(new byte[] { 0, 1, 2, 3 });
         body.markReaderIndex();
         EROSubobjectUtil.formatSubobject(2, true, body, out);
         assertArrayEquals(expected, ByteArray.getAllBytes(out));
@@ -129,7 +143,7 @@ public class UtilsTest {
         c.setAccessible(true);
         try {
             c.newInstance();
-        } catch (InvocationTargetException e) {
+        } catch (final InvocationTargetException e) {
             throw e.getCause();
         }
     }
@@ -140,7 +154,7 @@ public class UtilsTest {
         c.setAccessible(true);
         try {
             c.newInstance();
-        } catch (InvocationTargetException e) {
+        } catch (final InvocationTargetException e) {
             throw e.getCause();
         }
     }
@@ -151,7 +165,7 @@ public class UtilsTest {
         c.setAccessible(true);
         try {
             c.newInstance();
-        } catch (InvocationTargetException e) {
+        } catch (final InvocationTargetException e) {
             throw e.getCause();
         }
     }
@@ -162,7 +176,7 @@ public class UtilsTest {
         c.setAccessible(true);
         try {
             c.newInstance();
-        } catch (InvocationTargetException e) {
+        } catch (final InvocationTargetException e) {
             throw e.getCause();
         }
     }
@@ -173,7 +187,7 @@ public class UtilsTest {
         c.setAccessible(true);
         try {
             c.newInstance();
-        } catch (InvocationTargetException e) {
+        } catch (final InvocationTargetException e) {
             throw e.getCause();
         }
     }
@@ -184,7 +198,7 @@ public class UtilsTest {
         c.setAccessible(true);
         try {
             c.newInstance();
-        } catch (InvocationTargetException e) {
+        } catch (final InvocationTargetException e) {
             throw e.getCause();
         }
     }
@@ -195,7 +209,7 @@ public class UtilsTest {
         c.setAccessible(true);
         try {
             c.newInstance();
-        } catch (InvocationTargetException e) {
+        } catch (final InvocationTargetException e) {
             throw e.getCause();
         }
     }
@@ -206,7 +220,7 @@ public class UtilsTest {
         c.setAccessible(true);
         try {
             c.newInstance();
-        } catch (InvocationTargetException e) {
+        } catch (final InvocationTargetException e) {
             throw e.getCause();
         }
     }
@@ -217,7 +231,7 @@ public class UtilsTest {
         c.setAccessible(true);
         try {
             c.newInstance();
-        } catch (InvocationTargetException e) {
+        } catch (final InvocationTargetException e) {
             throw e.getCause();
         }
     }
index 95cca2e26d937fc1abc6f4ae544604e211dba7cf..c45108985d5c30feaf2aea67f28a5b93a8824db1 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.protocol.util;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import com.google.common.collect.Lists;
@@ -56,6 +58,13 @@ public class IPAddressesAndPrefixesTest {
         assertEquals(new Ipv4Prefix("255.255.0.0/16"), Ipv4Util.prefixForBytes(bytes, 16));
 
         assertArrayEquals(new byte[] { (byte) 255, (byte) 255, 0, 0, 16 }, Ipv4Util.bytesForPrefix(new Ipv4Prefix("255.255.0.0/16")));
+
+        try {
+            Ipv4Util.prefixForBytes(bytes, 200);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertNull(e.getMessage());
+        }
     }
 
     @Test
@@ -115,6 +124,13 @@ public class IPAddressesAndPrefixesTest {
         assertEquals(new Ipv6Prefix("2001:db8:1:2::/64"), Ipv6Util.prefixForBytes(bytes, 64));
         assertArrayEquals(new byte[] { 0x20, (byte) 0x01, 0x0d, (byte) 0xb8, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             0x00, 0x00, 0x40 }, Ipv6Util.bytesForPrefix(new Ipv6Prefix("2001:db8:1:2::/64")));
+
+        try {
+            Ipv6Util.prefixForBytes(bytes, 200);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertNull(e.getMessage());
+        }
     }
 
     @Test
@@ -133,18 +149,24 @@ public class IPAddressesAndPrefixesTest {
     @Test
     public void testPrefixList4ForBytes() {
         final byte[] bytes = new byte[] { 22, (byte) 172, (byte) 168, 3, 8, 12, 32, (byte) 192, (byte) 168, 35, 100 };
-        final List<Ipv4Prefix> prefs = Ipv4Util.prefixListForBytes(bytes);
+        List<Ipv4Prefix> prefs = Ipv4Util.prefixListForBytes(bytes);
         assertEquals(
             Lists.newArrayList(new Ipv4Prefix("172.168.3.0/22"), new Ipv4Prefix("12.0.0.0/8"), new Ipv4Prefix("192.168.35.100/32")),
             prefs);
+
+        prefs = Ipv4Util.prefixListForBytes(new byte[] {});
+        assertTrue(prefs.isEmpty());
     }
 
     @Test
     public void testPrefixList6ForBytes() {
         final byte[] bytes = new byte[] { 0x40, 0x20, 0x01, 0x0d, (byte) 0xb8, 0x00, 0x01, 0x00, 0x02, 0x40, 0x20, 0x01, 0x0d, (byte) 0xb8,
             0x00, 0x01, 0x00, 0x01, };
-        final List<Ipv6Prefix> prefs = Ipv6Util.prefixListForBytes(bytes);
+        List<Ipv6Prefix> prefs = Ipv6Util.prefixListForBytes(bytes);
         assertEquals(prefs, Lists.newArrayList(new Ipv6Prefix("2001:db8:1:2::/64"), new Ipv6Prefix("2001:db8:1:1::/64")));
+
+        prefs = Ipv6Util.prefixListForBytes(new byte[] {});
+        assertTrue(prefs.isEmpty());
     }
 
     @Test(expected=UnsupportedOperationException.class)
@@ -153,7 +175,7 @@ public class IPAddressesAndPrefixesTest {
         c.setAccessible(true);
         try {
             c.newInstance();
-        } catch (InvocationTargetException e) {
+        } catch (final InvocationTargetException e) {
             throw e.getCause();
         }
     }
@@ -164,7 +186,7 @@ public class IPAddressesAndPrefixesTest {
         c.setAccessible(true);
         try {
             c.newInstance();
-        } catch (InvocationTargetException e) {
+        } catch (final InvocationTargetException e) {
             throw e.getCause();
         }
     }