Search in sources :

Example 76 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class EventInboundChannelAdapterParserTests method validateUsageWithHistory.

@Test
public void validateUsageWithHistory() {
    PollableChannel channel = context.getBean("input", PollableChannel.class);
    assertEquals(ContextRefreshedEvent.class, channel.receive(0).getPayload().getClass());
    context.publishEvent(new SampleEvent("hello"));
    Message<?> message = channel.receive(0);
    MessageHistory history = MessageHistory.read(message);
    assertNotNull(history);
    Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "eventAdapterSimple", 0);
    assertNotNull(componentHistoryRecord);
    assertEquals("event:inbound-channel-adapter", componentHistoryRecord.get("type"));
    assertNotNull(message);
    assertEquals(SampleEvent.class, message.getPayload().getClass());
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) PollableChannel(org.springframework.messaging.PollableChannel) Properties(java.util.Properties) Test(org.junit.Test)

Example 77 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class RedisQueueMessageDrivenEndpointTests method testInt3932ReadFromLeft.

@Test
@RedisAvailable
@SuppressWarnings("unchecked")
public void testInt3932ReadFromLeft() {
    String queueName = "si.test.redisQueueInboundChannelAdapterTests3932";
    RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
    redisTemplate.setConnectionFactory(this.connectionFactory);
    redisTemplate.setEnableDefaultSerializer(false);
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
    redisTemplate.afterPropertiesSet();
    String payload = "testing";
    redisTemplate.boundListOps(queueName).rightPush(payload);
    Date payload2 = new Date();
    redisTemplate.boundListOps(queueName).rightPush(payload2);
    PollableChannel channel = new QueueChannel();
    RedisQueueMessageDrivenEndpoint endpoint = new RedisQueueMessageDrivenEndpoint(queueName, this.connectionFactory);
    endpoint.setBeanFactory(Mockito.mock(BeanFactory.class));
    endpoint.setOutputChannel(channel);
    endpoint.setReceiveTimeout(10);
    endpoint.setRightPop(false);
    endpoint.afterPropertiesSet();
    endpoint.start();
    Message<Object> receive = (Message<Object>) channel.receive(10000);
    assertNotNull(receive);
    assertEquals(payload, receive.getPayload());
    receive = (Message<Object>) channel.receive(10000);
    assertNotNull(receive);
    assertEquals(payload2, receive.getPayload());
    endpoint.stop();
}
Also used : StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) QueueChannel(org.springframework.integration.channel.QueueChannel) ErrorMessage(org.springframework.messaging.support.ErrorMessage) Message(org.springframework.messaging.Message) JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) Date(java.util.Date) StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) PollableChannel(org.springframework.messaging.PollableChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 78 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class FtpOutboundTests method testFtpOutboundGatewayInsideChain.

// INT-2275
@Test
public void testFtpOutboundGatewayInsideChain() throws Exception {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("FtpOutboundInsideChainTests-context.xml", getClass());
    MessageChannel channel = context.getBean("ftpOutboundGatewayInsideChain", MessageChannel.class);
    channel.send(MessageBuilder.withPayload("remote-test-dir").build());
    PollableChannel output = context.getBean("output", PollableChannel.class);
    Message<?> result = output.receive();
    Object payload = result.getPayload();
    assertTrue(payload instanceof List<?>);
    @SuppressWarnings("unchecked") List<? extends FileInfo<?>> remoteFiles = (List<? extends FileInfo<?>>) payload;
    assertEquals(3, remoteFiles.size());
    List<String> files = Arrays.asList(new File("remote-test-dir").list());
    for (FileInfo<?> remoteFile : remoteFiles) {
        assertTrue(files.contains(remoteFile.getFilename()));
    }
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) MessageChannel(org.springframework.messaging.MessageChannel) FileInfo(org.springframework.integration.file.remote.FileInfo) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) FTPFile(org.apache.commons.net.ftp.FTPFile) Test(org.junit.Test)

Example 79 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class GroovyServiceActivatorTests method testScriptWithoutVariables.

@Test
public void testScriptWithoutVariables() throws Exception {
    PollableChannel replyChannel = new QueueChannel();
    for (int i = 1; i <= 3; i++) {
        Message<?> message = MessageBuilder.withPayload("test-" + i).setReplyChannel(replyChannel).build();
        this.scriptWithoutVariablesInput.send(message);
    }
    DateFormat format = new SimpleDateFormat("dd.MM.yyyy");
    String now = format.format(new Date());
    assertEquals("withoutVariables-test-1 : " + now, replyChannel.receive(0).getPayload());
    assertEquals("withoutVariables-test-2 : " + now, replyChannel.receive(0).getPayload());
    assertEquals("withoutVariables-test-3 : " + now, replyChannel.receive(0).getPayload());
    assertNull(replyChannel.receive(0));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) PollableChannel(org.springframework.messaging.PollableChannel) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 80 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class SftpOutboundTests method testFtpOutboundGatewayInsideChain.

// INT-2275
@Test
public void testFtpOutboundGatewayInsideChain() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("SftpOutboundInsideChainTests-context.xml", getClass());
    MessageChannel channel = context.getBean("outboundGatewayInsideChain", MessageChannel.class);
    channel.send(MessageBuilder.withPayload("remote-test-dir").build());
    PollableChannel output = context.getBean("replyChannel", PollableChannel.class);
    Message<?> result = output.receive();
    Object payload = result.getPayload();
    assertTrue(payload instanceof List<?>);
    @SuppressWarnings("unchecked") List<? extends FileInfo<?>> remoteFiles = (List<? extends FileInfo<?>>) payload;
    assertEquals(3, remoteFiles.size());
    List<String> files = Arrays.asList(new File("remote-test-dir").list());
    for (FileInfo<?> remoteFile : remoteFiles) {
        assertTrue(files.contains(remoteFile.getFilename()));
    }
    context.close();
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MessageChannel(org.springframework.messaging.MessageChannel) FileInfo(org.springframework.integration.file.remote.FileInfo) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Aggregations

PollableChannel (org.springframework.messaging.PollableChannel)210 Test (org.junit.Test)190 MessageChannel (org.springframework.messaging.MessageChannel)89 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)82 QueueChannel (org.springframework.integration.channel.QueueChannel)52 GenericMessage (org.springframework.messaging.support.GenericMessage)52 Message (org.springframework.messaging.Message)40 BeanFactory (org.springframework.beans.factory.BeanFactory)25 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)20 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)19 MessagingException (org.springframework.messaging.MessagingException)16 SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)13 MessagingTemplate (org.springframework.integration.core.MessagingTemplate)12 ErrorMessage (org.springframework.messaging.support.ErrorMessage)12 Document (org.w3c.dom.Document)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 Matchers.containsString (org.hamcrest.Matchers.containsString)11 Date (java.util.Date)10 ArrayList (java.util.ArrayList)9 MessageHistory (org.springframework.integration.history.MessageHistory)9