本文整理汇总了Java中org.springframework.jms.support.converter.SimpleMessageConverter类的典型用法代码示例。如果您正苦于以下问题:Java SimpleMessageConverter类的具体用法?Java SimpleMessageConverter怎么用?Java SimpleMessageConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleMessageConverter类属于org.springframework.jms.support.converter包,在下文中一共展示了SimpleMessageConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: convertAndSendCustomJmsMessageConverter
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入依赖的package包/类
@Test
public void convertAndSendCustomJmsMessageConverter() throws JMSException {
messagingTemplate.setJmsMessageConverter(new SimpleMessageConverter() {
@Override
public javax.jms.Message toMessage(Object object, Session session)
throws JMSException, org.springframework.jms.support.converter.MessageConversionException {
throw new org.springframework.jms.support.converter.MessageConversionException("Test exception");
}
});
messagingTemplate.convertAndSend("myQueue", "msg to convert");
verify(jmsTemplate).send(eq("myQueue"), messageCreator.capture());
thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
thrown.expectMessage(new StringContains("Test exception"));
messageCreator.getValue().createMessage(mock(Session.class));
}
示例5: testConverter
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入依赖的package包/类
@Test
public void testConverter() throws Exception {
JmsTemplate template = createTemplate();
template.setConnectionFactory(connectionFactory);
template.setMessageConverter(new SimpleMessageConverter());
String s = "Hello world";
MessageProducer messageProducer = mock(MessageProducer.class);
TextMessage textMessage = mock(TextMessage.class);
given(session.createProducer(queue)).willReturn(messageProducer);
given(session.createTextMessage("Hello world")).willReturn(textMessage);
template.convertAndSend(queue, s);
verify(messageProducer).send(textMessage);
verify(messageProducer).close();
if (useTransactedTemplate()) {
verify(session).commit();
}
verify(session).close();
verify(connection).close();
}
示例6: setUp
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入依赖的package包/类
@Before
public void setUp() {
mockJMeadowsService = mock(IJMeadowsPatientService.class);
syncService = mock(ISyncService.class);
converter = mock(SimpleMessageConverter.class);
metrics = mock(MetricRegistry.class);
syncStatusDao = mock(IVprSyncStatusDao.class);
broadcastService = mock(IBroadcastService.class);
mockLogger = mock(Logger.class);
mockExpirationRulesEngine = mock(IExpirationRulesEngine.class);
patientDao = mock(IPatientDAO.class);
handler = new SyncDodMessageHandler();
handler.setJMeadowsPatientService(mockJMeadowsService);
handler.setSyncService(syncService);
handler.setMessageConverter(converter);
handler.setMetricRegistry(metrics);
handler.setSyncStatusDao(syncStatusDao);
handler.setBroadcastService(broadcastService);
handler.setLogger(mockLogger);
handler.setExpirationRulesEngine(mockExpirationRulesEngine);
handler.setPatientDao(patientDao);
}
示例7: setUp
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入依赖的package包/类
@Before
public void setUp() {
mockVlerDasPatientService = mock(IVlerDasPatientService.class);
syncService = mock(ISyncService.class);
converter = mock(SimpleMessageConverter.class);
metrics = mock(MetricRegistry.class);
syncStatusDao = mock(IVprSyncStatusDao.class);
broadcastService = mock(IBroadcastService.class);
mockLogger = mock(Logger.class);
mockExpirationRulesEngine = mock(IExpirationRulesEngine.class);
patientDao = mock(IPatientDAO.class);
handler = new SyncDasMessageHandler();
handler.setDasPatientService(mockVlerDasPatientService);
handler.setSyncService(syncService);
handler.setMessageConverter(converter);
handler.setMetricRegistry(metrics);
handler.setSyncStatusDao(syncStatusDao);
handler.setBroadcastService(broadcastService);
handler.setLogger(mockLogger);
handler.setExpirationRulesEngine(mockExpirationRulesEngine);
handler.setPatientDao(patientDao);
}
示例8: setUp
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
mockJdsDao = mock(IGenericPOMObjectDAO.class);
when(mockJdsDao.save(any(IPOMObject.class))).thenAnswer(new ReturnsArgumentAt(0));
mockResourceLoader = mock(ResourceLoader.class);
when(mockResourceLoader.getResource(anyString())).thenReturn(MOCK_RESOURCE);
mockVistaOperationalDataService = mock(VistaOperationalDataDAO.class);
when(mockVistaOperationalDataService.save(eq(MOCK_VISTA_ID), any(IPOMObject.class))).thenAnswer(new ReturnsArgumentAt(1));
mockErrorDao = mock(IVprSyncErrorDao.class);
handler = new InitOperationalDomainMessageHandler();
handler.setJdsDao(mockJdsDao);
handler.setResourceLoader(mockResourceLoader);
handler.setVistaOperationalDataService(mockVistaOperationalDataService);
handler.setErrorDao(mockErrorDao);
converter = mock(SimpleMessageConverter.class);
mockMessage = Mockito.mock(Message.class);
mockSession = Mockito.mock(Session.class);
handler.converter = converter;
}
示例9: setUp
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入依赖的package包/类
@Before
public void setUp() {
mockVlerService = mock(IVlerService.class);
syncService = mock(ISyncService.class);
converter = mock(SimpleMessageConverter.class);
metrics = mock(MetricRegistry.class);
syncStatusDao = mock(IVprSyncStatusDao.class);
broadcastService = mock(IBroadcastService.class);
mockLogger = mock(Logger.class);
mockExpirationRulesEngine = mock(IExpirationRulesEngine.class);
patientDao = mock(IPatientDAO.class);
handler = new SyncVlerMessageHandler();
handler.setVlerService(mockVlerService);
handler.setSyncService(syncService);
handler.setMessageConverter(converter);
handler.setMetricRegistry(metrics);
handler.setSyncStatusDao(syncStatusDao);
handler.setBroadcastService(broadcastService);
handler.setLogger(mockLogger);
handler.setExpirationRulesEngine(mockExpirationRulesEngine);
handler.setPatientDao(patientDao);
}
示例10: 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");
}
示例11: 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 */ }
}
示例12: 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 */ }
}
示例13: testConverter
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入依赖的package包/类
@Test
public void testConverter() throws Exception {
JmsTemplate102 template = createTemplate();
template.setConnectionFactory(queueConnectionFactory);
template.setMessageConverter(new SimpleMessageConverter());
String s = "Hello world";
QueueSender queueSender = mock(QueueSender.class);
TextMessage message = mock(TextMessage.class);
given(queueSession.createSender(this.queue)).willReturn(queueSender);
given(queueSession.createTextMessage("Hello world")).willReturn(message);
template.convertAndSend(queue, s);
if (useTransactedTemplate()) {
verify(queueSession).commit();
}
verify(queueSender).send(message);
verify(queueSender).close();
verify(queueSession).close();
verify(queueConnection).close();
}
示例14: setUp
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
TextMessage message = mock(TextMessage.class);
given(this.mockJmsTemplate.getMessageConverter()).willReturn(new SimpleMessageConverter());
given(this.mockJmsTemplate.receiveSelected(anyString())).willReturn(message);
}
示例15: testThatTheDefaultMessageConverterisIndeedTheSimpleMessageConverter
import org.springframework.jms.support.converter.SimpleMessageConverter; //导入依赖的package包/类
@Test
public void testThatTheDefaultMessageConverterisIndeedTheSimpleMessageConverter() throws Exception {
MessageListenerAdapter adapter = new MessageListenerAdapter();
assertNotNull("The default [MessageConverter] must never be null.", adapter.getMessageConverter());
assertTrue("The default [MessageConverter] must be of the type [SimpleMessageConverter]",
adapter.getMessageConverter() instanceof SimpleMessageConverter);
}