Search in sources :

Example 6 with ChannelMessage2

use of org.fisco.bcos.channel.dto.ChannelMessage2 in project web3sdk by FISCO-BCOS.

the class ChannelMessage2Test method channelMessage2CodecTest0.

@Test
public void channelMessage2CodecTest0() {
    ChannelMessage2 channelMessage2 = new ChannelMessage2();
    String seq = UUID.randomUUID().toString().replaceAll("-", "");
    Integer result = Integer.valueOf(0);
    String content = "test content";
    String topic = "test_topic";
    channelMessage2.setSeq(seq);
    channelMessage2.setResult(result);
    channelMessage2.setType((short) ChannelMessageType.AMOP_REQUEST.getType());
    channelMessage2.setData(content.getBytes());
    channelMessage2.setTopic(topic);
    ByteBuf buffer = Unpooled.buffer();
    channelMessage2.writeHeader(buffer);
    channelMessage2.writeExtra(buffer);
    ChannelMessage2 channelMessage21 = new ChannelMessage2();
    channelMessage21.readHeader(buffer);
    channelMessage21.readExtra(buffer);
    assertEquals(channelMessage21.getTopic(), topic);
    assertEquals(new String(channelMessage21.getData()), content);
    assertEquals(channelMessage21.getResult(), result);
    assertEquals(channelMessage21.getSeq(), seq);
    assertEquals(channelMessage21.getType().intValue(), ChannelMessageType.AMOP_REQUEST.getType());
}
Also used : ChannelMessage2(org.fisco.bcos.channel.dto.ChannelMessage2) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

ChannelMessage2 (org.fisco.bcos.channel.dto.ChannelMessage2)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 ByteBuf (io.netty.buffer.ByteBuf)4 IOException (java.io.IOException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 KeyStoreException (java.security.KeyStoreException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 NoSuchProviderException (java.security.NoSuchProviderException)3 CertificateException (java.security.cert.CertificateException)3 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)3 TransactionException (org.fisco.bcos.web3j.protocol.exceptions.TransactionException)3 ChannelResponse (org.fisco.bcos.channel.dto.ChannelResponse)2 ChannelConnections (org.fisco.bcos.channel.handler.ChannelConnections)2 ConnectionInfo (org.fisco.bcos.channel.handler.ConnectionInfo)2 Test (org.junit.Test)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 Timeout (io.netty.util.Timeout)1 TimerTask (io.netty.util.TimerTask)1 BigInteger (java.math.BigInteger)1