org.apache.activemq.artemis.core.protocol.proton.converter.ProtonMessageConverter

Here are the examples of the java api class org.apache.activemq.artemis.core.protocol.proton.converter.ProtonMessageConverter taken from open source projects.

1. TestConversions#testSimpleConversionBytes()

View license
@Test
public void testSimpleConversionBytes() throws Exception {
    Map<String, Object> mapprop = createPropertiesMap();
    ApplicationProperties properties = new ApplicationProperties(mapprop);
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setApplicationProperties(properties);
    byte[] bodyBytes = new byte[4];
    for (int i = 0; i < bodyBytes.length; i++) {
        bodyBytes[i] = (byte) 0xff;
    }
    message.setBody(new Data(new Binary(bodyBytes)));
    EncodedMessage encodedMessage = encodeMessage(message);
    ProtonMessageConverter converter = new ProtonMessageConverter(new SimpleIDGenerator(0));
    ServerJMSBytesMessage serverMessage = (ServerJMSBytesMessage) converter.inboundJMSType(encodedMessage);
    verifyProperties(serverMessage);
    assertEquals(bodyBytes.length, serverMessage.getBodyLength());
    byte[] newBodyBytes = new byte[4];
    serverMessage.readBytes(newBodyBytes);
    Assert.assertArrayEquals(bodyBytes, newBodyBytes);
    Object obj = converter.outbound((ServerMessage) serverMessage.getInnerMessage(), 0);
    System.out.println("output = " + obj);
}

2. TestConversions#testSimpleConversionMap()

View license
@Test
public void testSimpleConversionMap() throws Exception {
    Map<String, Object> mapprop = createPropertiesMap();
    ApplicationProperties properties = new ApplicationProperties(mapprop);
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setApplicationProperties(properties);
    Map<String, Object> mapValues = new HashMap<>();
    mapValues.put("somestr", "value");
    mapValues.put("someint", Integer.valueOf(1));
    message.setBody(new AmqpValue(mapValues));
    EncodedMessage encodedMessage = encodeMessage(message);
    ProtonMessageConverter converter = new ProtonMessageConverter(new SimpleIDGenerator(0));
    ServerJMSMapMessage serverMessage = (ServerJMSMapMessage) converter.inboundJMSType(encodedMessage);
    verifyProperties(serverMessage);
    Assert.assertEquals(1, serverMessage.getInt("someint"));
    Assert.assertEquals("value", serverMessage.getString("somestr"));
    Object obj = converter.outbound((ServerMessage) serverMessage.getInnerMessage(), 0);
    reEncodeMsg(obj);
    MessageImpl outMessage = (MessageImpl) obj;
    AmqpValue value = (AmqpValue) outMessage.getBody();
    Map mapoutput = (Map) value.getValue();
    assertEquals(Integer.valueOf(1), mapoutput.get("someint"));
    System.out.println("output = " + obj);
}

3. TestConversions#testSimpleConversionStream()

View license
@Test
public void testSimpleConversionStream() throws Exception {
    Map<String, Object> mapprop = createPropertiesMap();
    ApplicationProperties properties = new ApplicationProperties(mapprop);
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setApplicationProperties(properties);
    List<Object> objects = new LinkedList<>();
    objects.add(new Integer(10));
    objects.add("10");
    message.setBody(new AmqpSequence(objects));
    EncodedMessage encodedMessage = encodeMessage(message);
    ProtonMessageConverter converter = new ProtonMessageConverter(new SimpleIDGenerator(0));
    ServerJMSStreamMessage serverMessage = (ServerJMSStreamMessage) converter.inboundJMSType(encodedMessage);
    simulatePersistence(serverMessage);
    verifyProperties(serverMessage);
    serverMessage.reset();
    assertEquals(10, serverMessage.readInt());
    assertEquals("10", serverMessage.readString());
    Object obj = converter.outbound((ServerMessage) serverMessage.getInnerMessage(), 0);
    reEncodeMsg(obj);
    MessageImpl outMessage = (MessageImpl) obj;
    List list = ((AmqpSequence) outMessage.getBody()).getValue();
    Assert.assertEquals(Integer.valueOf(10), list.get(0));
    Assert.assertEquals("10", list.get(1));
}

4. TestConversions#testSimpleConversionText()

View license
@Test
public void testSimpleConversionText() throws Exception {
    Map<String, Object> mapprop = createPropertiesMap();
    ApplicationProperties properties = new ApplicationProperties(mapprop);
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setApplicationProperties(properties);
    String text = "someText";
    message.setBody(new AmqpValue(text));
    EncodedMessage encodedMessage = encodeMessage(message);
    ProtonMessageConverter converter = new ProtonMessageConverter(new SimpleIDGenerator(0));
    ServerJMSTextMessage serverMessage = (ServerJMSTextMessage) converter.inboundJMSType(encodedMessage);
    simulatePersistence(serverMessage);
    verifyProperties(serverMessage);
    Assert.assertEquals(text, serverMessage.getText());
    Object obj = converter.outbound((ServerMessage) serverMessage.getInnerMessage(), 0);
    reEncodeMsg(obj);
    MessageImpl outMessage = (MessageImpl) obj;
    AmqpValue value = (AmqpValue) outMessage.getBody();
    String textValue = (String) value.getValue();
    Assert.assertEquals(text, textValue);
    System.out.println("output = " + obj);
}