org.apache.qpid.proton.amqp.messaging.Data Java Examples

The following examples show how to use org.apache.qpid.proton.amqp.messaging.Data. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmqpSourceTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test
public void testSourceWithDataContent() {
    String topic = UUID.randomUUID().toString();
    Map<String, Object> config = getConfig(topic);
    List<Message<byte[]>> messages = new ArrayList<>();
    provider = new AmqpConnector();
    provider.setup(executionHolder);

    PublisherBuilder<? extends Message<?>> builder = provider.getPublisherBuilder(new MapBasedConfig(config));
    AtomicBoolean opened = new AtomicBoolean();

    builder.to(createSubscriber(messages, opened)).run();
    await().until(opened::get);

    await().until(() -> provider.isReady(config.get(CHANNEL_NAME_ATTRIBUTE).toString()));

    List<String> list = new ArrayList<>();
    list.add("hello");
    list.add("world");
    usage.produce(topic, 1, () -> new Data(new Binary(list.toString().getBytes())));

    await().atMost(2, TimeUnit.MINUTES).until(() -> !messages.isEmpty());
    byte[] result = messages.get(0).getPayload();
    assertThat(new String(result))
            .isEqualTo(list.toString());
}
 
Example #2
Source File: JMSMappingOutboundTransformerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertTextMessageContentNotStoredCreatesBodyUsingOriginalEncodingWithDataSection() throws Exception {
   String contentString = "myTextMessageContent";
   ServerJMSTextMessage outbound = createTextMessage(contentString);
   outbound.setShortProperty(JMS_AMQP_ORIGINAL_ENCODING, AMQP_DATA);
   outbound.encode();

   AMQPMessage amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage(), null);

   assertNotNull(amqp.getBody());
   assertTrue(amqp.getBody() instanceof Data);
   assertTrue(((Data) amqp.getBody()).getValue() instanceof Binary);

   Binary data = ((Data) amqp.getBody()).getValue();
   String contents = new String(data.getArray(), data.getArrayOffset(), data.getLength(), StandardCharsets.UTF_8);
   assertEquals(contentString, contents);
}
 
Example #3
Source File: JMSMappingOutboundTransformerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertTextMessageCreatesBodyUsingOriginalEncodingWithDataSection() throws Exception {
   String contentString = "myTextMessageContent";
   ServerJMSTextMessage outbound = createTextMessage(contentString);
   outbound.setShortProperty(JMS_AMQP_ORIGINAL_ENCODING, AMQP_DATA);
   outbound.encode();

   AMQPMessage amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage(), null);

   assertNotNull(amqp.getBody());
   assertTrue(amqp.getBody() instanceof Data);
   assertTrue(((Data) amqp.getBody()).getValue() instanceof Binary);

   Binary data = ((Data) amqp.getBody()).getValue();
   String contents = new String(data.getArray(), data.getArrayOffset(), data.getLength(), StandardCharsets.UTF_8);
   assertEquals(contentString, contents);
}
 
Example #4
Source File: JMSMappingOutboundTransformerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertObjectMessageToAmqpMessageUnknownEncodingGetsDataSection() throws Exception {
   ServerJMSObjectMessage outbound = createObjectMessage(TEST_OBJECT_VALUE);
   outbound.setShortProperty(JMS_AMQP_ORIGINAL_ENCODING, AMQP_UNKNOWN);
   outbound.encode();

   AMQPMessage amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage(), null);

   assertNotNull(amqp.getBody());
   assertTrue(amqp.getBody() instanceof Data);
   assertFalse(0 == ((Data) amqp.getBody()).getValue().getLength());

   Object value = deserialize(((Data) amqp.getBody()).getValue().getArray());
   assertNotNull(value);
   assertTrue(value instanceof UUID);
}
 
Example #5
Source File: MessageSendTester.java    From enmasse with Apache License 2.0 6 votes vote down vote up
private void handleMessage(final Message message) {

            if (log.isInfoEnabled()) {
                String str = message.toString();
                if (str.length() > MAX_MESSAGE_DUMP_LENGTH) {
                    str = str.substring(0, MAX_MESSAGE_DUMP_LENGTH) + "…";
                }
                log.info("Received message - {}", str);
            }

            var body = message.getBody();
            if (!(body instanceof Data)) {
                handleInvalidMessage(message);
                return;
            }

            var json = new JsonObject(Buffer.buffer(((Data) body).getValue().getArray()));
            var testId = json.getString("test-id");
            var timestamp = json.getLong("timestamp");
            if (!this.testId.equals(testId) || timestamp == null) {
                handleInvalidMessage(message);
                return;
            }

            handleValidMessage(message, timestamp, json);
        }
 
Example #6
Source File: AmqpJmsTextMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTextUsingReceivedMessageWithDataSectionContainingStringBytes() throws Exception {
    String encodedString = "myEncodedString";
    byte[] encodedBytes = encodedString.getBytes(Charset.forName("UTF-8"));

    org.apache.qpid.proton.codec.Data payloadData = org.apache.qpid.proton.codec.Data.Factory.create();
    payloadData.putDescribedType(new DataDescribedType(new Binary(encodedBytes)));
    Binary b = payloadData.encode();

    Message message = Message.Factory.create();
    int decoded = message.decode(b.getArray(), b.getArrayOffset(), b.getLength());
    assertEquals(decoded, b.getLength());
    AmqpJmsTextMessageFacade amqpTextMessageFacade = createReceivedTextMessageFacade(createMockAmqpConsumer(), message);

    assertEquals(encodedString, amqpTextMessageFacade.getText());
}
 
Example #7
Source File: AmqpJmsTextMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTextWithUnknownEncodedDataThrowsJMSException() throws Exception {
    String encodedString = "myEncodedString";
    byte[] encodedBytes = encodedString.getBytes(Charset.forName("UTF-16"));

    Message message = Message.Factory.create();
    message.setBody(new Data(new Binary(encodedBytes)));
    AmqpJmsTextMessageFacade amqpTextMessageFacade = createReceivedTextMessageFacade(createMockAmqpConsumer(), message);

    try {
        amqpTextMessageFacade.getText();
        fail("expected exception not thrown");
    } catch (JMSException ise) {
        // expected
    }
}
 
Example #8
Source File: AmqpCodecTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Test that a data body containing nothing, but with the content type set to
 * {@value AmqpMessageSupport#OCTET_STREAM_CONTENT_TYPE} results in a BytesMessage when not
 * otherwise annotated to indicate the type of JMS message it is.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testCreateBytesMessageFromDataWithEmptyBinaryAndContentType() throws Exception {
    Message message = Proton.message();
    Binary binary = new Binary(new byte[0]);
    message.setBody(new Data(binary));
    message.setContentType(AmqpMessageSupport.OCTET_STREAM_CONTENT_TYPE.toString());

    JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage();
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", JmsBytesMessage.class, jmsMessage.getClass());

    JmsMessageFacade facade = jmsMessage.getFacade();
    assertNotNull("Facade should not be null", facade);
    assertEquals("Unexpected facade class type", AmqpJmsBytesMessageFacade.class, facade.getClass());
}
 
Example #9
Source File: JMSMappingOutboundTransformerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertBytesMessageToAmqpMessageWithDataBody() throws Exception {
   byte[] expectedPayload = new byte[]{8, 16, 24, 32};
   ServerJMSBytesMessage outbound = createBytesMessage();
   outbound.writeBytes(expectedPayload);
   outbound.encode();

   AMQPMessage amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage(), null);

   assertNotNull(amqp.getBody());
   assertTrue(amqp.getBody() instanceof Data);
   assertTrue(((Data) amqp.getBody()).getValue() instanceof Binary);
   assertEquals(4, ((Data) amqp.getBody()).getValue().getLength());

   Binary amqpData = ((Data) amqp.getBody()).getValue();
   Binary inputData = new Binary(expectedPayload);

   assertTrue(inputData.equals(amqpData));
}
 
Example #10
Source File: AmqpCodecTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Test that a receiving a data body containing nothing and no content type being set
 * results in a BytesMessage when not otherwise annotated to indicate the type of
 * JMS message it is.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testCreateBytesMessageFromDataWithEmptyBinaryAndNoContentType() throws Exception {
    Message message = Proton.message();
    Binary binary = new Binary(new byte[0]);
    message.setBody(new Data(binary));

    assertNull(message.getContentType());

    JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage();
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", JmsBytesMessage.class, jmsMessage.getClass());

    JmsMessageFacade facade = jmsMessage.getFacade();
    assertNotNull("Facade should not be null", facade);
    assertEquals("Unexpected facade class type", AmqpJmsBytesMessageFacade.class, facade.getClass());
}
 
Example #11
Source File: AmqpDefaultMessageConverter.java    From strimzi-kafka-bridge with Apache License 2.0 6 votes vote down vote up
@Override
public Message toMessage(String address, KafkaConsumerRecord<String, byte[]> record) {

    Message message = Proton.message();
    message.setAddress(address);

    // put message annotations about partition, offset and key (if not null)
    Map<Symbol, Object> map = new HashMap<>();
    map.put(Symbol.valueOf(AmqpBridge.AMQP_PARTITION_ANNOTATION), record.partition());
    map.put(Symbol.valueOf(AmqpBridge.AMQP_OFFSET_ANNOTATION), record.offset());
    map.put(Symbol.valueOf(AmqpBridge.AMQP_KEY_ANNOTATION), record.key());
    map.put(Symbol.valueOf(AmqpBridge.AMQP_TOPIC_ANNOTATION), record.topic());

    MessageAnnotations messageAnnotations = new MessageAnnotations(map);
    message.setMessageAnnotations(messageAnnotations);

    message.setBody(new Data(new Binary(record.value())));

    return message;
}
 
Example #12
Source File: AmqpCodecTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Test that receiving a data body containing nothing, but with the content type set to
 * {@value AmqpMessageSupport#SERIALIZED_JAVA_OBJECT_CONTENT_TYPE} results in an ObjectMessage
 * when not otherwise annotated to indicate the type of JMS message it is.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testCreateObjectMessageFromDataWithContentTypeAndEmptyBinary() throws Exception {
    Message message = Proton.message();
    Binary binary = new Binary(new byte[0]);
    message.setBody(new Data(binary));
    message.setContentType(AmqpMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString());

    JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage();
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", JmsObjectMessage.class, jmsMessage.getClass());

    JmsMessageFacade facade = jmsMessage.getFacade();
    assertNotNull("Facade should not be null", facade);
    assertEquals("Unexpected facade class type", AmqpJmsObjectMessageFacade.class, facade.getClass());

    AmqpObjectTypeDelegate delegate = ((AmqpJmsObjectMessageFacade) facade).getDelegate();
    assertTrue("Unexpected delegate type: " + delegate, delegate instanceof AmqpSerializedObjectDelegate);
}
 
Example #13
Source File: AmqpJmsBytesMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testClearBodyWithExistingInputStream() throws Exception {
    byte[] bytes = "myBytes".getBytes();

    Message message = Message.Factory.create();
    message.setBody(new Data(new Binary(bytes)));
    AmqpJmsBytesMessageFacade amqpBytesMessageFacade = createReceivedBytesMessageFacade(createMockAmqpConsumer(), message);

    @SuppressWarnings("unused")
    InputStream unused = amqpBytesMessageFacade.getInputStream();

    amqpBytesMessageFacade.clearBody();

    assertEquals("Expected no data from facade, but got some", END_OF_STREAM, amqpBytesMessageFacade.getInputStream().read(new byte[1]));

    assertDataBodyAsExpected(amqpBytesMessageFacade.getBody(), 0);
}
 
Example #14
Source File: AmqpJmsBytesMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testInputStreamUsingReceivedMessageWithDataSection() throws Exception {
    byte[] bytes = "myBytes".getBytes();

    Message message = Message.Factory.create();
    message.setBody(new Data(new Binary(bytes)));

    AmqpJmsBytesMessageFacade amqpBytesMessageFacade = createReceivedBytesMessageFacade(createMockAmqpConsumer(), message);
    InputStream bytesStream = amqpBytesMessageFacade.getInputStream();
    assertNotNull(bytesStream);

    // retrieve the expected bytes, check they match
    byte[] receivedBytes = new byte[bytes.length];
    bytesStream.read(receivedBytes);
    assertTrue(Arrays.equals(bytes, receivedBytes));

    // verify no more bytes remain, i.e EOS
    assertEquals("Expected input stream to be at end but data was returned", END_OF_STREAM, bytesStream.read(new byte[1]));
}
 
Example #15
Source File: AbstractRequestResponseClientTest.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Verifies that the client creates and sends a message based on provided headers and payload
 * and sets a timer for canceling the request if no response is received.
 */
@Test
public void testCreateAndSendRequestSendsProperRequestMessage() {

    // GIVEN a request-response client that times out requests after 200 ms
    client.setRequestTimeout(200);

    // WHEN sending a request message with some headers and payload
    final JsonObject payload = new JsonObject().put("key", "value");
    final Map<String, Object> props = Collections.singletonMap("test-key", "test-value");
    client.createAndSendRequest("get", props, payload.toBuffer(), s -> {});

    // THEN the message is sent and the message being sent contains the headers as application properties
    final ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
    verify(sender).send(messageCaptor.capture(), VertxMockSupport.anyHandler());
    assertThat(messageCaptor.getValue()).isNotNull();
    assertThat(messageCaptor.getValue().getBody()).isNotNull();
    assertThat(messageCaptor.getValue().getBody()).isInstanceOf(Data.class);
    final Buffer body = MessageHelper.getPayload(messageCaptor.getValue());
    assertThat(body.getBytes()).isEqualTo(payload.toBuffer().getBytes());
    assertThat(messageCaptor.getValue().getApplicationProperties()).isNotNull();
    assertThat(messageCaptor.getValue().getApplicationProperties().getValue().get("test-key")).isEqualTo("test-value");
    // and a timer has been set to time out the request after 200 ms
    verify(vertx).setTimer(eq(200L), VertxMockSupport.anyHandler());
}
 
Example #16
Source File: AmqpJmsObjectMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Test that setting an object on a new message results in the expected
 * content in the body section of the underlying message.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testSetObjectOnNewMessage() throws Exception {
    String content = "myStringContent";

    AmqpJmsObjectMessageFacade amqpObjectMessageFacade = createNewObjectMessageFacade(false);
    amqpObjectMessageFacade.setObject(content);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(content);
    oos.flush();
    oos.close();
    byte[] bytes = baos.toByteArray();

    // retrieve the bytes from the underlying message, check they match expectation
    Section section = amqpObjectMessageFacade.getBody();
    assertNotNull(section);
    assertEquals(Data.class, section.getClass());
    assertArrayEquals("Underlying message data section did not contain the expected bytes", bytes, ((Data) section).getValue().getArray());
}
 
Example #17
Source File: JMSMappingOutboundTransformerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertObjectMessageToAmqpMessageWithDataBody() throws Exception {
   ServerJMSObjectMessage outbound = createObjectMessage(TEST_OBJECT_VALUE);
   outbound.encode();

   AMQPMessage amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage(), null);

   assertNotNull(amqp.getBody());
   assertTrue(amqp.getBody() instanceof Data);
   assertFalse(0 == ((Data) amqp.getBody()).getValue().getLength());

   Object value = deserialize(((Data) amqp.getBody()).getValue().getArray());
   assertNotNull(value);
   assertTrue(value instanceof UUID);
}
 
Example #18
Source File: AmqpJmsBytesMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testClearBodyWithExistingOutputStream() throws Exception {
    byte[] bytes = "myBytes".getBytes();

    Message message = Message.Factory.create();
    message.setBody(new Data(new Binary(bytes)));
    AmqpJmsBytesMessageFacade amqpBytesMessageFacade = createReceivedBytesMessageFacade(createMockAmqpConsumer(), message);

    @SuppressWarnings("unused")
    OutputStream unused = amqpBytesMessageFacade.getOutputStream();

    amqpBytesMessageFacade.clearBody();

    assertDataBodyAsExpected(amqpBytesMessageFacade.getBody(), 0);
}
 
Example #19
Source File: AmqpJmsBytesMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * Test that setting bytes on a received message results in the expected content in the body section
 * of the underlying message and returned by a new InputStream requested from the message.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testSetGetBodyOnReceivedMessage() throws Exception {
    byte[] orig = "myOrigBytes".getBytes();
    byte[] replacement = "myReplacementBytes".getBytes();

    Message message = Message.Factory.create();
    message.setBody(new Data(new Binary(orig)));
    AmqpJmsBytesMessageFacade amqpBytesMessageFacade = createReceivedBytesMessageFacade(createMockAmqpConsumer(), message);

    OutputStream os = amqpBytesMessageFacade.getOutputStream();
    os.write(replacement);

    amqpBytesMessageFacade.reset();

    // Retrieve the new Binary from the underlying message, check they match
    // (the backing arrays may be different length so not checking arrayEquals)
    Data body = (Data) amqpBytesMessageFacade.getBody();
    assertEquals("Underlying message data section did not contain the expected bytes", new Binary(replacement), body.getValue());

    assertEquals("expected body length to match replacement bytes", replacement.length, amqpBytesMessageFacade.getBodyLength());

    // retrieve the new bytes via an InputStream, check they match expected
    byte[] receivedBytes = new byte[replacement.length];
    InputStream bytesStream = amqpBytesMessageFacade.getInputStream();
    bytesStream.read(receivedBytes);
    assertTrue("Retrieved bytes from input steam did not match expected bytes", Arrays.equals(replacement, receivedBytes));

    // verify no more bytes remain, i.e EOS
    assertEquals("Expected input stream to be at end but data was returned", END_OF_STREAM, bytesStream.read(new byte[1]));
}
 
Example #20
Source File: AmqpJmsObjectMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * Test that clearing the body on a message results in the underlying body
 * section being set with the null object body, ensuring getObject returns null.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testClearBodyWithExistingSerializedBodySection() throws Exception {
    Message protonMessage = Message.Factory.create();
    protonMessage.setContentType(AmqpMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString());
    protonMessage.setBody(new Data(new Binary(new byte[0])));

    AmqpJmsObjectMessageFacade amqpObjectMessageFacade = createReceivedObjectMessageFacade(createMockAmqpConsumer(), protonMessage);

    assertNotNull("Expected existing body section to be found", amqpObjectMessageFacade.getBody());
    amqpObjectMessageFacade.clearBody();
    assertSame("Expected existing body section to be replaced", AmqpSerializedObjectDelegate.NULL_OBJECT_BODY, amqpObjectMessageFacade.getBody());
    assertNull("Expected null object", amqpObjectMessageFacade.getObject());
}
 
Example #21
Source File: AmqpJmsBytesMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetBodyLengthUsingReceivedMessageWithDataSectionContainingNonZeroLengthBinary() throws Exception {
    Message message = Message.Factory.create();
    int length = 5;
    message.setBody(new Data(new Binary(new byte[length])));
    AmqpJmsBytesMessageFacade amqpBytesMessageFacade = createReceivedBytesMessageFacade(createMockAmqpConsumer(), message);

    assertEquals("Message reports unexpected length", length, amqpBytesMessageFacade.getBodyLength());
}
 
Example #22
Source File: AmqpJmsTextMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTextUsingReceivedMessageWithZeroLengthDataSectionReturnsEmptyString() throws Exception {
    org.apache.qpid.proton.codec.Data payloadData = org.apache.qpid.proton.codec.Data.Factory.create();
    payloadData.putDescribedType(new DataDescribedType(new Binary(new byte[0])));
    Binary b = payloadData.encode();

    Message message = Message.Factory.create();
    int decoded = message.decode(b.getArray(), b.getArrayOffset(), b.getLength());
    assertEquals(decoded, b.getLength());
    AmqpJmsTextMessageFacade amqpTextMessageFacade = createReceivedTextMessageFacade(createMockAmqpConsumer(), message);

    assertEquals("expected zero-length string", "", amqpTextMessageFacade.getText());
}
 
Example #23
Source File: AMQPMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the AMQP Section that composes the body of this message by decoding a
 * fresh copy from the encoded message data.  Changes to the returned value are not
 * reflected in the value encoded in the original message.
 *
 * @return the Section that makes up the body of this message.
 */
public final Section getBody() {
   ensureScanning();

   // We only handle Sections of AmqpSequence, AmqpValue and Data types so we filter on those.
   // There could also be a Footer and no body so this will prevent a faulty return type in case
   // of no body or message type we don't handle.
   return scanForMessageSection(Math.max(0, remainingBodyPosition), AmqpSequence.class, AmqpValue.class, Data.class);
}
 
Example #24
Source File: JMSMappingInboundTransformerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Test that a data body containing nothing, but with the content type set to
 * {@value AMQPMessageSupport#OCTET_STREAM_CONTENT_TYPE} results in a BytesMessage when not
 * otherwise annotated to indicate the type of JMS message it is.
 *
 * @throws Exception
 *         if an error occurs during the test.
 */
@Test
public void testCreateBytesMessageFromDataWithEmptyBinaryAndContentType() throws Exception {
   MessageImpl message = (MessageImpl) Message.Factory.create();
   Binary binary = new Binary(new byte[0]);
   message.setBody(new Data(binary));
   message.setContentType(AMQPMessageSupport.OCTET_STREAM_CONTENT_TYPE);

   AMQPStandardMessage amqp = encodeAndCreateAMQPMessage(message);
   javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(amqp.toCore());

   assertNotNull("Message should not be null", jmsMessage);
   assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass());
}
 
Example #25
Source File: JMSMappingOutboundTransformerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertEmptyObjectMessageToAmqpMessageUnknownEncodingGetsDataSection() throws Exception {
   ServerJMSObjectMessage outbound = createObjectMessage();
   outbound.setShortProperty(JMS_AMQP_ORIGINAL_ENCODING, AMQP_UNKNOWN);
   outbound.encode();

   AMQPMessage amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage(), null);

   assertNotNull(amqp.getBody());
   assertTrue(amqp.getBody() instanceof Data);
   assertEquals(5, ((Data) amqp.getBody()).getValue().getLength());
}
 
Example #26
Source File: JMSMappingOutboundTransformerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertEmptyObjectMessageToAmqpMessageWithDataBody() throws Exception {
   ServerJMSObjectMessage outbound = createObjectMessage();
   outbound.encode();

   AMQPMessage amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage(), null);

   assertNotNull(amqp.getBody());
   assertTrue(amqp.getBody() instanceof Data);
   assertEquals(5, ((Data) amqp.getBody()).getValue().getLength());
}
 
Example #27
Source File: JMSMappingInboundTransformerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Test that a message with an empty data body section, and with the content type set to an
 * unknown value results in a BytesMessage when not otherwise annotated to indicate the type
 * of JMS message it is.
 *
 * @throws Exception
 *         if an error occurs during the test.
 */
@Test
public void testCreateBytesMessageFromDataWithUnknownContentType() throws Exception {
   MessageImpl message = (MessageImpl) Message.Factory.create();
   Binary binary = new Binary(new byte[0]);
   message.setBody(new Data(binary));
   message.setContentType("unknown-content-type");

   javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore());

   assertNotNull("Message should not be null", jmsMessage);
   assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass());
}
 
Example #28
Source File: JMSMappingInboundTransformerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Test that a receiving a data body containing nothing and no content type being set results
 * in a BytesMessage when not otherwise annotated to indicate the type of JMS message it is.
 *
 * @throws Exception
 *         if an error occurs during the test.
 */
@Test
public void testCreateBytesMessageFromDataWithEmptyBinaryAndNoContentType() throws Exception {
   MessageImpl message = (MessageImpl) Message.Factory.create();
   Binary binary = new Binary(new byte[0]);
   message.setBody(new Data(binary));

   assertNull(message.getContentType());

   javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore());

   assertNotNull("Message should not be null", jmsMessage);
   assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass());
}
 
Example #29
Source File: JMSMappingInboundTransformerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Test that receiving a data body containing nothing, but with the content type set to
 * {@value AMQPMessageSupport#SERIALIZED_JAVA_OBJECT_CONTENT_TYPE} results in an
 * ObjectMessage when not otherwise annotated to indicate the type of JMS message it is.
 *
 * @throws Exception
 *         if an error occurs during the test.
 */
@Test
public void testCreateObjectMessageFromDataWithContentTypeAndEmptyBinary() throws Exception {
   MessageImpl message = (MessageImpl) Message.Factory.create();
   Binary binary = new Binary(new byte[0]);
   message.setBody(new Data(binary));
   message.setContentType(AMQPMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString());

   javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore());

   assertNotNull("Message should not be null", jmsMessage);
   assertEquals("Unexpected message class type", ServerJMSObjectMessage.class, jmsMessage.getClass());
}
 
Example #30
Source File: JMSMappingInboundTransformerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void doCreateTextMessageFromDataWithContentTypeTestImpl(String contentType, Charset expectedCharset) throws Exception {
   MessageImpl message = (MessageImpl) Message.Factory.create();
   Binary binary = new Binary(new byte[0]);
   message.setBody(new Data(binary));
   message.setContentType(contentType);

   javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore());

   assertNotNull("Message should not be null", jmsMessage);
   if (StandardCharsets.UTF_8.equals(expectedCharset)) {
      assertEquals("Unexpected message class type", ServerJMSTextMessage.class, jmsMessage.getClass());
   } else {
      assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass());
   }
}