Example usage for io.netty.buffer Unpooled EMPTY_BUFFER

List of usage examples for io.netty.buffer Unpooled EMPTY_BUFFER

Introduction

In this page you can find the example usage for io.netty.buffer Unpooled EMPTY_BUFFER.

Prototype

ByteBuf EMPTY_BUFFER

To view the source code for io.netty.buffer Unpooled EMPTY_BUFFER.

Click Source Link

Document

A buffer whose capacity is 0 .

Usage

From source file:org.opendaylight.protocol.rsvp.parser.impl.EROSubobjectParserTest.java

License:Open Source License

@Test
public void testEROIp6PrefixSubobject() throws RSVPParsingException {
    final EROIpv6PrefixSubobjectParser parser = new EROIpv6PrefixSubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setSubobjectType(/* www . j ava  2s  . com*/
            new IpPrefixCaseBuilder()
                    .setIpPrefix(new IpPrefixBuilder()
                            .setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF,
                                    (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
                                    (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
                                    (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22)))
                            .build())
                    .build());
    subs.setLoose(false);
    assertEquals(subs.build(),
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(IP_6_PREFIX_BYTES, 2)), false));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(IP_6_PREFIX_BYTES, ByteArray.getAllBytes(buff));

    try {
        parser.parseSubobject(null, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.EROSubobjectParserTest.java

License:Open Source License

@Test
public void testEROAsNumberSubobject() throws RSVPParsingException {
    final EROAsNumberSubobjectParser parser = new EROAsNumberSubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setLoose(true);//from  w  w  w.  ja  va  2  s. c  o  m
    subs.setSubobjectType(new AsNumberCaseBuilder()
            .setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build()).build());
    assertEquals(subs.build(),
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(AS_NUMBER_BYTES, 2)), true));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(AS_NUMBER_BYTES, ByteArray.getAllBytes(buff));

    try {
        parser.parseSubobject(null, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.EROSubobjectParserTest.java

License:Open Source License

@Test
public void testEROUnnumberedSubobject() throws RSVPParsingException {
    final EROUnnumberedInterfaceSubobjectParser parser = new EROUnnumberedInterfaceSubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setLoose(true);// w  w w.j a  v a2s . c om
    subs.setSubobjectType(new UnnumberedCaseBuilder()
            .setUnnumbered(new UnnumberedBuilder().setRouterId(0x12345000L).setInterfaceId(0xffffffffL).build())
            .build());
    assertEquals(subs.build(),
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(UNNUMBERED_BYTES, 2)), true));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(UNNUMBERED_BYTES, ByteArray.getAllBytes(buff));

    try {
        parser.parseSubobject(null, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.EROSubobjectParserTest.java

License:Open Source License

@Test
public void testEROPathKey32Subobject() throws RSVPParsingException {
    final EROPathKey32SubobjectParser parser = new EROPathKey32SubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setLoose(true);/* www.  j  av  a  2s . c  om*/
    final PathKeyBuilder pBuilder = new PathKeyBuilder();
    pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 }));
    pBuilder.setPathKey(new PathKey(4660));
    subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
    assertEquals(subs.build(),
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(PATH_KEY_32_BYTES, 2)), true));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(PATH_KEY_32_BYTES, ByteArray.getAllBytes(buff));

    try {
        parser.parseSubobject(null, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.EROSubobjectParserTest.java

License:Open Source License

@Test
public void testEROPathKey128Subobject() throws RSVPParsingException {
    final EROPathKey128SubobjectParser parser128 = new EROPathKey128SubobjectParser();
    final EROPathKey32SubobjectParser parser = new EROPathKey32SubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setLoose(true);//from   www  .jav  a  2  s  .c  o m
    final PathKeyBuilder pBuilder = new PathKeyBuilder();
    pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A,
            (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
    pBuilder.setPathKey(new PathKey(4660));
    subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
    assertEquals(subs.build(),
            parser128.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(PATH_KEY_128_BYTES, 2)), true));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(PATH_KEY_128_BYTES, ByteArray.getAllBytes(buff));

    try {
        parser128.parseSubobject(null, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser128.parseSubobject(Unpooled.EMPTY_BUFFER, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.EROSubobjectParserTest.java

License:Open Source License

@Test
public void testEROLabelSubobject() throws Exception {
    final EROLabelSubobjectParser parser = new EROLabelSubobjectParser(this.ctx.getLabelHandlerRegistry());

    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setLoose(true);/*from w w w.j  a va2  s .  co  m*/
    subs.setSubobjectType(new LabelCaseBuilder().setLabel(new LabelBuilder().setUniDirectional(true)
            .setLabelType(new GeneralizedLabelCaseBuilder().setGeneralizedLabel(new GeneralizedLabelBuilder()
                    .setGeneralizedLabel(new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF })
                    .build()).build())
            .build()).build());
    assertEquals(subs.build(),
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(LABEL_BYTES, 2)), true));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(LABEL_BYTES, ByteArray.getAllBytes(buff));

    try {
        parser.parseSubobject(null, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.EROSubobjectParserTest.java

License:Open Source License

@Test
public void testEROEXRSSubobject() throws Exception {
    final EROExplicitExclusionRouteSubobjectParser parser = new EROExplicitExclusionRouteSubobjectParser(
            this.ctx.getXROSubobjectHandlerRegistry());
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setLoose(true);/*  ww  w.jav  a2s .c o  m*/
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.Exrs> list = Lists
            .newArrayList();
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.ExrsBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.ExrsBuilder();
    builder.setMandatory(true);
    builder.setSubobjectType(new AsNumberCaseBuilder()
            .setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build()).build());
    list.add(builder.build());
    subs.setSubobjectType(new ExrsCaseBuilder().setExrs(new ExrsBuilder().setExrs(list).build()).build());
    assertEquals(subs.build(),
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(EXRS_BYTES, 2)), true));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(EXRS_BYTES, ByteArray.getAllBytes(buff));

    try {
        parser.parseSubobject(null, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.LabelSubobjectParserTest.java

License:Open Source License

@Test
public void testGeneralizedLabel() throws RSVPParsingException {
    final GeneralizedLabelParser parser = new GeneralizedLabelParser();
    final GeneralizedLabelBuilder iBuilder = new GeneralizedLabelBuilder();
    iBuilder.setGeneralizedLabel(ByteArray.cutBytes(GENERALIZED_LABEL_BYTES, 2));
    final GeneralizedLabelCaseBuilder builder = new GeneralizedLabelCaseBuilder()
            .setGeneralizedLabel(iBuilder.build());
    assertEquals(builder.build(),//from w w w.  ja v a 2 s. c o  m
            parser.parseLabel(Unpooled.wrappedBuffer(ByteArray.cutBytes(GENERALIZED_LABEL_BYTES, 2))));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeLabel(true, false, builder.build(), buff);
    assertArrayEquals(GENERALIZED_LABEL_BYTES, 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());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.LabelSubobjectParserTest.java

License:Open Source License

@Test
public void testWavebandLabel() throws RSVPParsingException {
    final WavebandSwitchingLabelParser parser = new WavebandSwitchingLabelParser();
    final WavebandSwitchingLabelBuilder iBuilder = new WavebandSwitchingLabelBuilder();
    iBuilder.setWavebandId(0x1234L);/*from  w ww  . j  ava2  s  .  c o  m*/
    iBuilder.setStartLabel(0x9999L);
    iBuilder.setEndLabel(0x1111L);
    final WavebandSwitchingLabelCaseBuilder builder = new WavebandSwitchingLabelCaseBuilder()
            .setWavebandSwitchingLabel(iBuilder.build());
    assertEquals(builder.build(),
            parser.parseLabel(Unpooled.wrappedBuffer(ByteArray.cutBytes(WAVEBAND_LABEL_BYTES, 2))));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeLabel(false, true, builder.build(), buff);
    assertArrayEquals(WAVEBAND_LABEL_BYTES, 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());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.LabelSubobjectParserTest.java

License:Open Source License

@Test
public void testTypeOneLabel() throws RSVPParsingException {
    final Type1LabelParser parser = new Type1LabelParser();
    final Type1LabelBuilder iBuilder = new Type1LabelBuilder();
    iBuilder.setType1Label(0x120025ffL);
    final Type1LabelCaseBuilder builder = new Type1LabelCaseBuilder().setType1Label(iBuilder.build());
    assertEquals(builder.build(),/*w  w w  .j  av  a 2  s .  c  o  m*/
            parser.parseLabel(Unpooled.wrappedBuffer(ByteArray.cutBytes(TYPE_ONE_LABEL_BYTES, 2))));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeLabel(true, true, builder.build(), buff);
    assertArrayEquals(TYPE_ONE_LABEL_BYTES, 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());
    }
}