本文整理汇总了Java中org.springframework.jms.support.converter.SimpleMessageConverter.toMessage方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleMessageConverter.toMessage方法的具体用法?Java SimpleMessageConverter.toMessage怎么用?Java SimpleMessageConverter.toMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.jms.support.converter.SimpleMessageConverter
的用法示例。
在下文中一共展示了SimpleMessageConverter.toMessage方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testByteArrayConversion
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入方法依赖的package包/类
@Test
public void testByteArrayConversion() throws JMSException {
Session session = mock(Session.class);
BytesMessage message = mock(BytesMessage.class);
byte[] content = "test".getBytes();
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content);
given(session.createBytesMessage()).willReturn(message);
given(message.getBodyLength()).willReturn((long) content.length);
given(message.readBytes(any(byte[].class))).willAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
return byteArrayInputStream.read((byte[]) invocation.getArguments()[0]);
}
});
SimpleMessageConverter converter = new SimpleMessageConverter();
Message msg = converter.toMessage(content, session);
assertEquals(content.length, ((byte[]) converter.fromMessage(msg)).length);
verify(message).writeBytes(content);
}
示例2: testMapConversion
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入方法依赖的package包/类
@Test
public void testMapConversion() throws JMSException {
Session session = mock(Session.class);
MapMessage message = mock(MapMessage.class);
Map<String, String> content = new HashMap<String, String>(2);
content.put("key1", "value1");
content.put("key2", "value2");
given(session.createMapMessage()).willReturn(message);
given(message.getMapNames()).willReturn(Collections.enumeration(content.keySet()));
given(message.getObject("key1")).willReturn("value1");
given(message.getObject("key2")).willReturn("value2");
SimpleMessageConverter converter = new SimpleMessageConverter();
Message msg = converter.toMessage(content, session);
assertEquals(content, converter.fromMessage(msg));
verify(message).setObject("key1", "value1");
verify(message).setObject("key2", "value2");
}
示例3: testMapConversionWhereMapHasNonStringTypesForKeys
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入方法依赖的package包/类
@Test
public void testMapConversionWhereMapHasNonStringTypesForKeys() throws JMSException {
MapMessage message = mock(MapMessage.class);
final Session session = mock(Session.class);
given(session.createMapMessage()).willReturn(message);
final Map<Integer, String> content = new HashMap<Integer, String>(1);
content.put(1, "value1");
final SimpleMessageConverter converter = new SimpleMessageConverter();
try {
converter.toMessage(content, session);
fail("expected MessageConversionException");
} catch (MessageConversionException ex) { /* expected */ }
}
示例4: testMapConversion
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入方法依赖的package包/类
@Test
public void testMapConversion() throws JMSException {
Session session = mock(Session.class);
MapMessage message = mock(MapMessage.class);
Map content = new HashMap();
content.put("key1", "value1");
content.put("key2", "value2");
given(session.createMapMessage()).willReturn(message);
given(message.getMapNames()).willReturn(Collections.enumeration(content.keySet()));
given(message.getObject("key1")).willReturn("value1");
given(message.getObject("key2")).willReturn("value2");
SimpleMessageConverter converter = new SimpleMessageConverter();
Message msg = converter.toMessage(content, session);
assertEquals(content, converter.fromMessage(msg));
verify(message).setObject("key1", "value1");
verify(message).setObject("key2", "value2");
}
示例5: testMapConversionWhereMapHasNonStringTypesForKeys
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入方法依赖的package包/类
@Test
public void testMapConversionWhereMapHasNonStringTypesForKeys() throws JMSException {
MapMessage message = mock(MapMessage.class);
final Session session = mock(Session.class);
given(session.createMapMessage()).willReturn(message);
final Map content = new HashMap();
content.put(new Integer(1), "value1");
final SimpleMessageConverter converter = new SimpleMessageConverter();
try {
converter.toMessage(content, session);
fail("expected MessageConversionException");
} catch (MessageConversionException ex) { /* expected */ }
}
示例6: testMapConversionWhereMapHasNNullForKey
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入方法依赖的package包/类
@Test
public void testMapConversionWhereMapHasNNullForKey() throws JMSException {
MapMessage message = mock(MapMessage.class);
final Session session = mock(Session.class);
given(session.createMapMessage()).willReturn(message);
final Map content = new HashMap();
content.put(null, "value1");
final SimpleMessageConverter converter = new SimpleMessageConverter();
try {
converter.toMessage(content, session);
fail("expected MessageConversionException");
} catch (MessageConversionException ex) { /* expected */ }
}
示例7: testStringConversion
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入方法依赖的package包/类
@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));
}
示例8: testSerializableConversion
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入方法依赖的package包/类
@Test
public void testSerializableConversion() throws JMSException {
Session session = mock(Session.class);
ObjectMessage message = mock(ObjectMessage.class);
Integer content = new Integer(5);
given(session.createObjectMessage(content)).willReturn(message);
given(message.getObject()).willReturn(content);
SimpleMessageConverter converter = new SimpleMessageConverter();
Message msg = converter.toMessage(content, session);
assertEquals(content, converter.fromMessage(msg));
}
示例9: testToMessageSimplyReturnsMessageAsIsIfSuppliedWithMessage
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入方法依赖的package包/类
@Test
public void testToMessageSimplyReturnsMessageAsIsIfSuppliedWithMessage() throws JMSException {
Session session = mock(Session.class);
ObjectMessage message = mock(ObjectMessage.class);
SimpleMessageConverter converter = new SimpleMessageConverter();
Message msg = converter.toMessage(message, session);
assertSame(message, msg);
}
示例10: testMapConversionWhereMapHasNNullForKey
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入方法依赖的package包/类
@Test
public void testMapConversionWhereMapHasNNullForKey() throws JMSException {
MapMessage message = mock(MapMessage.class);
final Session session = mock(Session.class);
given(session.createMapMessage()).willReturn(message);
final Map<Object, String> content = new HashMap<Object, String>(1);
content.put(null, "value1");
final SimpleMessageConverter converter = new SimpleMessageConverter();
try {
converter.toMessage(content, session);
fail("expected MessageConversionException");
} catch (MessageConversionException ex) { /* expected */ }
}