org.apache.qpid.jms.message.JmsMessage Java Examples
The following examples show how to use
org.apache.qpid.jms.message.JmsMessage.
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: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * Test that a message with the {@value AmqpMessageSupport#JMS_MSG_TYPE} * annotation set to {@value AmqpMessageSupport#JMS_MESSAGE} is * treated as a generic {@link JmsMessage} with {@link AmqpJmsMessageFacade} * * @throws Exception if an error occurs during the test. */ @Test public void testCreateGenericMessageFromMessageTypeAnnotation() throws Exception { Message message = Proton.message(); Map<Symbol, Object> map = new HashMap<Symbol, Object>(); map.put(AmqpMessageSupport.JMS_MSG_TYPE, AmqpMessageSupport.JMS_MESSAGE); MessageAnnotations messageAnnotations = new MessageAnnotations(map); message.setMessageAnnotations(messageAnnotations); JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsMessage.class, jmsMessage.getClass()); JmsMessageFacade facade = jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertEquals("Unexpected facade class type", AmqpJmsMessageFacade.class, facade.getClass()); }
Example #2
Source File: AmqpPublisherActorTest.java From ditto with Eclipse Public License 2.0 | 6 votes |
@Override protected void verifyPublishedMessage() throws Exception { final ArgumentCaptor<JmsMessage> messageCaptor = ArgumentCaptor.forClass(JmsMessage.class); verify(messageProducer, timeout(1000)).send(messageCaptor.capture(), any(CompletionListener.class)); final Message message = messageCaptor.getValue(); assertThat(message).isNotNull(); assertThat(message.getStringProperty("thing_id")).isEqualTo(TestConstants.Things.THING_ID.toString()); assertThat(message.getStringProperty("suffixed_thing_id")).isEqualTo( TestConstants.Things.THING_ID + ".some.suffix"); assertThat(message.getStringProperty("prefixed_thing_id")).isEqualTo( "some.prefix." + TestConstants.Things.THING_ID); assertThat(message.getStringProperty("eclipse")).isEqualTo("ditto"); assertThat(message.getStringProperty("device_id")) .isEqualTo(TestConstants.Things.THING_ID.toString()); }
Example #3
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * Test that an amqp-value body containing a map 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 testCreateAmqpObjectMessageFromAmqpValueWithMap() throws Exception { Message message = Proton.message(); Map<String, String> map = new HashMap<String,String>(); message.setBody(new AmqpValue(map)); 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 AmqpTypedObjectDelegate); }
Example #4
Source File: InterconnectReadData.java From maestro-java with Apache License 2.0 | 6 votes |
/** * Create request message * @param component string representation component name * @return created message * @throws JMSException if unable to create message */ private Message createMessage(String component) throws JMSException { logger.debug("Creating request message for: {}", component); Message message = session.createObjectMessage(); message.setBooleanProperty("JMS_AMQP_TYPED_ENCODING", true); message.setStringProperty("name", "self"); message.setStringProperty("operation", "QUERY"); message.setStringProperty("type", "org.amqp.management"); Binary requestFor = new Binary(("org.apache.qpid.dispatch." + component).getBytes()); ((JmsMessage) message).getFacade().setProperty("entityType", requestFor); HashMap<String,Object> map = new HashMap<>(); map.put("attributeNames", new ArrayList<>()); ((ObjectMessage) message).setObject(map); message.setJMSReplyTo(destination); return message; }
Example #5
Source File: AmqpClientActorTest.java From ditto with Eclipse Public License 2.0 | 6 votes |
private void prepareSession(final Session mockSession, final JmsMessageConsumer mockConsumer) throws JMSException { doReturn(mockConsumer).when(mockSession).createConsumer(any(JmsQueue.class)); doAnswer((Answer<MessageProducer>) destinationInv -> { final MessageProducer messageProducer = mock(MessageProducer.class); doReturn(destinationInv.getArgument(0)).when(messageProducer).getDestination(); mockProducers.add(messageProducer); return messageProducer; }).when(mockSession).createProducer(any(Destination.class)); doAnswer((Answer<JmsMessage>) textMsgInv -> { final String textMsg = textMsgInv.getArgument(0); final AmqpJmsTextMessageFacade facade = new AmqpJmsTextMessageFacade(); facade.initialize(Mockito.mock(AmqpConnection.class)); final JmsTextMessage jmsTextMessage = new JmsTextMessage(facade); jmsTextMessage.setText(textMsg); return jmsTextMessage; }).when(mockSession).createTextMessage(anyString()); }
Example #6
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * Test that an amqp-value body containing a list 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 testCreateAmqpObjectMessageFromAmqpValueWithList() throws Exception { Message message = Proton.message(); List<String> list = new ArrayList<String>(); message.setBody(new AmqpValue(list)); 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 AmqpTypedObjectDelegate); }
Example #7
Source File: JmsProducerTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testBytesBodyIsApplied() throws JMSException { JMSProducer producer = context.createProducer(); final byte[] bodyValue = new byte[] { 0, 1, 2, 3, 4 }; producer.send(JMS_DESTINATION, bodyValue); JmsOutboundMessageDispatch envelope = remotePeer.getLastReceivedMessage(); assertNotNull(envelope); JmsMessage message = envelope.getMessage(); byte[] payload = message.getBody(byte[].class); assertNotNull(payload); assertEquals(bodyValue.length, payload.length); for (int i = 0; i < payload.length; ++i) { assertEquals(bodyValue[i], payload[i]); } }
Example #8
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * Test that an amqp-value body containing a value which can't be categorised 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 testCreateObjectMessageFromAmqpValueWithUncategorisedContent() throws Exception { Message message = Proton.message(); message.setBody(new AmqpValue(UUID.randomUUID())); 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 AmqpTypedObjectDelegate); }
Example #9
Source File: AmqpConsumerActor.java From ditto with Eclipse Public License 2.0 | 6 votes |
private ExternalMessageBuilder extractPayloadFromMessage(final JmsMessage message, final ExternalMessageBuilder builder) throws JMSException { if (message instanceof TextMessage) { final String payload = ((TextMessage) message).getText(); builder.withText(payload); } else if (message instanceof BytesMessage) { final BytesMessage bytesMessage = (BytesMessage) message; final long bodyLength = bytesMessage.getBodyLength(); if (bodyLength >= Integer.MIN_VALUE && bodyLength <= Integer.MAX_VALUE) { final int length = (int) bodyLength; final ByteBuffer byteBuffer = ByteBuffer.allocate(length); bytesMessage.readBytes(byteBuffer.array()); builder.withBytes(byteBuffer); } else { throw new IllegalArgumentException("Message too large..."); } } else { if (log.isDebugEnabled()) { final Destination destination = message.getJMSDestination(); final Map<String, String> headersMapFromJmsMessage = extractHeadersMapFromJmsMessage(message); log.debug("Received message at '{}' of unsupported type ({}) with headers: {}", destination, message.getClass().getName(), headersMapFromJmsMessage); } } return builder; }
Example #10
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * Test that an amqp-sequence body containing a binary value 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 testCreateObjectMessageMessageFromAmqpSequence() throws Exception { Message message = Proton.message(); List<String> list = new ArrayList<String>(); message.setBody(new AmqpSequence(list)); 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 AmqpTypedObjectDelegate); }
Example #11
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testMessagePrioritySetFromMessageWithNonDefaultValue() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); message.setPriority((short) 8); message.setBody(new AmqpValue("test")); JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsTextMessage.class, jmsMessage.getClass()); assertEquals(8, jmsMessage.getJMSPriority()); JmsMessageFacade facade = jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, facade.getClass()); assertEquals(8, facade.getPriority()); }
Example #12
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testPersistentSetFromMessageWithNonDefaultValue() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); message.setDurable(true); message.setBody(new AmqpValue("test")); JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsTextMessage.class, jmsMessage.getClass()); assertEquals(DeliveryMode.PERSISTENT, jmsMessage.getJMSDeliveryMode()); JmsMessageFacade facade = jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, facade.getClass()); assertTrue(facade.isPersistent()); }
Example #13
Source File: AmqpPublisherActor.java From ditto with Eclipse Public License 2.0 | 6 votes |
private Message toJmsMessage(final ExternalMessage externalMessage) throws JMSException { final Message message; final Optional<String> optTextPayload = externalMessage.getTextPayload(); if (optTextPayload.isPresent()) { message = session.createTextMessage(optTextPayload.get()); } else if (externalMessage.getBytePayload().isPresent()) { final BytesMessage bytesMessage = session.createBytesMessage(); bytesMessage.writeBytes(externalMessage.getBytePayload().map(ByteBuffer::array).orElse(new byte[]{})); message = bytesMessage; } else { message = session.createMessage(); } JMSPropertyMapper.setPropertiesAndApplicationProperties(message, externalMessage.getHeaders(), log); // wrap the message to prevent Qpid client from setting properties willy-nilly. return JMSMessageWorkaround.wrap((JmsMessage) message); }
Example #14
Source File: AmqpClientActorTest.java From ditto with Eclipse Public License 2.0 | 6 votes |
private static void sendThingEventAndExpectPublish(final ActorRef amqpClientActor, final Target target, final Supplier<MessageProducer> messageProducerSupplier) throws JMSException { final String uuid = UUID.randomUUID().toString(); final ThingModifiedEvent thingModifiedEvent = TestConstants.thingModified(Collections.emptyList(), Attributes.newBuilder().set("uuid", uuid).build()) .setDittoHeaders(DittoHeaders.newBuilder().putHeader("reply-to", target.getAddress()).build()); final OutboundSignal outboundSignal = OutboundSignalFactory.newOutboundSignal(thingModifiedEvent, singletonList(target)); amqpClientActor.tell(outboundSignal, ActorRef.noSender()); final ArgumentCaptor<JmsMessage> messageCaptor = ArgumentCaptor.forClass(JmsMessage.class); final MessageProducer messageProducer = messageProducerSupplier.get(); verify(messageProducer, timeout(2000).times(1)) .send(messageCaptor.capture(), any(CompletionListener.class)); final Message message = messageCaptor.getValue(); assertThat(message).isNotNull(); assertThat(message.getBody(String.class)).contains(uuid); assertThat(message.getBody(String.class)).contains( TestConstants.Things.NAMESPACE + "/" + TestConstants.Things.ID + "/" + TopicPath.Group.THINGS.getName() + "/" + TopicPath.Channel.TWIN.getName() + "/" + TopicPath.Criterion.EVENTS.getName() + "/" + TopicPath.Action.MODIFIED.getName()); }
Example #15
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * 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 #16
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * 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 #17
Source File: JmsProducerTest.java From qpid-jms with Apache License 2.0 | 6 votes |
private void doTestSendAppliesTimeToLiveWithMessageBody(Class<?> bodyType) throws JMSException { JMSProducer producer = context.createProducer(); producer.setTimeToLive(2000); producer.send(JMS_DESTINATION, "text"); JmsOutboundMessageDispatch envelope = remotePeer.getLastReceivedMessage(); assertNotNull(envelope); JmsMessage message = envelope.getMessage(); assertTrue(message.getJMSExpiration() > 0); producer.setTimeToLive(Message.DEFAULT_TIME_TO_LIVE); producer.send(JMS_DESTINATION, "text"); envelope = remotePeer.getLastReceivedMessage(); assertNotNull(envelope); message = envelope.getMessage(); assertTrue(message.getJMSExpiration() == 0); }
Example #18
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * 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 #19
Source File: JmsProducerTest.java From qpid-jms with Apache License 2.0 | 6 votes |
private void doTestSendAppliesPriorityWithMessageBody(Class<?> bodyType) throws JMSException { JMSProducer producer = context.createProducer(); producer.setPriority(0); producer.send(JMS_DESTINATION, "text"); JmsOutboundMessageDispatch envelope = remotePeer.getLastReceivedMessage(); assertNotNull(envelope); JmsMessage message = envelope.getMessage(); assertEquals(0, message.getJMSPriority()); producer.setPriority(7); producer.send(JMS_DESTINATION, "text"); envelope = remotePeer.getLastReceivedMessage(); assertNotNull(envelope); message = envelope.getMessage(); assertEquals(7, message.getJMSPriority()); }
Example #20
Source File: JmsProducerTest.java From qpid-jms with Apache License 2.0 | 6 votes |
private void doTestSendAppliesDisableTimestampWithMessageBody(Class<?> bodyType) throws JMSException { JMSProducer producer = context.createProducer(); producer.setDisableMessageTimestamp(true); producer.send(JMS_DESTINATION, "text"); JmsOutboundMessageDispatch envelope = remotePeer.getLastReceivedMessage(); assertNotNull(envelope); JmsMessage message = envelope.getMessage(); assertTrue(message.getJMSTimestamp() == 0); producer.setDisableMessageTimestamp(false); producer.send(JMS_DESTINATION, "text"); envelope = remotePeer.getLastReceivedMessage(); assertNotNull(envelope); message = envelope.getMessage(); assertFalse(message.getJMSTimestamp() == 0); }
Example #21
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * Test that a message with no body section, 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 testCreateObjectMessageFromNoBodySectionAndContentType() throws Exception { Message message = Proton.message(); 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 #22
Source File: JmsProducerTest.java From qpid-jms with Apache License 2.0 | 6 votes |
private void doTestSendAppliesDisableMessageIDWithMessageBody(Class<?> bodyType) throws JMSException { JMSProducer producer = context.createProducer(); producer.setDisableMessageID(true); producer.send(JMS_DESTINATION, "text"); JmsOutboundMessageDispatch envelope = remotePeer.getLastReceivedMessage(); assertNotNull(envelope); JmsMessage message = envelope.getMessage(); assertNull(message.getJMSMessageID()); producer.setDisableMessageID(false); producer.send(JMS_DESTINATION, "text"); envelope = remotePeer.getLastReceivedMessage(); assertNotNull(envelope); message = envelope.getMessage(); assertNotNull(message.getJMSMessageID()); }
Example #23
Source File: JmsProducerTest.java From qpid-jms with Apache License 2.0 | 6 votes |
public void doTestSendAppliesDeliveryModeWithMessageBody(Class<?> bodyType) throws JMSException { JMSProducer producer = context.createProducer(); producer.setDeliveryMode(DeliveryMode.PERSISTENT); producer.send(JMS_DESTINATION, "text"); JmsOutboundMessageDispatch envelope = remotePeer.getLastReceivedMessage(); assertNotNull(envelope); JmsMessage message = envelope.getMessage(); assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode()); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); producer.send(JMS_DESTINATION, "text"); envelope = remotePeer.getLastReceivedMessage(); assertNotNull(envelope); message = envelope.getMessage(); assertEquals(DeliveryMode.NON_PERSISTENT, message.getJMSDeliveryMode()); }
Example #24
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * Test that a message with the {@value AmqpMessageSupport#JMS_MSG_TYPE} * annotation set to {@value AmqpMessageSupport#JMS_STREAM_MESSAGE} is * treated as a {@link JmsStreamMessage} with {@link AmqpJmsStreamMessageFacade} * * @throws Exception if an error occurs during the test. */ @Test public void testCreateStreamMessageFromMessageTypeAnnotation() throws Exception { Message message = Proton.message(); Map<Symbol, Object> map = new HashMap<Symbol, Object>(); map.put(AmqpMessageSupport.JMS_MSG_TYPE, AmqpMessageSupport.JMS_STREAM_MESSAGE); MessageAnnotations messageAnnotations = new MessageAnnotations(map); message.setMessageAnnotations(messageAnnotations); JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsStreamMessage.class, jmsMessage.getClass()); JmsMessageFacade facade = jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertEquals("Unexpected facade class type", AmqpJmsStreamMessageFacade.class, facade.getClass()); }
Example #25
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testDeliveryCountSetFromMessageWithNonDefaultValue() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); message.setDeliveryCount(2); message.setBody(new AmqpValue("test")); JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsTextMessage.class, jmsMessage.getClass()); assertTrue(jmsMessage.getJMSRedelivered()); assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, jmsMessage.getFacade().getClass()); AmqpJmsTextMessageFacade facade = (AmqpJmsTextMessageFacade) jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertEquals(2, facade.getRedeliveryCount()); assertEquals(2, facade.getAmqpHeader().getDeliveryCount()); assertEquals(UnsignedInteger.valueOf(2), facade.getHeader().getDeliveryCount()); }
Example #26
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * Test that a message with the {@value AmqpMessageSupport#JMS_MSG_TYPE} * annotation set to {@value AmqpMessageSupport#JMS_BYTES_MESSAGE} is * treated as a {@link JmsTextMessage} with {@link AmqpJmsTextMessageFacade} * * @throws Exception if an error occurs during the test. */ @Test public void testCreateTextMessageFromMessageTypeAnnotation() throws Exception { Message message = Proton.message(); Map<Symbol, Object> map = new HashMap<Symbol, Object>(); map.put(AmqpMessageSupport.JMS_MSG_TYPE, AmqpMessageSupport.JMS_TEXT_MESSAGE); MessageAnnotations messageAnnotations = new MessageAnnotations(map); message.setMessageAnnotations(messageAnnotations); JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsTextMessage.class, jmsMessage.getClass()); JmsMessageFacade facade = jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, facade.getClass()); }
Example #27
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * Test that a message with the {@value AmqpMessageSupport#JMS_MSG_TYPE} * annotation set to {@value AmqpMessageSupport#JMS_BYTES_MESSAGE} is * treated as a {@link JmsBytesMessage} with {@link AmqpJmsBytesMessageFacade} * * @throws Exception if an error occurs during the test. */ @Test public void testCreateBytesMessageFromMessageTypeAnnotation() throws Exception { Message message = Proton.message(); Map<Symbol, Object> map = new HashMap<Symbol, Object>(); map.put(AmqpMessageSupport.JMS_MSG_TYPE, AmqpMessageSupport.JMS_BYTES_MESSAGE); MessageAnnotations messageAnnotations = new MessageAnnotations(map); message.setMessageAnnotations(messageAnnotations); 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 #28
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
private void doCreateTextMessageFromDataWithContentTypeTestImpl(String contentType, Charset expectedCharset) throws IOException { Message message = Proton.message(); Binary binary = new Binary(new byte[0]); message.setBody(new Data(binary)); message.setContentType(contentType); JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsTextMessage.class, jmsMessage.getClass()); JmsMessageFacade facade = jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, facade.getClass()); AmqpJmsTextMessageFacade textFacade = (AmqpJmsTextMessageFacade) facade; assertEquals("Unexpected character set", expectedCharset, textFacade.getCharset()); }
Example #29
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test public void testTimeToLiveSetFromMessageWithNonDefaultValue() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); message.setTtl(65535); message.setBody(new AmqpValue("test")); JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsTextMessage.class, jmsMessage.getClass()); assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, jmsMessage.getFacade().getClass()); AmqpJmsTextMessageFacade facade = (AmqpJmsTextMessageFacade) jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertEquals(65535, facade.getAmqpHeader().getTimeToLive()); }
Example #30
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 5 votes |
/** * Test that a message with no body section, and with the content type set to * an unknown value results in a plain Message when not otherwise annotated to * indicate the type of JMS message it is. * * @throws Exception if an error occurs during the test. */ public void testCreateGenericMessageFromNoBodySectionAndUnknownContentType() throws Exception { Message message = Proton.message(); message.setContentType("unknown-content-type"); JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsMessage.class, jmsMessage.getClass()); JmsMessageFacade facade = jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertEquals("Unexpected facade class type", AmqpJmsMessageFacade.class, facade.getClass()); }