当前位置: 首页>>代码示例>>Java>>正文


Java SimpleMessageConverter类代码示例

本文整理汇总了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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:SimpleMessageConverterTests.java

示例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");
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:SimpleMessageConverterTests.java

示例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 */ }
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:SimpleMessageConverterTests.java

示例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));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:JmsMessagingTemplateTests.java

示例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();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:JmsTemplateTests.java

示例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);
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:24,代码来源:SyncDodMessageHandlerTest.java

示例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);
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:24,代码来源:SyncDasMessageHandlerTest.java

示例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;
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:21,代码来源:InitOperationalDomainMessageHandlerTests.java

示例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);
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:24,代码来源:SyncVlerMessageHandlerTest.java

示例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");
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:23,代码来源:SimpleMessageConverterTests.java

示例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 */ }
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:17,代码来源:SimpleMessageConverterTests.java

示例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 */ }
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:17,代码来源:SimpleMessageConverterTests.java

示例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();
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:24,代码来源:JmsTemplate102Tests.java

示例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);
}
 
开发者ID:hafidsousa,项目名称:webcrawler,代码行数:8,代码来源:CrawlerBatchTaskTest.java

示例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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:MessageListenerAdapterTests.java


注:本文中的org.springframework.jms.support.converter.SimpleMessageConverter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。