Skip to content

Commit

Permalink
INT-1257, added tests and minor modification to support MessageHistor…
Browse files Browse the repository at this point in the history
…y in MAIL, JDBC, IP, HTTP modules
  • Loading branch information
olegz committed Sep 22, 2010
1 parent fa570a4 commit c4d31af
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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;
Expand Down Expand Up @@ -109,6 +110,8 @@ public void postRequestWithTextContentOk() throws Exception {
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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,6 +26,7 @@
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;
Expand Down Expand Up @@ -66,6 +68,8 @@ public void testConnect() throws Exception {
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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +30,7 @@
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;
Expand Down Expand Up @@ -71,6 +73,8 @@ public void test1() throws Exception {
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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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;
Expand Down Expand Up @@ -137,6 +138,8 @@ public void run() {
}
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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;
Expand Down Expand Up @@ -60,6 +61,8 @@ public void testSimpleInboundChannelAdapter(){
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<?>);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,7 +34,6 @@
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,32 @@
*/
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;
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
Expand Down Expand Up @@ -188,4 +193,50 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@
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"/>

<util:properties id="configProperties">
<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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

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;
Expand Down Expand Up @@ -125,5 +124,4 @@ public void customAdapter() {
assertEquals("bar", properties.getProperty("foo"));
assertEquals(Boolean.FALSE, receiverAccessor.getPropertyValue("shouldDeleteMessages"));
}

}

0 comments on commit c4d31af

Please sign in to comment.