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;
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
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
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());
+ }
}
}
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;
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
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
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
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
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
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
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
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());
+ }
}
}
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;
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
@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);
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;
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
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
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
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
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
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());
+ }
}
}
}
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;
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(tlv, buff);
assertArrayEquals(noPathVectorBytes, ByteArray.getAllBytes(buff));
+ assertNull(parser.parseTlv(null));
}
@Test
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(tlv, buff);
assertArrayEquals(overloadedBytes, ByteArray.getAllBytes(buff));
+ assertNull(parser.parseTlv(null));
}
@Test
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(tlv, buff);
assertArrayEquals(reqMissingBytes, ByteArray.getAllBytes(buff));
+ assertNull(parser.parseTlv(null));
}
@Test
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(tlv, buff);
assertArrayEquals(orderBytes, ByteArray.getAllBytes(buff));
+ assertNull(parser.parseTlv(null));
}
@Test
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(tlv, buff);
assertArrayEquals(ofListBytes, ByteArray.getAllBytes(buff));
+ assertNull(parser.parseTlv(null));
}
@Test
final ByteBuf buff = Unpooled.buffer();
this.vsParser.serializeTlv(tlv, buff);
assertArrayEquals(vsTlvBytes, ByteArray.getAllBytes(buff));
+ assertNull(this.vsParser.parseTlv(null));
}
@Test
final ByteBuf buff = Unpooled.buffer(VENDOR_INFO_BYTES.length);
parser.serializeTlv(viTlv, buff);
assertArrayEquals(VENDOR_INFO_BYTES, ByteArray.getAllBytes(buff));
+ assertNull(parser.parseTlv(null));
}
}
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;
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;
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
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
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
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
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
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());
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;
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
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
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
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
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
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
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
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));
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));
@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));
}
@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));
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
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;
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
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
@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)
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}