Example usage for io.netty.buffer Unpooled wrappedBuffer

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

Introduction

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

Prototype

public static ByteBuf wrappedBuffer(ByteBuffer... buffers) 

Source Link

Document

Creates a new big-endian composite buffer which wraps the slices of the specified NIO buffers without copying them.

Usage

From source file:com.whizzosoftware.wzwave.channel.TransactionInboundHandlerTest.java

License:Open Source License

@Test
public void testSendDataSleepingNodeTransactionNetworkCongestionFailure() throws Exception {
    MockChannelHandlerContext ctx = new MockChannelHandlerContext();
    TransactionInboundHandler h = new TransactionInboundHandler();

    h.userEventTriggered(ctx,//from  w w  w  . j av  a  2  s .c  o  m
            new DataFrameSentEvent(new SendData(Unpooled.wrappedBuffer(
                    new byte[] { 0x01, 0x09, 0x00, 0x13, 0x06, 0x02, 0x00, 0x00, 0x25, 0x0a, (byte) 0xce })),
                    false));
    assertEquals(1, ctx.getUserEvents().size());
    assertEquals(0, ctx.getWriteQueue().size());
    assertTrue(ctx.getUserEvents().get(0) instanceof TransactionStartedEvent);
    h.channelRead(ctx, new ACK());
    assertEquals(1, ctx.getUserEvents().size());
    assertEquals(0, ctx.getWriteQueue().size());
    h.channelRead(ctx,
            new SendData(Unpooled.wrappedBuffer(new byte[] { 0x01, 0x04, 0x01, 0x13, 0x01, (byte) 0xe8 })));
    assertEquals(1, ctx.getUserEvents().size());
    assertEquals(0, ctx.getWriteQueue().size());
    h.channelRead(ctx, new SendData(
            Unpooled.wrappedBuffer(new byte[] { 0x01, 0x05, 0x00, 0x13, 0x0a, 0x02, (byte) 0xe2 })));
    assertEquals(1, ctx.getUserEvents().size());
    assertEquals(1, ctx.getWriteQueue().size());
    assertTrue(ctx.getWriteQueue().get(0) instanceof OutboundDataFrame);
}

From source file:com.whizzosoftware.wzwave.channel.TransactionInboundHandlerTest.java

License:Open Source License

@Test
public void testSendDataResponseFrameTimeout() throws Exception {
    MockChannelHandlerContext ctx = new MockChannelHandlerContext();
    TransactionInboundHandler h = new TransactionInboundHandler();

    h.userEventTriggered(ctx,/*from w  w w  .j a  v  a  2s. c  om*/
            new DataFrameSentEvent(new SendData("", (byte) 0x01,
                    new byte[] { 0x01, 0x09, 0x00, 0x13, 0x06, 0x02, 0x00, 0x00, 0x25, 0x0a, (byte) 0xce },
                    (byte) 0x05, true), true));
    assertEquals(1, ctx.getUserEvents().size());
    assertEquals(0, ctx.getWriteQueue().size());
    assertTrue(ctx.getUserEvents().get(0) instanceof TransactionStartedEvent);
    h.channelRead(ctx, new ACK());
    assertEquals(1, ctx.getUserEvents().size());
    assertEquals(0, ctx.getWriteQueue().size());
    h.channelRead(ctx,
            new SendData(Unpooled.wrappedBuffer(new byte[] { 0x01, 0x04, 0x01, 0x13, 0x01, (byte) 0xe8 })));
    assertEquals(1, ctx.getUserEvents().size());
    assertEquals(0, ctx.getWriteQueue().size());
    h.channelRead(ctx, new SendData(
            Unpooled.wrappedBuffer(new byte[] { 0x01, 0x05, 0x00, 0x13, 0x0a, 0x00, (byte) 0xe2 })));
    assertEquals(1, ctx.getUserEvents().size());
    assertEquals(0, ctx.getWriteQueue().size());
    h.userEventTriggered(ctx, new TransactionTimeoutEvent(h.getCurrentTransaction().getId()));
    assertEquals(1, ctx.getWriteQueue().size());
    assertTrue(ctx.getWriteQueue().get(0) instanceof OutboundDataFrame);
    assertTrue(((OutboundDataFrame) ctx.getWriteQueue().get(0)).getDataFrame() instanceof SendData);
}

From source file:com.whizzosoftware.wzwave.channel.TransactionInboundHandlerTest.java

License:Open Source License

@Test
public void testSendDataSuccessfulTransaction() throws Exception {
    MockChannelHandlerContext ctx = new MockChannelHandlerContext();
    TransactionInboundHandler h = new TransactionInboundHandler();

    h.userEventTriggered(ctx,//from w  w  w  .j av  a 2s  .co  m
            new DataFrameSentEvent(new SendData(Unpooled.wrappedBuffer(
                    new byte[] { 0x01, 0x09, 0x00, 0x13, 0x06, 0x02, 0x00, 0x00, 0x25, 0x0a, (byte) 0xce })),
                    false));
    assertEquals(1, ctx.getUserEvents().size());
    assertEquals(0, ctx.getWriteQueue().size());
    assertTrue(ctx.getUserEvents().get(0) instanceof TransactionStartedEvent);
    h.channelRead(ctx, new ACK());
    assertEquals(1, ctx.getUserEvents().size());
    assertEquals(0, ctx.getWriteQueue().size());
    h.channelRead(ctx,
            new SendData(Unpooled.wrappedBuffer(new byte[] { 0x01, 0x04, 0x01, 0x13, 0x01, (byte) 0xe8 })));
    assertEquals(1, ctx.getUserEvents().size());
    assertEquals(0, ctx.getWriteQueue().size());
    h.channelRead(ctx, new SendData(
            Unpooled.wrappedBuffer(new byte[] { 0x01, 0x05, 0x00, 0x13, 0x0a, 0x00, (byte) 0xe2 })));
    assertEquals(2, ctx.getUserEvents().size());
    assertTrue(ctx.getUserEvents().get(1) instanceof TransactionCompletedEvent);
}

From source file:com.whizzosoftware.wzwave.frame.AddNodeToNetworkTest.java

License:Open Source License

@Test
public void testResponseConstructorWithNoNodeInfo() {
    byte[] b = new byte[] { 0x01, 0x07, 0x00, 0x4A, 0x02, 0x01, 0x00, 0x00, (byte) 0xB1 };
    ByteBuf buffer = Unpooled.wrappedBuffer(b);
    AddNodeToNetwork f = new AddNodeToNetwork(buffer);
    assertEquals(1, buffer.readableBytes());
    assertEquals(AddNodeToNetwork.ADD_NODE_STATUS_LEARN_READY, f.getStatus());
    assertEquals(0, f.getSource());/*from   w w  w  .  ja  va  2  s .c o  m*/
    assertFalse(f.hasNodeInfo());
}

From source file:com.whizzosoftware.wzwave.frame.AddNodeToNetworkTest.java

License:Open Source License

@Test
public void testResponseConstructorWithNodeInfo() {
    byte[] b = new byte[] { 0x01, 0x14, 0x00, 0x4A, 0x01, 0x03, 0x02, 0x0D, 0x04, 0x10, 0x01, 0x25, 0x31, 0x32,
            0x27, 0x70, (byte) 0x85, 0x72, (byte) 0x86, (byte) 0xEF, (byte) 0x82, (byte) 0xD4 };
    ByteBuf buffer = Unpooled.wrappedBuffer(b);
    AddNodeToNetwork f = new AddNodeToNetwork(buffer);
    assertEquals(1, buffer.readableBytes());
    assertEquals(AddNodeToNetwork.ADD_NODE_STATUS_ADDING_SLAVE, f.getStatus());
    assertEquals(2, f.getSource());/* ww w  . jav a2  s  .  c om*/
    assertTrue(f.hasNodeInfo());
    assertEquals(0x04, f.getNodeInfo().getBasicDeviceClass());
    assertEquals(0x10, f.getNodeInfo().getGenericDeviceClass());
    assertEquals(0x01, f.getNodeInfo().getSpecificDeviceClass());
    assertNotNull(f.getNodeInfo().getCommandClasses());
    assertEquals(10, f.getNodeInfo().getCommandClasses().length);
    assertEquals(0x25, f.getNodeInfo().getCommandClasses()[0]);
    assertEquals(0x31, f.getNodeInfo().getCommandClasses()[1]);
    assertEquals(0x32, f.getNodeInfo().getCommandClasses()[2]);
    assertEquals(0x27, f.getNodeInfo().getCommandClasses()[3]);
    assertEquals(0x70, f.getNodeInfo().getCommandClasses()[4]);
    assertEquals((byte) 0x85, f.getNodeInfo().getCommandClasses()[5]);
    assertEquals(0x72, f.getNodeInfo().getCommandClasses()[6]);
    assertEquals((byte) 0x86, f.getNodeInfo().getCommandClasses()[7]);
    assertEquals((byte) 0xEF, f.getNodeInfo().getCommandClasses()[8]);
    assertEquals((byte) 0x82, f.getNodeInfo().getCommandClasses()[9]);
}

From source file:com.whizzosoftware.wzwave.frame.ApplicationCommandTest.java

License:Open Source License

@Test
public void testByteArrayConstructor() {
    byte[] b1 = { 0x01, 0x09, 0x00, 0x04, 0x00, 0x06, 0x03, 0x25, 0x03, 0x00, -45 };
    ByteBuf buffer = Unpooled.wrappedBuffer(b1);
    ApplicationCommand cmd = new ApplicationCommand(buffer);
    assertEquals(1, buffer.readableBytes());
    assertEquals(0, cmd.getStatus());//from www.  ja  va2s  .  com
    assertEquals(6, cmd.getNodeId());
    assertEquals(BinarySwitchCommandClass.ID, cmd.getCommandClassId());
}

From source file:com.whizzosoftware.wzwave.frame.ApplicationUpdateTest.java

License:Open Source License

@Test
public void testConstructorWithNodeInfoReceived() {
    byte[] b = new byte[] { 0x01, 16, 0x00, 0x49, (byte) 0x84, 0x02, 0x0a, 0x04, 0x10, 0x01, 0x25, 0x27, 0x75,
            0x73, (byte) 0x86, 0x72, 0x77, (byte) 0xb8 };
    ByteBuf buffer = Unpooled.wrappedBuffer(b);
    ApplicationUpdate au = new ApplicationUpdate(buffer);
    assertEquals(1, buffer.readableBytes());
    assertEquals(ApplicationUpdate.UPDATE_STATE_NODE_INFO_RECEIVED, au.getState());
    assertEquals((byte) 0x02, (byte) au.getNodeId());
    assertNotNull(au.getNodeInfo());// w ww .j  a v a 2  s  . c o m
    assertEquals((byte) 0x04, au.getNodeInfo().getBasicDeviceClass());
    assertEquals((byte) 0x10, au.getNodeInfo().getGenericDeviceClass());
    assertEquals((byte) 0x01, au.getNodeInfo().getSpecificDeviceClass());
    assertEquals(7, au.getNodeInfo().getCommandClasses().length);
    assertEquals((byte) 0x25, au.getNodeInfo().getCommandClasses()[0]);
    assertEquals((byte) 0x27, au.getNodeInfo().getCommandClasses()[1]);
    assertEquals((byte) 0x75, au.getNodeInfo().getCommandClasses()[2]);
    assertEquals((byte) 0x73, au.getNodeInfo().getCommandClasses()[3]);
    assertEquals((byte) 0x86, au.getNodeInfo().getCommandClasses()[4]);
    assertEquals((byte) 0x72, au.getNodeInfo().getCommandClasses()[5]);
    assertEquals((byte) 0x77, au.getNodeInfo().getCommandClasses()[6]);
}

From source file:com.whizzosoftware.wzwave.frame.ApplicationUpdateTest.java

License:Open Source License

@Test
public void testConstructorWithNodeInfoRequestFailed() {
    byte[] b = new byte[] { 0x01, 6, 0x00, 0x49, (byte) 0x81, 0x00, 0x00, 0x31 };
    ByteBuf buffer = Unpooled.wrappedBuffer(b);
    ApplicationUpdate au = new ApplicationUpdate(buffer);
    assertEquals(1, buffer.readableBytes());
    assertEquals(ApplicationUpdate.UPDATE_STATE_NODE_INFO_REQ_FAILED, au.getState());
}

From source file:com.whizzosoftware.wzwave.frame.InitDataTest.java

License:Open Source License

@Test
public void testResponseConstructor() {
    byte[] b = new byte[] { 0x01, 0x25, 0x01, 0x02, 0x05, 0x00, 0x1d, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, (byte) 0xe2 };
    ByteBuf buffer = Unpooled.wrappedBuffer(b);
    InitData id = new InitData(buffer);
    assertEquals(1, buffer.readableBytes());
    List<Byte> nodes = id.getNodes();
    assertEquals(2, nodes.size());//from ww w  .j  a  v  a2  s  .  c  om
    assertEquals(1, (int) nodes.get(0));
    assertEquals(14, (int) nodes.get(1));
}

From source file:com.whizzosoftware.wzwave.frame.MemoryGetIdTest.java

License:Open Source License

@Test
public void testResponseConstructor() {
    byte[] b = new byte[] { 0x01, 0x08, 0x01, 0x20, 0x01, 0x6a, 0x2d, (byte) 0xec, 0x01, 0x7d };
    ByteBuf buffer = Unpooled.wrappedBuffer(b);
    MemoryGetId mgid = new MemoryGetId(buffer);
    assertEquals(1, buffer.readableBytes());
    assertEquals(-20, (int) mgid.getHomeId()); // TODO
    assertEquals(0x01, (byte) mgid.getNodeId());
}