Example usage for io.netty.buffer ByteBuf array

List of usage examples for io.netty.buffer ByteBuf array

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf array.

Prototype

public abstract byte[] array();

Source Link

Document

Returns the backing byte array of this buffer.

Usage

From source file:org.opendaylight.protocol.pcep.impl.PCEPValidatorTest.java

License:Open Source License

@Test
public void testMonReqMsg() throws PCEPDeserializerException, IOException {
    final PCEPMonitoringRequestMessageParser parser = new PCEPMonitoringRequestMessageParser(
            this.objectRegistry);

    final PcreqMessageBuilder builder = new PcreqMessageBuilder();
    final MonitoringRequestBuilder monReqBuilder = new MonitoringRequestBuilder();
    monReqBuilder.setMonitoring(this.monitoring);
    monReqBuilder.setPceIdList(Lists.newArrayList(new PceIdListBuilder().setPceId(this.pceId).build()));
    builder.setMonitoringRequest(monReqBuilder.build());
    final byte[] msgBytes = { 0x20, 0x08, 0x00, 0x18,
            /* monitoring object */
            0x13, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64,
            /* pce-id object */
            0x19, 0x10, 0x00, 0x08, 0x7f, 0x00, 0x00, 0x02 };
    ByteBuf result = Unpooled.wrappedBuffer(msgBytes);
    assertEquals(new PcmonreqBuilder().setPcreqMessage(builder.build()).build(),
            parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList()));
    ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcmonreqBuilder().setPcreqMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());

    result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCMonReq.bin"));
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Requests> reqs2 = Lists
            .newArrayList();/*from   w  ww .  j a v a 2s  .  c o  m*/
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder rBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder();
    rBuilder1.setRp(this.rpTrue);
    final P2pBuilder p2pBuilder = new P2pBuilder();
    p2pBuilder.setEndpointsObj(this.endpoints);
    p2pBuilder.setMetrics(Lists.newArrayList(this.metrics));
    p2pBuilder.setIro(this.iro);
    rBuilder1.setSegmentComputation(new SegmentComputationBuilder().setP2p(p2pBuilder.build()).build());
    reqs2.add(rBuilder1.build());
    builder.setRequests(reqs2);
    builder.setSvec(Lists.newArrayList(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder()
                    .setSvec(this.svec).build()));
    monReqBuilder.setMonitoring(this.monitoring);
    monReqBuilder.setPccIdReq(this.pccIdReq);
    final PceIdList pceIdList = new PceIdListBuilder().setPceId(this.pceId).build();
    monReqBuilder.setPceIdList(Lists.newArrayList(pceIdList, pceIdList));
    builder.setMonitoringRequest(monReqBuilder.build());

    assertEquals(new PcmonreqBuilder().setPcreqMessage(builder.build()).build(),
            parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList()));
    buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcmonreqBuilder().setPcreqMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());
}

From source file:org.opendaylight.protocol.pcep.pcecc.PceccLabelUpdateMessageParserTest.java

License:Open Source License

@Test
public void testPceLabelDownloadWithMultiElementList() throws IOException, PCEPDeserializerException {

    final PceccLabelUpdateMessageParser parser = new PceccLabelUpdateMessageParser(
            this.ctx.getObjectHandlerRegistry());
    final PclabelupdMessageBuilder builder = new PclabelupdMessageBuilder();
    final List<PceLabelUpdates> updates = Lists.newArrayList();
    final List<Label> labelList = Lists.newArrayList();

    PceLabelDownloadCaseBuilder pceLabelDownloadCaseBuilder = new PceLabelDownloadCaseBuilder();
    PceLabelDownloadBuilder pceLabelDownload = new PceLabelDownloadBuilder();
    final FecBuilder fecBuilder = new FecBuilder();
    fecBuilder.setProcessingRule(false);
    fecBuilder.setIgnore(false);//from www.  j  a va  2s  .  c o  m
    fecBuilder.setFec(new Ipv4NodeIdCaseBuilder().setNodeId(new Ipv4Address("255.144.0.1")).build());

    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder tlvBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder();
    AddressBuilder addressBuilder = new AddressBuilder();
    Ipv4Builder ipv4 = new Ipv4Builder();
    ipv4.setIpv4Address(new Ipv4Address("1.1.1.1")).build();
    addressBuilder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(ipv4.build()).build());

    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.pce.label.update.pce.label.update.type.pce.label.download._case.pce.label.download.LabelBuilder labelBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.pce.label.update.pce.label.update.type.pce.label.download._case.pce.label.download.LabelBuilder();
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.LabelBuilder label1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.LabelBuilder();
    label1.setOutLabel(false);
    label1.setIgnore(false);
    label1.setProcessingRule(false);
    label1.setLabelNum(new LabelNumber(5001L));
    label1.setTlvs(tlvBuilder.setAddress(addressBuilder.build()).build());

    labelBuilder.setLabel(label1.build());

    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder tlvBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder();
    AddressBuilder addressBuilder1 = new AddressBuilder();
    Ipv4Builder ipv41 = new Ipv4Builder();
    ipv41.setIpv4Address(new Ipv4Address("14.10.1.29")).build();
    addressBuilder1.setAddressFamily(new Ipv4CaseBuilder().setIpv4(ipv41.build()).build());

    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.pce.label.update.pce.label.update.type.pce.label.download._case.pce.label.download.LabelBuilder labelBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.pce.label.update.pce.label.update.type.pce.label.download._case.pce.label.download.LabelBuilder();
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.LabelBuilder label2 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.LabelBuilder();
    label2.setOutLabel(true);
    label2.setIgnore(false);
    label2.setProcessingRule(false);
    label2.setLabelNum(new LabelNumber(5001L));
    label2.setTlvs(tlvBuilder1.setAddress(addressBuilder1.build()).build());

    labelBuilder1.setLabel(label2.build());

    labelList.add(labelBuilder.build());
    labelList.add(labelBuilder1.build());
    final SrpBuilder srpBuilder = new SrpBuilder();
    srpBuilder.setIgnore(false);
    srpBuilder.setProcessingRule(false);
    srpBuilder.setOperationId(new SrpIdNumber(1L));

    srpBuilder.setTlvs(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder()
                    .build());

    final LspBuilder lspBuilder = new LspBuilder();
    lspBuilder.setIgnore(false);
    lspBuilder.setProcessingRule(false);
    lspBuilder.setAdministrative(false);
    lspBuilder.setDelegate(false);
    lspBuilder.setPlspId(new PlspId(0L));
    lspBuilder.setOperational(OperationalStatus.Down);
    lspBuilder.setSync(false);
    lspBuilder.setRemove(false);
    lspBuilder.setTlvs(new TlvsBuilder().build());

    pceLabelDownload.setLabel(labelList).build();
    pceLabelDownload.setSrp(srpBuilder.build()).build();
    pceLabelDownload.setLsp(lspBuilder.build());
    pceLabelDownloadCaseBuilder.setPceLabelDownload(pceLabelDownload.build()).build();

    updates.add(
            new PceLabelUpdatesBuilder().setPceLabelUpdateType(pceLabelDownloadCaseBuilder.build()).build());
    builder.setPceLabelUpdates(updates);

    ByteBuf result = Unpooled.wrappedBuffer(PceccLabelDownloadWithMultiElementList);

    assertEquals(new PclabelupdBuilder().setPclabelupdMessage(builder.build()).build(),
            parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList()));
    ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PclabelupdBuilder().setPclabelupdMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());

}

From source file:org.opendaylight.protocol.pcep.pcecc.PceccLabelUpdateMessageParserTest.java

License:Open Source License

@Test
public void testPceLabelDownloadWithSingleElementList() throws IOException, PCEPDeserializerException {

    final PceccLabelUpdateMessageParser parser = new PceccLabelUpdateMessageParser(
            this.ctx.getObjectHandlerRegistry());
    final PclabelupdMessageBuilder builder = new PclabelupdMessageBuilder();
    final List<PceLabelUpdates> updates = Lists.newArrayList();
    final List<Label> labelList = Lists.newArrayList();

    PceLabelDownloadCaseBuilder pceLabelDownloadCaseBuilder = new PceLabelDownloadCaseBuilder();
    PceLabelDownloadBuilder pceLabelDownload = new PceLabelDownloadBuilder();
    final FecBuilder fecBuilder = new FecBuilder();
    fecBuilder.setProcessingRule(false);
    fecBuilder.setIgnore(false);/*from  w w  w . ja  va 2s  . c  o  m*/
    fecBuilder.setFec(new Ipv4NodeIdCaseBuilder().setNodeId(new Ipv4Address("255.144.0.1")).build());

    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder tlvBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder();
    AddressBuilder addressBuilder = new AddressBuilder();
    Ipv4Builder ipv4 = new Ipv4Builder();
    ipv4.setIpv4Address(new Ipv4Address("1.1.1.1")).build();
    addressBuilder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(ipv4.build()).build());

    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.pce.label.update.pce.label.update.type.pce.label.download._case.pce.label.download.LabelBuilder labelBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.pce.label.update.pce.label.update.type.pce.label.download._case.pce.label.download.LabelBuilder();
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.LabelBuilder label1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.LabelBuilder();
    label1.setOutLabel(false);
    label1.setIgnore(false);
    label1.setProcessingRule(false);
    label1.setLabelNum(new LabelNumber(5001L));
    label1.setTlvs(tlvBuilder.setAddress(addressBuilder.build()).build());

    labelBuilder.setLabel(label1.build());

    labelList.add(labelBuilder.build());
    final SrpBuilder srpBuilder = new SrpBuilder();
    srpBuilder.setIgnore(false);
    srpBuilder.setProcessingRule(false);
    srpBuilder.setOperationId(new SrpIdNumber(1L));

    srpBuilder.setTlvs(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder()
                    .build());

    final LspBuilder lspBuilder = new LspBuilder();
    lspBuilder.setIgnore(false);
    lspBuilder.setProcessingRule(false);
    lspBuilder.setAdministrative(false);
    lspBuilder.setDelegate(false);
    lspBuilder.setPlspId(new PlspId(0L));
    lspBuilder.setOperational(OperationalStatus.Down);
    lspBuilder.setSync(false);
    lspBuilder.setRemove(false);
    lspBuilder.setTlvs(new TlvsBuilder().build());

    pceLabelDownload.setLabel(labelList).build();
    pceLabelDownload.setSrp(srpBuilder.build()).build();
    pceLabelDownload.setLsp(lspBuilder.build());
    pceLabelDownloadCaseBuilder.setPceLabelDownload(pceLabelDownload.build()).build();

    updates.add(
            new PceLabelUpdatesBuilder().setPceLabelUpdateType(pceLabelDownloadCaseBuilder.build()).build());
    builder.setPceLabelUpdates(updates);

    ByteBuf result = Unpooled.wrappedBuffer(PceccLabelDownloadWithSingleElementList);

    assertEquals(new PclabelupdBuilder().setPclabelupdMessage(builder.build()).build(),
            parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList()));
    ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PclabelupdBuilder().setPclabelupdMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());

}

From source file:org.opendaylight.protocol.pcep.pcecc.PceccLabelUpdateMessageParserTest.java

License:Open Source License

@Test
public void testPceLabelMapWithAddressTlv() throws IOException, PCEPDeserializerException {

    final PceccLabelUpdateMessageParser parser = new PceccLabelUpdateMessageParser(
            this.ctx.getObjectHandlerRegistry());
    final PclabelupdMessageBuilder builder = new PclabelupdMessageBuilder();
    final List<PceLabelUpdates> updates = Lists.newArrayList();
    PceLabelMapCaseBuilder pceLabelMapCaseBuilder = new PceLabelMapCaseBuilder();
    PceLabelMapBuilder pceLabelMap = new PceLabelMapBuilder();
    final FecBuilder fecBuilder = new FecBuilder();
    fecBuilder.setProcessingRule(false);
    fecBuilder.setIgnore(false);/*  ww w  .  jav a 2 s . c om*/
    fecBuilder.setFec(new Ipv4NodeIdCaseBuilder().setNodeId(new Ipv4Address("255.144.0.1")).build());

    final LabelBuilder labelBuilder = new LabelBuilder();
    labelBuilder.setProcessingRule(false);
    labelBuilder.setIgnore(false);
    labelBuilder.setLabelNum(new LabelNumber(5001L));
    labelBuilder.setOutLabel(false);

    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder tlvBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder();
    AddressBuilder addressBuilder = new AddressBuilder();
    Ipv4Builder ipv4 = new Ipv4Builder();
    ipv4.setIpv4Address(new Ipv4Address("1.1.1.1")).build();
    addressBuilder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(ipv4.build()).build());

    labelBuilder.setTlvs(tlvBuilder.setAddress(addressBuilder.build()).build());

    final SrpBuilder srpBuilder = new SrpBuilder();
    srpBuilder.setIgnore(false);
    srpBuilder.setProcessingRule(false);
    srpBuilder.setOperationId(new SrpIdNumber(1L));

    srpBuilder.setTlvs(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder()
                    .build());

    pceLabelMap.setFec(fecBuilder.build()).build();
    pceLabelMap.setLabel(labelBuilder.build()).build();
    pceLabelMap.setSrp(srpBuilder.build()).build();
    pceLabelMapCaseBuilder.setPceLabelMap(pceLabelMap.build()).build();

    updates.add(new PceLabelUpdatesBuilder().setPceLabelUpdateType(pceLabelMapCaseBuilder.build()).build());
    builder.setPceLabelUpdates(updates);

    ByteBuf result = Unpooled.wrappedBuffer(PceccLabelMapObjectWithAddressTlvBytes);

    assertEquals(new PclabelupdBuilder().setPclabelupdMessage(builder.build()).build(),
            parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList()));
    ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PclabelupdBuilder().setPclabelupdMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());

}

From source file:org.opendaylight.protocol.pcep.pcecc.PceccLabelUpdateMessageParserTest.java

License:Open Source License

@Test
public void testPceLabelMapWithoutAddressTlv() throws IOException, PCEPDeserializerException {

    final PceccLabelUpdateMessageParser parser = new PceccLabelUpdateMessageParser(
            this.ctx.getObjectHandlerRegistry());
    final PclabelupdMessageBuilder builder = new PclabelupdMessageBuilder();
    final List<PceLabelUpdates> updates = Lists.newArrayList();
    PceLabelMapCaseBuilder pceLabelMapCaseBuilder = new PceLabelMapCaseBuilder();
    PceLabelMapBuilder pceLabelMap = new PceLabelMapBuilder();
    final FecBuilder fecBuilder = new FecBuilder();
    fecBuilder.setProcessingRule(false);
    fecBuilder.setIgnore(false);//from ww w.j  a va2  s.com
    fecBuilder.setFec(new Ipv4NodeIdCaseBuilder().setNodeId(new Ipv4Address("255.144.0.1")).build());

    final LabelBuilder labelBuilder = new LabelBuilder();
    labelBuilder.setProcessingRule(false);
    labelBuilder.setIgnore(false);
    labelBuilder.setLabelNum(new LabelNumber(5001L));
    labelBuilder.setOutLabel(false);
    labelBuilder.setTlvs(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder()
                    .build());
    final SrpBuilder srpBuilder = new SrpBuilder();
    srpBuilder.setIgnore(false);
    srpBuilder.setProcessingRule(false);
    srpBuilder.setOperationId(new SrpIdNumber(1L));

    srpBuilder.setTlvs(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder()
                    .build());

    pceLabelMap.setFec(fecBuilder.build()).build();
    pceLabelMap.setLabel(labelBuilder.build()).build();
    pceLabelMap.setSrp(srpBuilder.build()).build();
    pceLabelMapCaseBuilder.setPceLabelMap(pceLabelMap.build()).build();

    updates.add(new PceLabelUpdatesBuilder().setPceLabelUpdateType(pceLabelMapCaseBuilder.build()).build());
    builder.setPceLabelUpdates(updates);

    ByteBuf result = Unpooled.wrappedBuffer(PceccLabelMapObjectWithoutAddressTlvBytes);

    assertEquals(new PclabelupdBuilder().setPclabelupdMessage(builder.build()).build(),
            parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList()));
    ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PclabelupdBuilder().setPclabelupdMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());

}

From source file:org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtilTest.java

License:Open Source License

@Test
public void testFormatSubobject1() {
    final byte[] array = new byte[] { 2, 3 };
    final byte[] expected = new byte[] { (byte) 0x81, 4, 2, 3 };
    final ByteBuf body = Unpooled.copiedBuffer(array);
    final ByteBuf aggregator = Unpooled.buffer(4);
    EROSubobjectUtil.formatSubobject(1, Boolean.TRUE, body, aggregator);
    assertArrayEquals(expected, aggregator.array());
}

From source file:org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtilTest.java

License:Open Source License

@Test
public void testFormatSubobject2() {
    final byte[] array = new byte[] { 2, 3 };
    final byte[] expected = new byte[] { 1, 4, 2, 3 };
    final ByteBuf body = Unpooled.copiedBuffer(array);
    final ByteBuf aggregator = Unpooled.buffer(4);
    EROSubobjectUtil.formatSubobject(1, Boolean.FALSE, body, aggregator);
    assertArrayEquals(expected, aggregator.array());
}

From source file:org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtilTest.java

License:Open Source License

@Test
public void testFormatSubobject3() {
    final byte[] array = new byte[] { 2, 3 };
    final byte[] expected = new byte[] { 1, 4, 2, 3 };
    final ByteBuf body = Unpooled.copiedBuffer(array);
    final ByteBuf aggregator = Unpooled.buffer(4);
    EROSubobjectUtil.formatSubobject(1, null, body, aggregator);
    assertArrayEquals(expected, aggregator.array());
}

From source file:org.opendaylight.protocol.rsvp.parser.spi.subobjects.CUISubobjectParserTest.java

License:Open Source License

@Test
public void testProcessing() {
    final ByteBuf input = Unpooled.buffer(8);
    input.writeInt(this.routerId.intValue());
    input.writeInt(this.interfaceId.intValue());
    final UnnumberedCase output = this.parser.parseUnnumeredInterface(input);
    assertEquals(this.routerId, output.getUnnumbered().getRouterId());
    assertEquals(this.interfaceId, output.getUnnumbered().getInterfaceId());

    final ByteBuf bytebuf = Unpooled.buffer(8);
    this.parser.serializeUnnumeredInterface(output.getUnnumbered(), bytebuf);
    assertArrayEquals(input.array(), bytebuf.array());
}

From source file:org.opendaylight.protocol.rsvp.parser.spi.subobjects.EROSubobjectListParserTest.java

License:Open Source License

@Test
public void testAbstractRSVPObjParser() throws RSVPParsingException {
    final ByteBuf byteAggregator = Unpooled.buffer(4);
    byte[] output = new byte[] { 0, 1, 2, 3 };
    this.parser.serializeAttributeHeader(1, (short) 2, (short) 3, byteAggregator);
    assertArrayEquals(output, byteAggregator.array());

    final ByteBuf body = Unpooled.buffer(4);
    output = new byte[] { 0, 0, 0, 1 };
    final AttributeFilter filter = new AttributeFilter(1L);
    this.parser.writeAttributeFilter(filter, body);
    assertArrayEquals(output, body.array());

    final ByteBuf parseTeObj = Unpooled.buffer(1);
    assertNotNull(this.parser.parseObject(parseTeObj));
    assertNull(this.parser.parseObject(null));

    assertEquals(0, parseTeObj.readableBytes());
    this.parser.serializeObject(null, parseTeObj);
    assertEquals(0, parseTeObj.readableBytes());
    this.parser.serializeObject(this.rsvpTeObj, parseTeObj);
    assertEquals(1, parseTeObj.readableBytes());
    assertEquals((short) 3, parseTeObj.readUnsignedByte());
}