Example usage for io.netty.buffer UnpooledByteBufAllocator DEFAULT

List of usage examples for io.netty.buffer UnpooledByteBufAllocator DEFAULT

Introduction

In this page you can find the example usage for io.netty.buffer UnpooledByteBufAllocator DEFAULT.

Prototype

UnpooledByteBufAllocator DEFAULT

To view the source code for io.netty.buffer UnpooledByteBufAllocator DEFAULT.

Click Source Link

Document

Default instance which uses leak-detection for direct buffers.

Usage

From source file:org.opendaylight.netide.shim.ShimRelayTest.java

License:Open Source License

@Test
public void testSendToSwitch() {
    ByteBuf input = UnpooledByteBufAllocator.DEFAULT.buffer();
    Mockito.doCallRealMethod().when(shimRelay).sendToSwitch(connectionAdapter, input, ofVersion, coreConnector,
            1L, 1);//from ww  w  .j a  v a2s  .  c  o m
    shimRelay.sendToSwitch(connectionAdapter, input, ofVersion, coreConnector, 1L, 1);
    Mockito.verify(shimRelay).sendDataObjectToSwitch(connectionAdapter, msg, ofVersion, coreConnector, 1L, 1);
}

From source file:org.opendaylight.ocpjava.protocol.impl.serialization.factories.CreateObjInputFactoryTest.java

License:Open Source License

/**
 * Testing of {@link CreateObjInputFactory} for correct translation from POJO
 * @throws Exception//w ww.j  a  v  a  2  s  .com
 */
@Test
public void testElementsSet() throws Exception {
    CreateObjInputBuilder hib = new CreateObjInputBuilder();
    BufferHelper.setupHeader(hib, OcpMsgType.valueOf("CREATEOBJREQ"));
    boolean testEvent = true;
    String testObjTypeId = "exampleObj";

    //set xid
    Method m2_t = hib.getClass().getMethod("setXid", Long.class);
    m2_t.invoke(hib, new Long(0));

    //set ObjType
    Method m3_t = hib.getClass().getMethod("setObjType", ObjType.class);
    m3_t.invoke(hib, new ObjType(testObjTypeId));

    //set params
    ParamBuilder parambuilder1 = new ParamBuilder();
    List<Param> plist = new ArrayList();
    parambuilder1.setName("parameter1");
    parambuilder1.setValue("value1");
    plist.add(parambuilder1.build());
    ParamBuilder parambuilder2 = new ParamBuilder();
    parambuilder2.setName("parameter2");
    parambuilder2.setValue("value2");
    plist.add(parambuilder2.build());
    Method m4_t = hib.getClass().getMethod("setParam", List.class);
    m4_t.invoke(hib, plist);

    CreateObjInput hi = hib.build();
    LOG.debug("CreateObjInputFactoryTest - hi objId value = {}", hi.getObjType());

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    createObjInputFactory.serialize(hi, out);

    //Verify and check the bytebuf info
    LOG.debug("HealthCheckInputMessageFactoryTest - out = {}", out.readableBytes());
    byte[] bytes = new byte[out.readableBytes()];
    int readerIndex = out.readerIndex();
    out.getBytes(readerIndex, bytes);

    String buf = new String(bytes, "UTF-8");
    StringBuilder seq = new StringBuilder("");
    seq.append("<param name=\"parameter1\">value1</param>");
    boolean checkVal = buf.contains(seq);

    StringBuilder seq2 = new StringBuilder("");
    seq2.append("<objType objTypeID=\"");
    seq2.append(testObjTypeId);
    seq2.append("\">");
    boolean checkVal2 = buf.contains(seq2);

    //Check and compare elements
    Assert.assertEquals("Wrong length", true, checkVal);
    Assert.assertEquals("Wrong length", true, checkVal2);
}

From source file:org.opendaylight.ocpjava.protocol.impl.serialization.factories.DeleteObjInputFactoryTest.java

License:Open Source License

/**
 * Testing of {@link HealthCheckInputMessageFactory} for correct translation from POJO
 * @throws Exception//from www. j a  v a2 s  .c  o  m
 */
@Test
public void testElementsSet() throws Exception {
    DeleteObjInputBuilder hib = new DeleteObjInputBuilder();
    BufferHelper.setupHeader(hib, OcpMsgType.valueOf("DELETEOBJREQ"));
    boolean testEvent = true;
    String testObjId = "exampleObj:0";
    //set xid
    Method m2_t = hib.getClass().getMethod("setXid", Long.class);
    m2_t.invoke(hib, new Long(0));

    //set ObjId
    Method m4_t = hib.getClass().getMethod("setObjId", ObjId.class);
    m4_t.invoke(hib, new ObjId(testObjId));

    DeleteObjInput hi = hib.build();
    LOG.debug("GetFaultInputFactoryTest - hi objId value = {}", hi.getObjId());

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    deleteObjInputFactory.serialize(hi, out);

    //Verify and check the bytebuf info
    LOG.debug("DeleteObjInputFactoryTest - out = {}", out.readableBytes());
    byte[] bytes = new byte[out.readableBytes()];
    int readerIndex = out.readerIndex();
    out.getBytes(readerIndex, bytes);

    String buf = new String(bytes, "UTF-8");
    StringBuilder seq = new StringBuilder("");
    seq.append("<obj objID=\"");
    seq.append(testObjId);
    seq.append("\"/>");
    boolean checkVal = buf.contains(seq);

    //Check and compare elements
    Assert.assertEquals("Wrong length", true, checkVal);
}

From source file:org.opendaylight.ocpjava.protocol.impl.serialization.factories.GetFaultInputFactoryTest.java

License:Open Source License

/**
 * Testing of {@link HealthCheckInputMessageFactory} for correct translation from POJO
 * @throws Exception/*  www . jav a 2s  . c  o m*/
 */
@Test
public void testElementsSet() throws Exception {
    GetFaultInputBuilder hib = new GetFaultInputBuilder();
    BufferHelper.setupHeader(hib, OcpMsgType.valueOf("GETFAULTREQ"));
    boolean testEvent = true;
    String testObjId = "ALL";
    //set xid
    Method m2_t = hib.getClass().getMethod("setXid", Long.class);
    m2_t.invoke(hib, new Long(0));

    //set ObjId
    Method m3_t = hib.getClass().getMethod("setObjId", ObjId.class);
    m3_t.invoke(hib, new ObjId(testObjId));

    //set eventDrivenReporting
    Method m4_t = hib.getClass().getMethod("setEventDrivenReporting", Boolean.class);
    m4_t.invoke(hib, new Boolean(testEvent));

    GetFaultInput hi = hib.build();
    LOG.debug("GetFaultInputFactoryTest - hi objId value = {}", hi.getObjId());

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    getFaultInputFactory.serialize(hi, out);

    //Verify and check the bytebuf info
    LOG.debug("HealthCheckInputMessageFactoryTest - out = {}", out.readableBytes());
    byte[] bytes = new byte[out.readableBytes()];
    int readerIndex = out.readerIndex();
    out.getBytes(readerIndex, bytes);

    String buf = new String(bytes, "UTF-8");
    StringBuilder seq = new StringBuilder("");
    seq.append("<eventDrivenReporting>");
    seq.append(String.valueOf(testEvent));
    seq.append("</eventDrivenReporting>");
    boolean checkVal = buf.contains(seq);

    StringBuilder seq2 = new StringBuilder("");
    seq2.append("<obj objID=\"");
    seq2.append(testObjId);
    seq2.append("\"/>");
    boolean checkVal2 = buf.contains(seq2);

    //Check and compare elements
    Assert.assertEquals("Wrong length", true, checkVal);
    Assert.assertEquals("Wrong length", true, checkVal2);
}

From source file:org.opendaylight.ocpjava.protocol.impl.serialization.factories.GetParamInputFactoryTest.java

License:Open Source License

/**
 * Testing of {@link GetParamInputFactory} for correct translation from POJO
 * @throws Exception/* w w  w. j  a va2 s .  c o m*/
 */
@Test
public void testElementsSet() throws Exception {
    GetParamInputBuilder hib = new GetParamInputBuilder();
    BufferHelper.setupHeader(hib, OcpMsgType.valueOf("GETPARAMREQ"));
    String testObjId = "RE:0";
    //set xid
    Method m2_t = hib.getClass().getMethod("setXid", Long.class);
    m2_t.invoke(hib, new Long(0));

    //set ObjId
    Method m3_t = hib.getClass().getMethod("setObjId", ObjId.class);
    m3_t.invoke(hib, new ObjId(testObjId));

    //set paramName
    Method m4_t = hib.getClass().getMethod("setParamName", String.class);
    m4_t.invoke(hib, "vendorID");

    GetParamInput hi = hib.build();
    LOG.debug("GetParamInputFactoryTest - hi objId = {}", hi.getObjId().getValue());
    LOG.debug("GetParamInputFactoryTest - hi paramName = {}", hi.getParamName());

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    getParamInputFactory.serialize(hi, out);

    //Verify and check the bytebuf info
    LOG.debug("GetParamInputFactoryTest - out = {}", out.readableBytes());
    byte[] bytes = new byte[out.readableBytes()];
    int readerIndex = out.readerIndex();
    out.getBytes(readerIndex, bytes);

    String buf = new String(bytes, "UTF-8");
    StringBuilder seq = new StringBuilder("");
    seq.append("<obj objID=\"");
    seq.append(testObjId);
    seq.append("\">");
    boolean checkVal = buf.contains(seq);

    //Check and compare elements
    Assert.assertEquals("Wrong length", true, checkVal);
}

From source file:org.opendaylight.ocpjava.protocol.impl.serialization.factories.GetStateInputFactoryTest.java

License:Open Source License

/**
 * Testing of {@link HealthCheckInputMessageFactory} for correct translation from POJO
 * @throws Exception/*from  ww w  . j  a va  2s. c o  m*/
 */
@Test
public void testElementsSet() throws Exception {
    GetStateInputBuilder hib = new GetStateInputBuilder();
    BufferHelper.setupHeader(hib, OcpMsgType.valueOf("GETSTATEREQ"));
    boolean testEvent = true;
    String testObjId = "exampleObj:0";
    String testStateType = "ALL";

    //set xid
    Method m2_t = hib.getClass().getMethod("setXid", Long.class);
    m2_t.invoke(hib, new Long(0));

    //set eventDrivenReporting
    Method m3_t = hib.getClass().getMethod("setEventDrivenReporting", Boolean.class);
    m3_t.invoke(hib, new Boolean(testEvent));

    //set ObjId
    Method m4_t = hib.getClass().getMethod("setObjId", ObjId.class);
    m4_t.invoke(hib, new ObjId(testObjId));

    //set State Type
    Method m5_t = hib.getClass().getMethod("setStateType", StateAllType.class);
    m5_t.invoke(hib, StateAllType.valueOf(testStateType));

    GetStateInput hi = hib.build();
    LOG.debug("GetStateInputFactoryTest - hi objId value = {}", hi.getObjId());

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    getStateInputFactory.serialize(hi, out);

    //Verify and check the bytebuf info
    LOG.debug("GetStateInputFactoryTest - out = {}", out.readableBytes());
    byte[] bytes = new byte[out.readableBytes()];
    int readerIndex = out.readerIndex();
    out.getBytes(readerIndex, bytes);

    String buf = new String(bytes, "UTF-8");
    StringBuilder seq = new StringBuilder("");
    seq.append("<obj objID=\"");
    seq.append(testObjId);
    seq.append("\">");
    boolean checkVal = buf.contains(seq);

    StringBuilder seq2 = new StringBuilder("");
    seq2.append("<eventDrivenReporting>");
    seq2.append(String.valueOf(testEvent));
    seq2.append("</eventDrivenReporting>");
    boolean checkVal2 = buf.contains(seq2);

    //Check and compare elements
    Assert.assertEquals("Wrong length", true, checkVal);
    Assert.assertEquals("Wrong length", true, checkVal2);
}

From source file:org.opendaylight.ocpjava.protocol.impl.serialization.factories.HealthCheckInputFactoryTest.java

License:Open Source License

/**
 * Testing of {@link HealthCheckInputMessageFactory} for correct translation from POJO
 * @throws Exception//from ww w  .  ja  v a2  s. c  om
 */
@Test
public void testElementsSet() throws Exception {
    HealthCheckInputBuilder hib = new HealthCheckInputBuilder();
    BufferHelper.setupHeader(hib, OcpMsgType.valueOf("HEALTHCHECKREQ"));
    int testTimeout = 16;

    //set tcpLinkMonTimeout
    Method m_t = hib.getClass().getMethod("setTcpLinkMonTimeout", XsdUnsignedShort.class);
    m_t.invoke(hib, new XsdUnsignedShort(testTimeout));

    //set xid
    Method m2_t = hib.getClass().getMethod("setXid", Long.class);
    m2_t.invoke(hib, new Long(0));

    HealthCheckInput hi = hib.build();
    LOG.debug("HealthCheckInputMessageFactoryTest - hi testTimeout value = {}",
            hi.getTcpLinkMonTimeout().getValue());

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    healthCheckFactory.serialize(hi, out);

    //Verify and check the bytebuf info
    LOG.debug("HealthCheckInputMessageFactoryTest - out = {}", out.readableBytes());
    byte[] bytes = new byte[out.readableBytes()];
    int readerIndex = out.readerIndex();
    out.getBytes(readerIndex, bytes);

    StringBuilder seq = new StringBuilder("");
    seq.append("<tcpLinkMonTimeout>");
    seq.append(testTimeout);
    seq.append("</tcpLinkMonTimeout>");
    String buf = new String(bytes, "UTF-8");
    boolean checkVal = buf.contains(seq);

    //Check and compare elements
    Assert.assertEquals("Wrong length", true, checkVal);
}

From source file:org.opendaylight.ocpjava.protocol.impl.serialization.factories.HelloInputFactoryTest.java

License:Open Source License

/**
 * Testing of {@link HealthCheckInputMessageFactory} for correct translation from POJO
 * @throws Exception//  w w  w .  ja va 2 s. c om
 */
@Test
public void testElementsSet() throws Exception {
    HelloInputBuilder hib = new HelloInputBuilder();
    BufferHelper.setupHeader(hib, OcpMsgType.valueOf("HELLOACK"));
    String testResult = "FAILOCPVERSION";

    //set result
    Method m_t = hib.getClass().getMethod("setResult", OriHelloAckRes.class);
    m_t.invoke(hib, OriHelloAckRes.valueOf(testResult));

    //set xid
    Method m2_t = hib.getClass().getMethod("setXid", Long.class);
    m2_t.invoke(hib, new Long(0));

    HelloInput hi = hib.build();
    LOG.debug("HealthCheckInputMessageFactoryTest - hi result value = {}", hi.getResult());

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    helloInputFactory.serialize(hi, out);

    //Verify and check the bytebuf info
    LOG.debug("HealthCheckInputMessageFactoryTest - out = {}", out.readableBytes());
    byte[] bytes = new byte[out.readableBytes()];
    int readerIndex = out.readerIndex();
    out.getBytes(readerIndex, bytes);

    StringBuilder seq = new StringBuilder("");
    seq.append("<result>");
    seq.append(testResult);
    seq.append("</result>");
    String buf = new String(bytes, "UTF-8");
    boolean checkVal = buf.contains(seq);

    //Check and compare elements
    Assert.assertEquals("Wrong length", true, checkVal);
}

From source file:org.opendaylight.ocpjava.protocol.impl.serialization.factories.ModifyParamInputFactoryTest.java

License:Open Source License

/**
 * Testing of {@link ModifyParamInputFactory} for correct translation from POJO
 * @throws Exception//from   w ww  . j  a  v  a  2 s.  c  o m
 */
@Test
public void testElementsSet() throws Exception {
    ModifyParamInputBuilder hib = new ModifyParamInputBuilder();
    BufferHelper.setupHeader(hib, OcpMsgType.valueOf("MODIFYPARAMREQ"));
    boolean testEvent = true;
    String testObjId = "ALL";
    //set xid
    Method m_t = hib.getClass().getMethod("setXid", Long.class);
    m_t.invoke(hib, new Long(0));

    //set ObjId
    Method m2_t = hib.getClass().getMethod("setObjId", ObjId.class);
    m2_t.invoke(hib, new ObjId(testObjId));

    //set Params
    List<Param> plist = new ArrayList();
    ParamBuilder parambuilder1 = new ParamBuilder();
    parambuilder1.setName("parameter1");
    parambuilder1.setValue("value1");
    plist.add(parambuilder1.build());
    ParamBuilder parambuilder2 = new ParamBuilder();
    parambuilder2.setName("parameter2");
    parambuilder2.setValue("value2");
    plist.add(parambuilder2.build());
    ParamBuilder parambuilder3 = new ParamBuilder();
    parambuilder3.setName("parameter3");
    parambuilder3.setValue("a wrong value");
    plist.add(parambuilder3.build());

    Method m3_t = hib.getClass().getMethod("setParam", List.class);
    m3_t.invoke(hib, plist);

    ModifyParamInput hi = hib.build();
    LOG.debug("ModifyParamInputFactoryTest - hi objId value = {}", hi.getObjId());

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    modifyParamInputFactory.serialize(hi, out);

    //Verify and check the bytebuf info
    LOG.debug("ModifyParamInputFactoryTest - out = {}", out.readableBytes());
    byte[] bytes = new byte[out.readableBytes()];
    int readerIndex = out.readerIndex();
    out.getBytes(readerIndex, bytes);

    String buf = new String(bytes, "UTF-8");
    StringBuilder seq = new StringBuilder("");
    seq.append("<obj objID=\"");
    seq.append(testObjId);
    seq.append("\">");
    boolean checkVal = buf.contains(seq);

    //Check and compare elements
    Assert.assertEquals("Wrong length", true, checkVal);
}

From source file:org.opendaylight.ocpjava.protocol.impl.serialization.factories.ModifyStateInputFactoryTest.java

License:Open Source License

/**
 * Testing of {@link HealthCheckInputMessageFactory} for correct translation from POJO
 * @throws Exception//from w w w. j a  v  a 2s  .co  m
 */
@Test
public void testElementsSet() throws Exception {
    ModifyStateInputBuilder hib = new ModifyStateInputBuilder();
    BufferHelper.setupHeader(hib, OcpMsgType.valueOf("MODIFYSTATEREQ"));
    boolean testEvent = true;
    String testObjId = "ALL";
    String testType = "AST";
    String testVal = "UNLOCKED";

    //set xid
    Method m2_t = hib.getClass().getMethod("setXid", Long.class);
    m2_t.invoke(hib, new Long(0));

    //set ObjId
    Method m3_t = hib.getClass().getMethod("setObjId", ObjId.class);
    m3_t.invoke(hib, new ObjId(testObjId));

    //set stateType
    Method m4_t = hib.getClass().getMethod("setStateType", StateType.class);
    m4_t.invoke(hib, StateType.valueOf(testType));

    //set stateValue
    Method m5_t = hib.getClass().getMethod("setStateValue", StateVal.class);
    m5_t.invoke(hib, StateVal.valueOf(testVal));

    ModifyStateInput hi = hib.build();
    LOG.debug("ModifyStateInputFactoryTest - hi objId value = {}", hi.getObjId());

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    modifyStateInputFactory.serialize(hi, out);

    //Verify and check the bytebuf info
    LOG.debug("ModifyStateInputFactoryTest - out = {}", out.readableBytes());
    byte[] bytes = new byte[out.readableBytes()];
    int readerIndex = out.readerIndex();
    out.getBytes(readerIndex, bytes);

    String buf = new String(bytes, "UTF-8");
    StringBuilder seq = new StringBuilder("");
    seq.append("<obj objID=\"");
    seq.append(testObjId);
    seq.append("\">");
    boolean checkVal = buf.contains(seq);

    //Check and compare elements
    Assert.assertEquals("Wrong length", true, checkVal);
}