JmsTopicSubscriber extends JmsConsumer implements Runnable { @Override public Message receive(TestContext context, long timeout) { return messageQueue.createConsumer().receive(context, timeout); } JmsTopicSubscriber(String name, JmsEndpointConfiguration endpointConfiguration, TestContextFactory testContextFactory); void run(); void start(); void stop(); @Override Message receive(TestContext context, long timeout); @Override Message receive(String selector, TestContext context, long timeout); boolean isRunning();  }
@Test public void testSubscriberWithTopicDestination() throws JMSException { JmsEndpointConfiguration endpointConfiguration = new JmsEndpointConfiguration(); endpointConfiguration.setPubSubDomain(true); endpointConfiguration.setAutoStart(true); endpointConfiguration.setConnectionFactory(topicConnectionFactory); endpointConfiguration.setDestination(topic); when(topicSubscriber.receive()).thenReturn(new TextMessageImpl("Foo1", Collections.emptyMap())) .thenReturn(null); JmsEndpoint jmsEndpoint = new JmsEndpoint(endpointConfiguration); JmsTopicSubscriber jmsTopicSubscriber = (JmsTopicSubscriber) jmsEndpoint.createConsumer(); Assert.assertEquals(jmsTopicSubscriber.receive(context, endpointConfiguration.getTimeout()).getPayload(String.class), "Foo1"); }
@Test public void testSubscriberWithJmsTemplate() throws JMSException { JmsEndpointConfiguration endpointConfiguration = new JmsEndpointConfiguration(); endpointConfiguration.setPubSubDomain(true); endpointConfiguration.setAutoStart(true); endpointConfiguration.setJmsTemplate(jmsTemplate); when(topicSubscriber.receive()).thenReturn(new TextMessageImpl("Foo1", Collections.emptyMap())) .thenReturn(null); JmsEndpoint jmsEndpoint = new JmsEndpoint(endpointConfiguration); JmsTopicSubscriber jmsTopicSubscriber = (JmsTopicSubscriber) jmsEndpoint.createConsumer(); Assert.assertEquals(jmsTopicSubscriber.receive(context, endpointConfiguration.getTimeout()).getPayload(String.class), "Foo1"); }