Java Code Examples for org.apache.qpid.proton.message.Message#setProperties()

The following examples show how to use org.apache.qpid.proton.message.Message#setProperties() . 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: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Check that getting the ReplyToGroupId returns the expected value from a
 * received messages with a reply-to-group-id.
 */
@Test
public void testGetReplyToGroupIdWithReceivedMessage() {
    String replyToGroupId = "myReplyGroup";

    Message message = Proton.message();

    Properties props = new Properties();
    props.setReplyToGroupId(replyToGroupId);
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    String actual = amqpMessageFacade.getReplyToGroupId();
    assertNotNull("expected ReplyToGroupId on message was not found", actual);
    assertEquals("expected ReplyToGroupId on message was not found", replyToGroupId, actual);
}
 
Example 2
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDestinationWithReceivedMessage() throws JMSException {
    String testToAddress = "myTestAddress";

    Message message = Proton.message();

    Properties props = new Properties();
    props.setTo(testToAddress);
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    JmsDestination dest = amqpMessageFacade.getDestination();
    //We didn't set any destination type annotations, so the consumer destination type will be used: a topic.
    assertTrue(dest instanceof Topic);
    assertEquals(testToAddress, ((Topic) dest).getTopicName());
}
 
Example 3
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetReplyToWithReceivedMessage() throws JMSException {
    String testReplyToAddress = "myTestReplyTo";

    Message message = Proton.message();

    Properties props = new Properties();
    props.setReplyTo(testReplyToAddress);
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    JmsDestination dest = amqpMessageFacade.getReplyTo();
    //We didn't set any destination type annotations, so the consumer destination type will be used: a topic.
    assertTrue(dest instanceof Topic);
    assertEquals(testReplyToAddress, ((Topic) dest).getTopicName());
}
 
Example 4
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
private void correlationIdOnReceivedMessageTestImpl(final Object testCorrelationId, final String expected, boolean appSpecificCorrelationId) {
    Message message = Proton.message();

    Properties props = new Properties();
    props.setCorrelationId(testCorrelationId);
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    String result = amqpMessageFacade.getCorrelationId();
    assertNotNull("Expected a correlationId on received message", result);
    assertEquals("Incorrect correlationId value received", expected, result);
    if(!appSpecificCorrelationId) {
        assertTrue("Should have have 'ID:' prefix", result.startsWith(AmqpMessageIdHelper.JMS_ID_PREFIX));
    }
}
 
Example 5
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
private void messageIdOnReceivedMessageTestImpl(Object underlyingMessageId, String expected) {
    if (!(underlyingMessageId == null || underlyingMessageId instanceof Binary
            || underlyingMessageId instanceof UnsignedLong || underlyingMessageId instanceof String || underlyingMessageId instanceof UUID)) {
        throw new IllegalArgumentException("invalid id type");
    }

    Message message = Proton.message();

    Properties props = new Properties();
    props.setMessageId(underlyingMessageId);
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertNotNull("Expected a messageId on received message", amqpMessageFacade.getMessageId());

    assertEquals("Incorrect messageId value received", expected, amqpMessageFacade.getMessageId());
}
 
Example 6
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetUserIdOnReceievedMessage() throws Exception {
    String userIdString = "testValue";
    byte[] bytes = userIdString.getBytes("UTF-8");

    Message message = Proton.message();

    Properties props = new Properties();
    props.setUserId(new Binary(bytes));
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertNotNull("Expected a userid on received message", amqpMessageFacade.getUserId());
    assertEquals("Incorrect messageId value received", userIdString, amqpMessageFacade.getUserId());
}
 
Example 7
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetUserIdBytesOnReceievedMessage() throws Exception {
    String userIdString = "testValue";
    byte[] bytes = userIdString.getBytes("UTF-8");

    Message message = Proton.message();

    message.setUserId(bytes);

    Properties props = new Properties();
    props.setUserId(new Binary(bytes));
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertNotNull("Expected a userid on received message", amqpMessageFacade.getUserIdBytes());
    assertArrayEquals("Incorrect userid bytes value received", bytes, amqpMessageFacade.getUserIdBytes());
}
 
Example 8
Source File: MessageHelper.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns a copy of the given message.
 * <p>
 * This is a shallow copy of the <em>Message</em> object, except for the copied <em>Properties</em>.
 *
 * @param message The message to copy.
 * @return The message copy.
 */
public static Message getShallowCopy(final Message message) {
    final Message copy = ProtonHelper.message();
    copy.setDeliveryAnnotations(message.getDeliveryAnnotations());
    copy.setMessageAnnotations(message.getMessageAnnotations());
    if (message.getProperties() != null) {
        copy.setProperties(new Properties(message.getProperties()));
    }
    copy.setApplicationProperties(message.getApplicationProperties());
    copy.setBody(message.getBody());
    copy.setFooter(message.getFooter());
    return copy;
}
 
Example 9
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * Check that getting the ReplyToGroupId works on received messages with a
 * properties section, but no reply-to-group-id
 */
@Test
public void testGetReplyToGroupIdWithReceivedMessageWithPropertiesButNoReplyToGroupId() {
    Message message = Proton.message();

    Properties props = new Properties();
    props.setContentType(Symbol.valueOf("content-type"));
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    String replyToGroupId = amqpMessageFacade.getReplyToGroupId();
    assertNull("expected ReplyToGroupId to be null on message with properties section but no reply-to-group-id", replyToGroupId);
}
 
Example 10
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetGroupSequenceOnReceivedMessageWithGroupSequenceJustAboveSignedIntRange() {
    Message message = Proton.message();

    Properties props = new Properties();
    props.setGroupSequence(UnsignedInteger.valueOf(1L + Integer.MAX_VALUE));
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    // The unsigned int value >= 2^31 will be represented as a negative, and so should begin from minimum signed int value
    assertEquals("GroupSequence not as expected", Integer.MIN_VALUE, amqpMessageFacade.getGroupSequence());
}
 
Example 11
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetGroupSequenceOnReceivedMessageWithGroupSequenceMaxUnsignedIntValue() {
    Message message = Proton.message();

    Properties props = new Properties();
    props.setGroupSequence(UnsignedInteger.valueOf(MAX_UINT));
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    // The unsigned int value 2^32-1 will be represented as a negative, and should be the largest such value, -1
    assertEquals("GroupSequence not as expected", -1, amqpMessageFacade.getGroupSequence());
}
 
Example 12
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetUserIdOnReceievedMessageWithEmptyBinaryValue() throws Exception {
    byte[] bytes = new byte[0];

    Message message = Proton.message();

    Properties props = new Properties();
    props.setUserId(new Binary(bytes));
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertNull("Expected a userid on received message", amqpMessageFacade.getUserId());
}