INT-1263, added more changes and tests related valdating MessageHistory in every module

This commit is contained in:
Oleg Zhurakousky
2010-09-22 18:44:51 -04:00
parent dee91f6871
commit b6e058c59b
46 changed files with 367 additions and 114 deletions

View File

@@ -23,6 +23,10 @@ package org.springframework.integration;
*/
@SuppressWarnings("serial")
public class MessageDeliveryException extends MessagingException {
public MessageDeliveryException(String description) {
super(description);
}
public MessageDeliveryException(Message<?> undeliveredMessage) {
super(undeliveredMessage);

View File

@@ -21,7 +21,11 @@ package org.springframework.integration;
* @author Mark Fisher
*/
@SuppressWarnings("serial")
public class MessageTimeoutException extends MessageHandlingException {
public class MessageTimeoutException extends MessageDeliveryException {
public MessageTimeoutException(String description) {
super(description);
}
public MessageTimeoutException(Message<?> failedMessage, String description, Throwable cause) {
super(failedMessage, description, cause);
@@ -31,10 +35,6 @@ public class MessageTimeoutException extends MessageHandlingException {
super(failedMessage, description);
}
public MessageTimeoutException(Message<?> failedMessage, Throwable cause) {
super(failedMessage, cause);
}
public MessageTimeoutException(Message<?> failedMessage) {
super(failedMessage);
}

View File

@@ -17,16 +17,17 @@
package org.springframework.integration.transformer;
import org.springframework.integration.Message;
import org.springframework.integration.context.IntegrationObjectSupport;
import org.springframework.integration.support.MessageBuilder;
/**
* A base class for {@link Transformer} implementations.
*
* @author Mark Fisher
* @author Oleg Zhurakousky
*/
public abstract class AbstractTransformer implements Transformer {
public abstract class AbstractTransformer extends IntegrationObjectSupport implements Transformer {
@SuppressWarnings("unchecked")
public final Message<?> transform(Message<?> message) {
try {
Object result = this.doTransform(message);

View File

@@ -19,11 +19,7 @@ package org.springframework.integration.transformer;
import java.util.Map;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.convert.ConversionService;
import org.springframework.util.Assert;
@@ -41,15 +37,11 @@ import org.springframework.validation.DataBinder;
* @author Oleg Zhurakousky
* @since 2.0
*/
public class MapToObjectTransformer extends AbstractPayloadTransformer<Map<?,?>, Object> implements BeanFactoryAware{
public class MapToObjectTransformer extends AbstractPayloadTransformer<Map<?,?>, Object>{
private final Class<?> targetClass;
private final String targetBeanName;
private volatile ConfigurableBeanFactory beanFactory;
/**
* @param targetClass
*/
@@ -73,25 +65,17 @@ public class MapToObjectTransformer extends AbstractPayloadTransformer<Map<?,?>,
protected Object transformPayload(Map<?,?> payload) throws Exception {
Object target = (this.targetClass != null)
? BeanUtils.instantiate(this.targetClass)
: this.beanFactory.getBean(this.targetBeanName);
: this.getBeanFactory().getBean(this.targetBeanName);
DataBinder binder = new DataBinder(target);
binder.setConversionService(this.beanFactory.getConversionService());
binder.setConversionService(((ConfigurableListableBeanFactory)this.getBeanFactory()).getConversionService());
binder.bind(new MutablePropertyValues(payload));
return target;
}
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
*/
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
Assert.isTrue(beanFactory instanceof ConfigurableListableBeanFactory,
"A ConfigurableListableBeanFactory is required.");
this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
protected void onInit(){
if (StringUtils.hasText(this.targetBeanName)) {
Assert.isTrue(this.beanFactory.isPrototype(this.targetBeanName),
Assert.isTrue(this.getBeanFactory().isPrototype(this.targetBeanName),
"target bean [" + targetBeanName + "] must have 'prototype' scope");
}
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.integration.transformer;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.integration.Message;
import org.springframework.integration.context.NamedComponent;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.util.Assert;
@@ -48,7 +49,8 @@ public class MessageTransformingHandler extends AbstractReplyProducingMessageHan
@Override
public String getComponentType() {
return "transformer";
return (this.transformer instanceof NamedComponent) ?
((NamedComponent) this.transformer).getComponentType() : "transformer";
}
@Override

View File

@@ -2,8 +2,10 @@
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd">
@@ -11,9 +13,24 @@
default-request-channel="requestChannel"
default-reply-timeout="3000"
service-interface="org.springframework.integration.gateway.GatewayRequiresReplyTests$TestService" />
<service-activator input-channel="requestChannel"
expression="payload == 'foo' ? 'bar' : null"
requires-reply="true"/>
<gateway id="timeoutGateway"
default-request-channel="timeoutChannel"
default-reply-timeout="1000"
service-interface="org.springframework.integration.gateway.GatewayRequiresReplyTests$TestService" />
<channel id="timeoutChannel">
<dispatcher task-executor="executor"/>
</channel>
<service-activator input-channel="timeoutChannel">
<beans:bean class="org.springframework.integration.gateway.GatewayRequiresReplyTests.LongRunningService"/>
</service-activator>
<task:executor id="executor" pool-size="5"/>
</beans:beans>

View File

@@ -51,10 +51,24 @@ public class GatewayRequiresReplyTests {
TestService gateway = (TestService) applicationContext.getBean("gateway");
gateway.test("bad");
}
@Test
public void timedOutGateway() {
TestService gateway = (TestService) applicationContext.getBean("timeoutGateway");
String result = gateway.test("hello");
System.out.println("Result: " + result);
}
public static interface TestService {
public String test(String s);
}
public static class LongRunningService{
public String echo(String value) throws Exception{
Thread.sleep(5000);
return value;
}
}
}

View File

@@ -19,6 +19,7 @@ package org.springframework.integration.test.util;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.util.Properties;
import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;
import org.hamcrest.Matcher;
@@ -41,15 +42,18 @@ import org.springframework.integration.context.NamedComponent;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.endpoint.AbstractPollingEndpoint;
import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.PeriodicTrigger;
import org.springframework.util.Assert;
import org.springframework.util.ErrorHandler;
import org.springframework.util.StringUtils;
/**
* @author Mark Fisher
* @author Iwein Fuld
* @author Oleg Zhurakousky
*/
public abstract class TestUtils {
@@ -159,4 +163,19 @@ public abstract class TestUtils {
}
};
}
public static Properties locateComponentInHistory(MessageHistory history, String componentName, int startingIndex){
Assert.notNull(history, "'history' must not be null");
Assert.isTrue(StringUtils.hasText(componentName), "'componentName' must be provided");
Assert.isTrue(startingIndex < history.size(), "'startingIndex' can not be greater then size of history");
Properties component = null;
for (int i = startingIndex; i < history.size(); i++) {
Properties properties = history.get(i);
if (componentName.equals(properties.get("name"))){
component = properties;
break;
}
}
return component;
}
}

View File

@@ -64,25 +64,6 @@ public class MapToObjectTransformerTests {
assertNotNull(person.getAddress());
assertEquals("1123 Main st", person.getAddress().getStreet());
}
@SuppressWarnings("unchecked")
@Test(expected=IllegalArgumentException.class)
public void testMapToObjectTransformationNonPrototype(){
Map map = new HashMap();
map.put("fname", "Justin");
map.put("lname", "Case");
Address address = new Address();
address.setStreet("1123 Main st");
map.put("address", address);
Message message = MessageBuilder.withPayload(map).build();
GenericApplicationContext context = new GenericApplicationContext();
RootBeanDefinition personDef = new RootBeanDefinition(Person.class);
context.registerBeanDefinition("person", personDef);
MapToObjectTransformer transformer = new MapToObjectTransformer("person");
transformer.setBeanFactory(context.getBeanFactory());
transformer.transform(message);
}
@SuppressWarnings("unchecked")
@Test

View File

@@ -1,3 +1,3 @@
#Thu Jul 29 17:49:43 EDT 2010
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventInboundChannelAdapterParserTests-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="829" endstart\="815" start\="774" startend\="798"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n</graph>
#Wed Sep 22 11:50:06 EDT 2010
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventInboundChannelAdapterParserTests-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1040" endstart\="1026" start\="985" startend\="1009"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1508" endstart\="1494" start\="1445" startend\="1477"/>\n<bounds height\="112" width\="116" x\="19" y\="149"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1731" endstart\="1717" start\="1657" startend\="1700"/>\n<bounds height\="112" width\="116" x\="19" y\="281"/>\n</element>\n</graph>
eclipse.preferences.version=1

View File

@@ -9,6 +9,8 @@
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-event="http://www.springframework.org/schema/integration/event">
<int:message-history/>
<int-event:inbound-channel-adapter id="eventAdapterSimple" channel="input"/>
<int:channel id="input">

View File

@@ -35,6 +35,7 @@ import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.integration.Message;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.event.ApplicationEventInboundChannelAdapter;
import org.springframework.integration.history.MessageHistory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -91,11 +92,13 @@ public class EventInboundChannelAdapterParserTests {
}
@Test
public void validateUsage() {
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);
assertTrue(history.containsComponent("eventAdapterSimple"));
assertNotNull(message);
assertEquals(SampleEvent.class, message.getPayload().getClass());
}

View File

@@ -15,8 +15,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>

View File

@@ -0,0 +1 @@
hello

View File

@@ -2,8 +2,10 @@ package org.springframework.integration.file;
import org.springframework.core.io.Resource;
import org.springframework.integration.Message;
import org.springframework.integration.MessagingException;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.endpoint.MessageProducerSupport;
import org.springframework.integration.file.entries.*;
import java.io.File;
@@ -27,7 +29,7 @@ import java.util.regex.Pattern;
*
* @author Josh Long
*/
public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<Y, T extends AbstractInboundRemoteFileSystemSychronizer<Y>> extends AbstractEndpoint implements MessageSource<File> {
public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<Y, T extends AbstractInboundRemoteFileSystemSychronizer<Y>> extends MessageProducerSupport implements MessageSource<File> {
/**
* Extension used when downloading files. We change it right after we know it's downloaded
*/
@@ -74,7 +76,8 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
this.remotePredicate = remotePredicate;
}
private EntryListFilter<File> buildFilter() {
@SuppressWarnings("unchecked")
private EntryListFilter<File> buildFilter() {
FileEntryNamer fileEntryNamer = new FileEntryNamer();
Pattern completePattern = Pattern.compile("^.*(?<!" + INCOMPLETE_EXTENSION + ")$");
return new CompositeEntryListFilter<File>(
@@ -83,33 +86,42 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
}
@Override
protected void onInit() throws Exception {
if (this.remotePredicate != null) {
this.synchronizer.setFilter(this.remotePredicate);
}
protected void onInit() {
try {
if (this.remotePredicate != null) {
this.synchronizer.setFilter(this.remotePredicate);
}
if (this.autoCreateDirectories) {
if ((this.localDirectory != null) && !this.localDirectory.exists() && this.localDirectory.getFile().mkdirs())
logger.debug("the localDirectory " + this.localDirectory + " doesn't exist");
}
if (this.autoCreateDirectories) {
if ((this.localDirectory != null) && !this.localDirectory.exists() && this.localDirectory.getFile().mkdirs())
logger.debug("the localDirectory " + this.localDirectory + " doesn't exist");
}
/**
* Handles making sure the remote files get here in one piece
*/
this.synchronizer.setLocalDirectory(this.localDirectory);
this.synchronizer.setTaskScheduler(this.getTaskScheduler());
this.synchronizer.setBeanFactory(this.getBeanFactory());
this.synchronizer.setPhase(this.getPhase());
this.synchronizer.setBeanName(this.getComponentName());
/**
* Handles making sure the remote files get here in one piece
*/
this.synchronizer.setLocalDirectory(this.localDirectory);
this.synchronizer.setTaskScheduler(this.getTaskScheduler());
this.synchronizer.setBeanFactory(this.getBeanFactory());
this.synchronizer.setPhase(this.getPhase());
this.synchronizer.setBeanName(this.getComponentName());
/**
* Handles forwarding files once they ultimately appear in the {@link #localDirectory}
*/
this.fileSource = new FileReadingMessageSource();
this.fileSource.setFilter(buildFilter());
this.fileSource.setDirectory(this.localDirectory.getFile());
this.fileSource.afterPropertiesSet();
this.synchronizer.afterPropertiesSet();
/**
* Handles forwarding files once they ultimately appear in the {@link #localDirectory}
*/
this.fileSource = new FileReadingMessageSource();
this.fileSource.setFilter(buildFilter());
this.fileSource.setDirectory(this.localDirectory.getFile());
this.fileSource.afterPropertiesSet();
this.synchronizer.afterPropertiesSet();
} catch (Exception e) {
if (e instanceof RuntimeException){
throw (RuntimeException)e;
} else {
throw new MessagingException("Failure during initialization of " + this.getComponentName(), e);
}
}
}
public Message<File> receive() {

View File

@@ -15,21 +15,25 @@
*/
package org.springframework.integration.file;
import java.io.File;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.PriorityBlockingQueue;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.Message;
import org.springframework.integration.MessagingException;
import org.springframework.integration.aggregator.ResequencingMessageGroupProcessor;
import org.springframework.integration.context.IntegrationObjectSupport;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.file.entries.EntryListFilter;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.util.Assert;
import java.io.File;
import java.util.*;
import java.util.concurrent.PriorityBlockingQueue;
/**
* {@link MessageSource} that creates messages from a file system directory. To prevent messages for certain files, you
@@ -52,8 +56,9 @@ import java.util.concurrent.PriorityBlockingQueue;
*
* @author Iwein Fuld
* @author Mark Fisher
* @author Oleg Zhurakousky
*/
public class FileReadingMessageSource implements MessageSource<File>, InitializingBean {
public class FileReadingMessageSource extends IntegrationObjectSupport implements MessageSource<File>{
private static final int DEFAULT_INTERNAL_QUEUE_CAPACITY = 5;
private static final Log logger = LogFactory.getLog(FileReadingMessageSource.class);
private volatile File directory;
@@ -178,8 +183,7 @@ public class FileReadingMessageSource implements MessageSource<File>, Initializi
this.scanEachPoll = scanEachPoll;
}
@SuppressWarnings({"ResultOfMethodCallIgnored"})
public final void afterPropertiesSet() {
protected void onInit() {
Assert.notNull(directory, "'directory' must not be set before initialization");
if (!this.directory.exists() && this.autoCreateDirectory) {
@@ -254,4 +258,8 @@ public class FileReadingMessageSource implements MessageSource<File>, Initializi
logger.debug("Sent: " + sentMessage);
}
}
public String getComponentType() {
return "file:inbound-channel-adapter";
}
}

View File

@@ -21,6 +21,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.integration.file.DefaultDirectoryScanner;
@@ -47,7 +48,12 @@ public class FileInboundChannelAdapterParserTests {
private ApplicationContext context;
@Autowired
// @Qualifier("inputDirPoller")
private FileReadingMessageSource source;
// @Autowired
// @Qualifier("inputDirPollerWithChannel")
// private FileReadingMessageSource sourceWithChannel;
private DirectFieldAccessor accessor;
@@ -59,6 +65,7 @@ public class FileInboundChannelAdapterParserTests {
@Test
public void channelName() throws Exception {
Object adapter = context.getBean("inputDirPoller");
AbstractMessageChannel channel = context.getBean("inputDirPoller", AbstractMessageChannel.class);
assertEquals("Channel should be available under specified id", "inputDirPoller", channel.getComponentName());
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.file.config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Properties;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.test.util.TestUtils;
/**
* @author Oleg Zhurakousky
*
*/
public class FileMessageHistoryTest {
@Test
public void testMessageHistory() throws Exception{
ApplicationContext context = new ClassPathXmlApplicationContext("file-message-history-context.xml", this.getClass());
File file = new File("input/FileMessageHistoryTest.txt");
BufferedWriter out = new BufferedWriter(new FileWriter(file));
out.write("hello");
out.close();
PollableChannel outChannel = context.getBean("outChannel", PollableChannel.class);
Message<?> message = outChannel.receive(1000);
MessageHistory history = MessageHistory.read(message);
assertNotNull(history);
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "fileAdapter", 0);
assertNotNull(componentHistoryRecord);
assertEquals("file:inbound-channel-adapter", componentHistoryRecord.get("type"));
}
}

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file-2.0.xsd">
<int:message-history/>
<int-file:inbound-channel-adapter id="fileAdapter" directory="input"
auto-startup="true"
channel="outChannel"
auto-create-directory="true">
<int:poller fixed-rate="100"/>
</int-file:inbound-channel-adapter>
<int:channel id="outChannel">
<int:queue/>
</int:channel>
</beans>

View File

@@ -28,7 +28,7 @@ public class FtpInboundRemoteFileSystemSynchronizingMessageSource extends Abstra
}
@Override
protected void onInit() throws Exception {
protected void onInit() {
super.onInit();
this.synchronizer.setClientPool(this.clientPool);
}

View File

@@ -8,9 +8,9 @@
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder
location="file://${user.home}/Desktop/ftp.properties"
ignore-unresolvable="true"/>
<!-- <context:property-placeholder-->
<!-- location="file://${user.home}/Desktop/ftp.properties"-->
<!-- ignore-unresolvable="true"/>-->
<ftp:inbound-channel-adapter remote-directory="${ftp.remotedir}" channel="ftpIn" auto-create-directories="true"

View File

@@ -25,6 +25,7 @@ import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.List;
import java.util.Properties;
import javax.servlet.http.HttpServletResponse;
@@ -40,6 +41,7 @@ import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.http.HttpRequestHandlingController;
import org.springframework.integration.http.HttpRequestHandlingMessagingGateway;
import org.springframework.integration.http.MockHttpServletRequest;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -111,6 +113,11 @@ public class HttpInboundChannelAdapterParserTests {
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
Message<?> message = requests.receive(0);
MessageHistory history = MessageHistory.read(message);
assertNotNull(history);
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "postOnlyAdapter", 0);
assertNotNull(componentHistoryRecord);
assertEquals("http:inbound-channel-adapter", componentHistoryRecord.get("type"));
//System.out.println(componentHistoryRecord);
assertTrue(history.containsComponent("postOnlyAdapter"));
assertNotNull(message);
assertEquals("test", message.getPayload());

View File

@@ -1,4 +1,4 @@
#Mon Mar 01 13:38:53 GMT 2010
#Wed Sep 22 13:42:49 EDT 2010
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources

View File

@@ -85,5 +85,7 @@ public class TcpInboundGateway extends MessagingGatewaySupport implements TcpLis
public void removeDeadConnection(TcpConnection connection) {
connections.remove(connection.getConnectionId());
}
public String getComponentType(){
return "ip:tcp-inbound-gateway";
}
}

View File

@@ -199,5 +199,8 @@ public class UnicastReceivingChannelAdapter extends AbstractInternetProtocolRece
public void setSoSendBufferSize(int soSendBufferSize) {
this.soSendBufferSize = soSendBufferSize;
}
public String getComponentType(){
return "ip:udp-inbound-channel-adapter";
}
}

View File

@@ -20,6 +20,8 @@ import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.Properties;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,6 +33,7 @@ import org.springframework.integration.ip.tcp.connection.AbstractClientConnectio
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
import org.springframework.integration.ip.tcp.connection.TcpConnection;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -69,7 +72,10 @@ public class ConnectionToConnectionTests {
connection.send(MessageBuilder.withPayload("Test").build());
Message<?> message = serverSideChannel.receive(10000);
MessageHistory history = MessageHistory.read(message);
assertTrue(history.containsComponent("looper"));
//org.springframework.integration.test.util.TestUtils
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "looper", 0);
assertNotNull(componentHistoryRecord);
assertTrue(componentHistoryRecord.get("type").equals("ip:tcp-inbound-gateway"));
assertNotNull(message);
assertEquals("Test", new String((byte[]) message.getPayload()));
}

View File

@@ -16,16 +16,17 @@
package org.springframework.integration.ip.udp;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Date;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -36,6 +37,7 @@ 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;
import org.springframework.integration.test.util.TestUtils;
/**
* Sends and receives a simple message through to the Udp channel adapters.
@@ -139,7 +141,9 @@ 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"));
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "udpReceiver", 0);
assertNotNull(componentHistoryRecord);
assertEquals("ip:udp-inbound-channel-adapter", componentHistoryRecord.get("type"));
firstReceived.countDown();
try {
doneProcessing.await();

View File

@@ -25,6 +25,7 @@ import javax.sql.DataSource;
import org.springframework.dao.DataAccessException;
import org.springframework.integration.Message;
import org.springframework.integration.context.IntegrationObjectSupport;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.jdbc.core.ColumnMapRowMapper;
@@ -45,7 +46,7 @@ import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
* @author Dave Syer
* @since 2.0
*/
public class JdbcPollingChannelAdapter implements MessageSource<Object> {
public class JdbcPollingChannelAdapter extends IntegrationObjectSupport implements MessageSource<Object> {
private final SimpleJdbcOperations jdbcOperations;
@@ -199,7 +200,9 @@ public class JdbcPollingChannelAdapter implements MessageSource<Object> {
}
return payload;
}
public String getComponentType(){
return "jdbc:inbound-channel-adapter";
}
}

View File

@@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.sql.DataSource;
@@ -34,6 +35,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.integration.test.util.TestUtils;
import org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.transaction.PlatformTransactionManager;
@@ -57,14 +59,17 @@ public class JdbcPollingChannelAdapterParserTests {
private PlatformTransactionManager transactionManager;
@Test
public void testSimpleInboundChannelAdapter(){
public void testSimpleInboundChannelAdapterWithHistory(){
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<?>);
MessageHistory history = MessageHistory.read(message);
assertNotNull(history);
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "jdbcAdapter", 0);
assertNotNull(componentHistoryRecord);
assertEquals("jdbc:inbound-channel-adapter", componentHistoryRecord.get("type"));
}

View File

@@ -57,5 +57,9 @@
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-test</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -140,5 +140,8 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport {
}
}
}
public String getComponentType(){
return "mail:imap-idle-channel-adapter";
}
}

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.integration.mail;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
@@ -23,6 +25,8 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Properties;
import javax.mail.Flags;
import javax.mail.Flags.Flag;
import javax.mail.Folder;
@@ -39,6 +43,7 @@ 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 org.springframework.integration.test.util.TestUtils;
import com.sun.mail.imap.IMAPFolder;
@@ -237,6 +242,9 @@ public class ImapMailReceiverTests {
adapter.start();
org.springframework.integration.Message<?> replMessage = channel.receive(10000);
MessageHistory history = MessageHistory.read(replMessage);
assertTrue(history.containsComponent("simpleAdapter"));
assertNotNull(history);
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "simpleAdapter", 0);
assertNotNull(componentHistoryRecord);
assertEquals("mail:imap-idle-channel-adapter", componentHistoryRecord.get("type"));
}
}

View File

@@ -90,7 +90,7 @@ public class SftpInboundRemoteFileSystemSynchronizingMessageSource extends Abstr
}
@Override
protected void onInit() throws Exception {
protected void onInit() {
super.onInit();
this.checkThatRemotePathExists(this.remotePath);

View File

@@ -24,6 +24,7 @@ import java.io.UnsupportedEncodingException;
import org.springframework.integration.Message;
import org.springframework.integration.MessagingException;
import org.springframework.integration.context.IntegrationObjectSupport;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.message.GenericMessage;
import org.springframework.util.Assert;
@@ -33,7 +34,7 @@ import org.springframework.util.Assert;
*
* @author Mark Fisher
*/
public class CharacterStreamReadingMessageSource implements MessageSource<String> {
public class CharacterStreamReadingMessageSource extends IntegrationObjectSupport implements MessageSource<String> {
private final BufferedReader reader;
@@ -87,5 +88,8 @@ public class CharacterStreamReadingMessageSource implements MessageSource<String
throw new IllegalArgumentException("unsupported encoding: " + charsetName, e);
}
}
public String getComponentType(){
return "stream:stdin-channel-adapter";
}
}

View File

@@ -16,6 +16,7 @@
package org.springframework.integration.stream.config;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -33,6 +34,7 @@ import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.context.NamedComponent;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
@@ -54,6 +56,10 @@ public class ConsoleInboundChannelAdapterParserTests {
SourcePollingChannelAdapter adapter =
(SourcePollingChannelAdapter) context.getBean("adapterWithDefaultCharset.adapter");
MessageSource<?> source = (MessageSource<?>) new DirectFieldAccessor(adapter).getPropertyValue("source");
assertTrue(source instanceof NamedComponent);
assertEquals("adapterWithDefaultCharset.adapter", adapter.getComponentName());
assertEquals("stream:stdin-channel-adapter", adapter.getComponentType());
assertEquals("stream:stdin-channel-adapter", ((NamedComponent)source).getComponentType());
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(source);
Reader bufferedReader = (Reader) sourceAccessor.getPropertyValue("reader");
assertEquals(BufferedReader.class, bufferedReader.getClass());
@@ -63,6 +69,7 @@ public class ConsoleInboundChannelAdapterParserTests {
Charset readerCharset = Charset.forName(((InputStreamReader) reader).getEncoding());
assertEquals(Charset.defaultCharset(), readerCharset);
Message<?> message = source.receive();
System.out.println(message);
assertNotNull(message);
assertEquals("foo", message.getPayload());
}

View File

@@ -9,6 +9,8 @@
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/stream
http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd">
<integration:message-history/>
<stdin-channel-adapter id="adapterWithDefaultCharset" auto-startup="false"/>

View File

@@ -40,17 +40,21 @@ import org.springframework.integration.context.NamedComponent;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.endpoint.AbstractPollingEndpoint;
import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.PeriodicTrigger;
import org.springframework.util.Assert;
import org.springframework.util.ErrorHandler;
import org.springframework.util.StringUtils;
import java.util.Properties;
import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;
/**
* @author Mark Fisher
* @author Iwein Fuld
* @author Oleg Zhurakousky
*/
public abstract class TestUtils {
@@ -160,4 +164,18 @@ public abstract class TestUtils {
}
};
}
public static Properties locateComponentInHistory(MessageHistory history, String componentName, int startingIndex){
Assert.notNull(history, "'history' must not be null");
Assert.isTrue(StringUtils.hasText(componentName), "'componentName' must be provided");
Assert.isTrue(startingIndex < history.size(), "'startingIndex' can not be greater then size of history");
Properties component = null;
for (int i = startingIndex; i < history.size(); i++) {
Properties properties = history.get(i);
if (componentName.equals(properties.get("name"))){
component = properties;
break;
}
}
return component;
}
}

View File

@@ -98,5 +98,9 @@
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-test</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -194,6 +194,9 @@ public class MarshallingWebServiceInboundGateway extends AbstractMarshallingPayl
public Object sendAndReceive(Object request) {
return super.sendAndReceive(request);
}
public String getComponentType() {
return "ws:outbound-gateway";
}
}
public String getComponentName() {

View File

@@ -130,4 +130,7 @@ public class SimpleWebServiceInboundGateway extends MessagingGatewaySupport impl
}
}
public String getComponentType() {
return "ws:outbound-gateway";
}
}

View File

@@ -15,19 +15,21 @@
*/
package org.springframework.integration.ws.config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Properties;
import javax.xml.transform.Source;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -35,6 +37,7 @@ import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.ws.MarshallingWebServiceInboundGateway;
import org.springframework.integration.ws.SimpleWebServiceInboundGateway;
import org.springframework.oxm.AbstractMarshaller;
@@ -122,7 +125,10 @@ public class WebServiceInboundGatewayParserTests {
marshallingGateway.invoke(context);
Message<?> message = requestsMarshalling.receive(100);
MessageHistory history = MessageHistory.read(message);
assertTrue(history.containsComponent("marshalling"));
assertNotNull(history);
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "marshalling", 0);
assertNotNull(componentHistoryRecord);
assertEquals("ws:outbound-gateway", componentHistoryRecord.get("type"));
}
@Test
public void testMessageHistoryWithSimpleGateway() throws Exception {
@@ -130,6 +136,10 @@ public class WebServiceInboundGatewayParserTests {
payloadExtractingGateway.invoke(context);
Message<?> message = requestsSimple.receive(100);
MessageHistory history = MessageHistory.read(message);
assertTrue(history.containsComponent("extractsPayload"));
assertNotNull(history);
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "extractsPayload", 0);
System.out.println(componentHistoryRecord);
assertNotNull(componentHistoryRecord);
assertEquals("ws:outbound-gateway", componentHistoryRecord.get("type"));
}
}

View File

@@ -79,5 +79,9 @@
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-test</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -99,5 +99,8 @@ public abstract class AbstractXPathRouter extends AbstractChannelNameResolvingMe
protected XPathExpression getXPathExpression() {
return this.xPathExpression;
}
public String getComponentType(){
return "xml:xpath-router";
}
}

View File

@@ -164,5 +164,9 @@ public class XPathMessageSplitter extends AbstractMessageSplitter {
return this.documentBuilderFactory.newDocumentBuilder();
}
}
public String getComponentType(){
return "xml:xpath-splitter";
}
}

View File

@@ -16,7 +16,6 @@
package org.springframework.integration.xml.transformer;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
@@ -35,8 +34,6 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.context.expression.MapAccessor;
import org.springframework.core.io.Resource;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.integration.Message;
import org.springframework.integration.MessageHeaders;
@@ -250,4 +247,7 @@ public class XsltPayloadTransformer extends AbstractTransformer {
public void setXsltParamHeaders(String[] xsltParamHeaders) {
this.xsltParamHeaders = xsltParamHeaders;
}
public String getComponentType(){
return "xml:xslt-transformer";
}
}

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.integration.xml.transformer;
import java.util.Properties;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,12 +27,14 @@ 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.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertFalse;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
/**
@@ -56,7 +60,10 @@ public class XsltTransformerTests {
input.send(message);
Message<?> resultMessage = output.receive();
MessageHistory history = MessageHistory.read(resultMessage);
assertTrue(history.containsComponent("paramHeadersWithStartWildCharacter"));
assertNotNull(history);
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "paramHeadersWithStartWildCharacter", 0);
assertNotNull(componentHistoryRecord);
assertEquals("xml:xslt-transformer", componentHistoryRecord.get("type"));
assertEquals("Wrong payload type",String.class, resultMessage.getPayload().getClass());
assertTrue(((String) resultMessage.getPayload()).contains("testParamValue"));
assertFalse(((String) resultMessage.getPayload()).contains("FOO"));