INT-1257, added tests and minor modification to support MessageHistory in MAIL, JDBC, IP, HTTP modules
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
http://www.springframework.org/schema/integration/http
|
||||
http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
|
||||
|
||||
<si:message-history/>
|
||||
|
||||
<si:channel id="requests">
|
||||
<si:queue capacity="1"/>
|
||||
</si:channel>
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.http.HttpRequestHandlingController;
|
||||
import org.springframework.integration.http.HttpRequestHandlingMessagingGateway;
|
||||
import org.springframework.integration.http.MockHttpServletRequest;
|
||||
@@ -109,6 +110,8 @@ public class HttpInboundChannelAdapterParserTests {
|
||||
postOnlyAdapter.handleRequest(request, response);
|
||||
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
|
||||
Message<?> message = requests.receive(0);
|
||||
MessageHistory history = MessageHistory.read(message);
|
||||
assertTrue(history.containsComponent("postOnlyAdapter"));
|
||||
assertNotNull(message);
|
||||
assertEquals("test", message.getPayload());
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
<int:message-history/>
|
||||
|
||||
<bean id="tcpIpUtils" class="org.springframework.integration.ip.util.SocketUtils" />
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.ip.tcp;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@@ -25,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
|
||||
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
|
||||
import org.springframework.integration.ip.tcp.connection.TcpConnection;
|
||||
@@ -66,6 +68,8 @@ public class ConnectionToConnectionTests {
|
||||
TcpConnection connection = client.getConnection();
|
||||
connection.send(MessageBuilder.withPayload("Test").build());
|
||||
Message<?> message = serverSideChannel.receive(10000);
|
||||
MessageHistory history = MessageHistory.read(message);
|
||||
assertTrue(history.containsComponent("looper"));
|
||||
assertNotNull(message);
|
||||
assertEquals("Test", new String((byte[]) message.getPayload()));
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
|
||||
<int:message-history/>
|
||||
|
||||
<bean id="tcpIpUtils" class="org.springframework.integration.ip.util.SocketUtils" />
|
||||
|
||||
<bean id="serializer" class="org.springframework.commons.serializer.java.JavaStreamingConverter" />
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.ip.tcp;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
@@ -29,6 +30,7 @@ import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -71,6 +73,8 @@ public class SharedConnectionTests {
|
||||
input.send(MessageBuilder.withPayload("Test").build());
|
||||
QueueChannel replies = ctx.getBean("replies", QueueChannel.class);
|
||||
Message<?> message = replies.receive(10000);
|
||||
MessageHistory history = MessageHistory.read(message);
|
||||
assertTrue(history.containsComponent("inboundClient"));
|
||||
assertNotNull(message);
|
||||
assertEquals("Test", message.getPayload());
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.support.channel.ChannelResolver;
|
||||
@@ -137,6 +138,8 @@ public class UdpUnicastEndToEndTests implements Runnable {
|
||||
}
|
||||
QueueChannel channel = ctx.getBean("udpOutChannel", QueueChannel.class);
|
||||
finalMessage = (Message<byte[]>) channel.receive();
|
||||
MessageHistory history = MessageHistory.read(finalMessage);
|
||||
assertTrue(history.containsComponent("udpReceiver"));
|
||||
firstReceived.countDown();
|
||||
try {
|
||||
doneProcessing.await();
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
|
||||
http://www.springframework.org/schema/integration/ip
|
||||
http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd">
|
||||
|
||||
|
||||
<message-history/>
|
||||
<!--
|
||||
Play with the buffer size to force errors. If the checkLength property is
|
||||
set and this buffer is too small, we'll throw an exception.
|
||||
|
||||
@@ -144,6 +144,7 @@
|
||||
</xsd:element>
|
||||
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:ID" use="optional"/>
|
||||
<xsd:attribute name="update" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.core.MessagingTemplate;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
@@ -60,6 +61,8 @@ public class JdbcPollingChannelAdapterParserTests {
|
||||
setUp("pollingForMapJdbcInboundChannelAdapterTest.xml", getClass());
|
||||
this.jdbcTemplate.update("insert into item values(1,'',2)");
|
||||
Message<?> message = messagingTemplate.receive();
|
||||
MessageHistory history = MessageHistory.read(message);
|
||||
assertTrue(history.containsComponent("jdbcAdapter"));
|
||||
assertNotNull("No message found ", message);
|
||||
assertTrue("Wrong payload type expected instance of List", message.getPayload() instanceof List<?>);
|
||||
}
|
||||
|
||||
@@ -6,11 +6,13 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/jdbc
|
||||
http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd">
|
||||
|
||||
<inbound-channel-adapter query="select * from item where status=2" channel="target"
|
||||
<si:message-history/>
|
||||
|
||||
<inbound-channel-adapter id="jdbcAdapter" query="select * from item where status=2" channel="target"
|
||||
data-source="dataSource" />
|
||||
|
||||
<beans:import resource="jdbcInboundChannelAdapterCommonConfig.xml" />
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.integration.mail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Authenticator;
|
||||
@@ -36,7 +34,6 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.integration.context.IntegrationObjectSupport;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Base class for {@link MailReceiver} implementations.
|
||||
|
||||
@@ -15,12 +15,18 @@
|
||||
*/
|
||||
package org.springframework.integration.mail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import javax.mail.Flags;
|
||||
import javax.mail.Flags.Flag;
|
||||
import javax.mail.Folder;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.Flags.Flag;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -28,14 +34,13 @@ import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.mail.config.ImapIdleChannelAdapterParserTests;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import com.sun.mail.imap.IMAPFolder;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -188,4 +193,50 @@ public class ImapMailReceiverTests {
|
||||
verify(msg2, times(1)).setFlag(Flag.SEEN, true);
|
||||
verify(receiver, times(0)).deleteMessages((Message[]) Mockito.any());
|
||||
}
|
||||
@Test
|
||||
public void testMessageHistory() throws Exception{
|
||||
ApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("ImapIdleChannelAdapterParserTests-context.xml", ImapIdleChannelAdapterParserTests.class);
|
||||
ImapIdleChannelAdapter adapter = context.getBean("simpleAdapter", ImapIdleChannelAdapter.class);
|
||||
|
||||
AbstractMailReceiver receiver = new ImapMailReceiver();
|
||||
receiver = spy(receiver);
|
||||
receiver.afterPropertiesSet();
|
||||
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
|
||||
adapterAccessor.setPropertyValue("mailReceiver", receiver);
|
||||
|
||||
MimeMessage mailMessage = mock(MimeMessage.class);
|
||||
Flags flags = mock(Flags.class);
|
||||
when(mailMessage.getFlags()).thenReturn(flags);
|
||||
final Message[] messages = new Message[]{mailMessage};
|
||||
|
||||
doAnswer(new Answer<Object>() {
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
DirectFieldAccessor accesor = new DirectFieldAccessor((invocation.getMock()));
|
||||
IMAPFolder folder = mock(IMAPFolder.class);
|
||||
accesor.setPropertyValue("folder", folder);
|
||||
when(folder.hasNewMessages()).thenReturn(true);
|
||||
return null;
|
||||
}
|
||||
}).when(receiver).openFolder();
|
||||
|
||||
doAnswer(new Answer<Object>() {
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return messages;
|
||||
}
|
||||
}).when(receiver).searchForNewMessages();
|
||||
|
||||
doAnswer(new Answer<Object>() {
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return null;
|
||||
}
|
||||
}).when(receiver).fetchMessages(messages);
|
||||
|
||||
PollableChannel channel = context.getBean("channel", PollableChannel.class);
|
||||
|
||||
adapter.start();
|
||||
org.springframework.integration.Message<?> replMessage = channel.receive(10000);
|
||||
MessageHistory history = MessageHistory.read(replMessage);
|
||||
assertTrue(history.containsComponent("simpleAdapter"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,11 @@
|
||||
http://www.springframework.org/schema/util
|
||||
http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/mail
|
||||
http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd">
|
||||
|
||||
<integration:message-history/>
|
||||
|
||||
<context:property-placeholder properties-ref="configProperties"/>
|
||||
|
||||
@@ -25,7 +27,9 @@
|
||||
<prop key="mail.delete">false</prop>
|
||||
</util:properties>
|
||||
|
||||
<integration:channel id="channel"/>
|
||||
<integration:channel id="channel">
|
||||
<integration:queue/>
|
||||
</integration:channel>
|
||||
|
||||
<mail:imap-idle-channel-adapter id="simpleAdapter"
|
||||
store-uri="imap:foo"
|
||||
|
||||
@@ -26,7 +26,6 @@ import javax.mail.URLName;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -125,5 +124,4 @@ public class ImapIdleChannelAdapterParserTests {
|
||||
assertEquals("bar", properties.getProperty("foo"));
|
||||
assertEquals(Boolean.FALSE, receiverAccessor.getPropertyValue("shouldDeleteMessages"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user