Search in sources :

Example 76 with TextMessage

use of javax.jms.TextMessage in project spring-framework by spring-projects.

the class SimpleMessageConverterTests method testStringConversion.

@Test
public void testStringConversion() throws JMSException {
    Session session = mock(Session.class);
    TextMessage message = mock(TextMessage.class);
    String content = "test";
    given(session.createTextMessage(content)).willReturn(message);
    given(message.getText()).willReturn(content);
    SimpleMessageConverter converter = new SimpleMessageConverter();
    Message msg = converter.toMessage(content, session);
    assertEquals(content, converter.fromMessage(msg));
}
Also used : TextMessage(javax.jms.TextMessage) MapMessage(javax.jms.MapMessage) ObjectMessage(javax.jms.ObjectMessage) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) SimpleMessageConverter(org.springframework.jms.support.converter.SimpleMessageConverter) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 77 with TextMessage

use of javax.jms.TextMessage in project spring-framework by spring-projects.

the class MappingJackson2MessageConverterTests method toTextMessageWithAnotherJsonViewClass.

@Test
public void toTextMessageWithAnotherJsonViewClass() throws JMSException {
    converter.setTargetType(MessageType.TEXT);
    TextMessage textMessageMock = mock(TextMessage.class);
    MyAnotherBean bean = new MyAnotherBean("test", "lengthy description");
    given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
    converter.toMessage(bean, sessionMock, Full.class);
    verify(textMessageMock).setStringProperty("__typeid__", MyAnotherBean.class.getName());
    verify(sessionMock).createTextMessage("{\"name\":\"test\",\"description\":\"lengthy description\"}");
}
Also used : TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 78 with TextMessage

use of javax.jms.TextMessage in project spring-framework by spring-projects.

the class MappingJackson2MessageConverterTests method toTextMessageWithObject.

@Test
public void toTextMessageWithObject() throws Exception {
    converter.setTargetType(MessageType.TEXT);
    TextMessage textMessageMock = mock(TextMessage.class);
    Date toBeMarshalled = new Date();
    given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
    converter.toMessage(toBeMarshalled, sessionMock);
    verify(textMessageMock).setStringProperty("__typeid__", Date.class.getName());
}
Also used : TextMessage(javax.jms.TextMessage) Date(java.util.Date) Test(org.junit.Test)

Example 79 with TextMessage

use of javax.jms.TextMessage in project spring-framework by spring-projects.

the class MappingJackson2MessageConverterTests method fromTextMessageAsMap.

@Test
public void fromTextMessageAsMap() throws Exception {
    TextMessage textMessageMock = mock(TextMessage.class);
    Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
    String text = "{\"foo\":\"bar\"}";
    given(textMessageMock.getStringProperty("__typeid__")).willReturn(HashMap.class.getName());
    given(textMessageMock.getText()).willReturn(text);
    Object result = converter.fromMessage(textMessageMock);
    assertEquals("Invalid result", result, unmarshalled);
}
Also used : HashMap(java.util.HashMap) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 80 with TextMessage

use of javax.jms.TextMessage in project spring-framework by spring-projects.

the class MappingJackson2MessageConverterTests method toTextMessageWithJsonViewClass.

@Test
public void toTextMessageWithJsonViewClass() throws JMSException {
    converter.setTargetType(MessageType.TEXT);
    TextMessage textMessageMock = mock(TextMessage.class);
    MyAnotherBean bean = new MyAnotherBean("test", "lengthy description");
    given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
    converter.toMessage(bean, sessionMock, Summary.class);
    verify(textMessageMock).setStringProperty("__typeid__", MyAnotherBean.class.getName());
    verify(sessionMock).createTextMessage("{\"name\":\"test\"}");
}
Also used : TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Aggregations

TextMessage (javax.jms.TextMessage)231 Test (org.junit.Test)92 Session (javax.jms.Session)75 MessageProducer (javax.jms.MessageProducer)71 Message (javax.jms.Message)70 JMSException (javax.jms.JMSException)64 Connection (javax.jms.Connection)44 Destination (javax.jms.Destination)44 MessageConsumer (javax.jms.MessageConsumer)44 ObjectMessage (javax.jms.ObjectMessage)25 BytesMessage (javax.jms.BytesMessage)22 Queue (javax.jms.Queue)21 QueueSession (javax.jms.QueueSession)20 StubTextMessage (org.springframework.jms.StubTextMessage)18 ConnectionFactory (javax.jms.ConnectionFactory)13 QueueConnection (javax.jms.QueueConnection)13 CountDownLatch (java.util.concurrent.CountDownLatch)12 MapMessage (javax.jms.MapMessage)11 Topic (javax.jms.Topic)11 JMSContext (javax.jms.JMSContext)9