use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class JdbcMessageStoreTests method testWithMessageHistory.
@Test
public void testWithMessageHistory() throws Exception {
Message<?> message = new GenericMessage<String>("Hello");
DirectChannel fooChannel = new DirectChannel();
fooChannel.setBeanName("fooChannel");
DirectChannel barChannel = new DirectChannel();
barChannel.setBeanName("barChannel");
message = MessageHistory.write(message, fooChannel);
message = MessageHistory.write(message, barChannel);
messageStore.addMessage(message);
message = messageStore.getMessage(message.getHeaders().getId());
MessageHistory messageHistory = MessageHistory.read(message);
assertNotNull(messageHistory);
assertEquals(2, messageHistory.size());
Properties fooChannelHistory = messageHistory.get(0);
assertEquals("fooChannel", fooChannelHistory.get("name"));
assertEquals("channel", fooChannelHistory.get("type"));
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class WebSocketServerTests method testBrokerIsNotPresented.
@Test
public void testBrokerIsNotPresented() throws Exception {
WebSocketInboundChannelAdapter webSocketInboundChannelAdapter = new WebSocketInboundChannelAdapter(Mockito.mock(ServerWebSocketContainer.class));
webSocketInboundChannelAdapter.setOutputChannel(new DirectChannel());
webSocketInboundChannelAdapter.setUseBroker(true);
webSocketInboundChannelAdapter.setBeanFactory(Mockito.mock(BeanFactory.class));
webSocketInboundChannelAdapter.setApplicationContext(Mockito.mock(ApplicationContext.class));
try {
webSocketInboundChannelAdapter.afterPropertiesSet();
fail("IllegalStateException expected");
} catch (Exception e) {
assertThat(e, instanceOf(IllegalStateException.class));
assertThat(e.getMessage(), containsString("WebSocket Broker Relay isn't present in the application context;"));
}
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class PresenceListeningEndpointTests method testWithErrorChannel.
@Test
public void testWithErrorChannel() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
XMPPConnection connection = mock(XMPPConnection.class);
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection);
PresenceListeningEndpoint endpoint = new PresenceListeningEndpoint();
DirectChannel outChannel = new DirectChannel();
outChannel.subscribe(message -> {
throw new RuntimeException("ooops");
});
PollableChannel errorChannel = new QueueChannel();
endpoint.setBeanFactory(bf);
endpoint.setOutputChannel(outChannel);
endpoint.setErrorChannel(errorChannel);
endpoint.afterPropertiesSet();
RosterListener listener = (RosterListener) TestUtils.getPropertyValue(endpoint, "rosterListener");
Presence presence = new Presence(Type.available);
listener.presenceChanged(presence);
ErrorMessage msg = (ErrorMessage) errorChannel.receive();
assertSame(presence, ((MessagingException) msg.getPayload()).getFailedMessage().getPayload());
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration-samples by spring-projects.
the class ApplicationTests method testWebSockets.
@Test
public void testWebSockets() throws InterruptedException {
System.setProperty("local.server.port", this.port);
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("client-context.xml", org.springframework.integration.samples.websocket.standard.client.Application.class);
DirectChannel webSocketInputChannel = ctx.getBean("webSocketInputChannel", DirectChannel.class);
final CountDownLatch stopLatch = new CountDownLatch(2);
webSocketInputChannel.addInterceptor(new ChannelInterceptorAdapter() {
@Override
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
Object payload = message.getPayload();
assertThat(payload, instanceOf(String.class));
Date date = null;
try {
date = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.DEFAULT).parse((String) payload);
} catch (ParseException e) {
fail("fail to parse date");
}
assertThat(new Date().compareTo(date), greaterThanOrEqualTo(0));
stopLatch.countDown();
}
});
assertTrue(stopLatch.await(10, TimeUnit.SECONDS));
ctx.close();
}
use of org.springframework.integration.channel.DirectChannel in project spring-cloud-stream by spring-cloud.
the class AbstractBinderTests method testSendPojoReceivePojoWithStreamListener.
@SuppressWarnings("rawtypes")
@Test
public void testSendPojoReceivePojoWithStreamListener() throws Exception {
StreamListenerMessageHandler handler = this.buildStreamListener(AbstractBinderTests.class, "echoStation", Station.class);
Binder binder = getBinder();
BindingProperties producerBindingProperties = createProducerBindingProperties(createProducerProperties());
DirectChannel moduleOutputChannel = createBindableChannel("output", producerBindingProperties);
BindingProperties consumerBindingProperties = createConsumerBindingProperties(createConsumerProperties());
DirectChannel moduleInputChannel = createBindableChannel("input", consumerBindingProperties);
Binding<MessageChannel> producerBinding = binder.bindProducer(String.format("bad%s0f", getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer());
Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("bad%s0f", getDestinationNameDelimiter()), "test-6", moduleInputChannel, consumerBindingProperties.getConsumer());
Readings r1 = new Readings();
r1.setCustomerid("123");
r1.setStationid("XYZ");
Readings r2 = new Readings();
r2.setCustomerid("546");
r2.setStationid("ABC");
Station station = new Station();
station.setReadings(Arrays.asList(r1, r2));
Message<?> message = MessageBuilder.withPayload(station).setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON).build();
moduleInputChannel.subscribe(handler);
moduleOutputChannel.send(message);
QueueChannel channel = (QueueChannel) handler.getOutputChannel();
Message<Station> reply = (Message<Station>) channel.receive(5000);
assertNotNull(reply);
assertTrue(reply.getPayload() instanceof Station);
producerBinding.unbind();
consumerBinding.unbind();
}
Aggregations