added tests
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
target
|
||||
.settings
|
||||
.springBeans
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
<config>src/test/resources/META-INF/spring/integration/flows/subflow1/subflow1-context.xml</config>
|
||||
<config>src/test/resources/TransactionalFlowTest-context.xml</config>
|
||||
<config>src/test/resources/txmanager-config.xml</config>
|
||||
<config>src/test/resources/autowired-referenced-beans.xml</config>
|
||||
<config>src/test/resources/META-INF/spring/integration/flows/autowired/autowired-flow-context.xml</config>
|
||||
<config>src/test/resources/FlowWithAutowireTest-context.xml</config>
|
||||
</configs>
|
||||
<configSets>
|
||||
</configSets>
|
||||
|
||||
8
pom.xml
8
pom.xml
@@ -63,13 +63,7 @@
|
||||
<version>${spring.framework.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-jms</artifactId>
|
||||
<version>${spring.integration.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionValidationException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
@@ -139,7 +140,10 @@ public class Flow implements InitializingBean, BeanNameAware, ChannelResolver, A
|
||||
this.flowContext.setConfigLocations(configLocations);
|
||||
|
||||
this.flowContext.refresh();
|
||||
|
||||
|
||||
// Deep debug
|
||||
// FlowUtils.displayBeansGraph(flowContext.getBeanFactory());
|
||||
//
|
||||
this.flowConfiguration = flowContext.getBean(FlowConfiguration.class);
|
||||
Assert.notNull(flowConfiguration, "flow context does not contain a flow configuration");
|
||||
|
||||
@@ -247,7 +251,7 @@ public class Flow implements InitializingBean, BeanNameAware, ChannelResolver, A
|
||||
|
||||
List<String> channelNames = Arrays.asList(this.flowContext.getBeanNamesForType(MessageChannel.class));
|
||||
|
||||
Set<String> referencedMessageChannels = FlowUtils.getReferencedMessageChannels(this.flowContext.getBeanFactory(),5);
|
||||
Set<String> referencedMessageChannels = FlowUtils.getReferencedMessageChannels(this.flowContext.getBeanFactory());
|
||||
|
||||
for (String referencedMessageChannel: referencedMessageChannels) {
|
||||
if (!channelNames.contains(referencedMessageChannel)) {
|
||||
|
||||
@@ -17,8 +17,11 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
@@ -29,6 +32,7 @@ import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.core.SubscribableChannel;
|
||||
import org.springframework.integration.handler.BridgeHandler;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Utility functions used by the flow parsers
|
||||
@@ -109,12 +113,40 @@ public class FlowUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<String> getReferencedMessageChannels(ConfigurableListableBeanFactory beanFactory, int max) {
|
||||
public static void displayBeansGraph(ConfigurableListableBeanFactory beanFactory) {
|
||||
String[] beans = beanFactory.getBeanNamesForType(Object.class);
|
||||
_displayDependencies(beanFactory, beans, 0);
|
||||
}
|
||||
|
||||
private static void _displayDependencies(ConfigurableListableBeanFactory beanFactory, String[] beans, int level) {
|
||||
for (int i = 0; i < beans.length; i++) {
|
||||
|
||||
System.out.println(indent(level) + beans[i]);
|
||||
|
||||
String[] dependencies = beanFactory.getDependenciesForBean(beans[i]);
|
||||
String[] depsArray = new String[dependencies.length];
|
||||
int index = 0;
|
||||
for (String dependency : dependencies) {
|
||||
if (!dependency.equals(beans[i])) {
|
||||
|
||||
depsArray[index++] = dependency;
|
||||
} else {
|
||||
System.out.println(indent(level+1) + beans[i]);
|
||||
}
|
||||
}
|
||||
if (depsArray.length > 0) {
|
||||
_displayDependencies(beanFactory, Arrays.copyOf(depsArray, index), level + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Set<String> getReferencedMessageChannels(ConfigurableListableBeanFactory beanFactory) {
|
||||
String[] beans = beanFactory.getBeanNamesForType(Object.class);
|
||||
Set<String> messageChannels = new HashSet<String>();
|
||||
_getReferencedMessageChannels(beanFactory, beans, messageChannels);
|
||||
return Collections.unmodifiableSet(messageChannels);
|
||||
|
||||
}
|
||||
|
||||
private static void _getReferencedMessageChannels(ConfigurableListableBeanFactory beanFactory, String[] beans,
|
||||
@@ -140,4 +172,13 @@ public class FlowUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static String indent(int size) {
|
||||
String indent = "";
|
||||
for (int i = 0; i < size; i++) {
|
||||
indent += " ";
|
||||
}
|
||||
return indent;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.PublishSubscribeChannel;
|
||||
@@ -36,5 +38,11 @@ public class FlowUtilsTest {
|
||||
assertSame(message, result);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayDependencies() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("META-INF/spring/integration/flows/subflow5/subflow5-context.xml");
|
||||
FlowUtils.displayBeansGraph(ctx.getBeanFactory());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.springframework.integration.flow.config.xml;
|
||||
|
||||
public class Bar {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.springframework.integration.flow.config.xml;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/FlowWithAutowireTest-context.xml")
|
||||
public class FlowWithAutowireTest {
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.springframework.integration.flow.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class Foo {
|
||||
@Autowired
|
||||
Bar bar;
|
||||
}
|
||||
9
src/test/resources/FlowWithAutowireTest-context.xml
Normal file
9
src/test/resources/FlowWithAutowireTest-context.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?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-flow="http://www.springframework.org/schema/integration/flow"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration/flow http://www.springframework.org/schema/integration/flow/spring-integration-flow-2.1.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<int-flow:flow id="autowired" referenced-bean-locations="classpath:autowired-referenced-beans.xml"/>
|
||||
</beans>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?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-flow="http://www.springframework.org/schema/integration/flow"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsd
|
||||
http://www.springframework.org/schema/integration/flow http://www.springframework.org/schema/integration/flow/spring-integration-flow-2.1.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
|
||||
|
||||
<context:annotation-config/>
|
||||
|
||||
<int-flow:flow-configuration>
|
||||
<int-flow:port-mapping input-channel="inputChannel" output-channel="outputChannel"/>
|
||||
</int-flow:flow-configuration>
|
||||
|
||||
<int:channel id="outputChannel"/>
|
||||
|
||||
</beans>
|
||||
8
src/test/resources/autowired-referenced-beans.xml
Normal file
8
src/test/resources/autowired-referenced-beans.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean class="org.springframework.integration.flow.config.xml.Foo"/>
|
||||
<bean class="org.springframework.integration.flow.config.xml.Bar"/>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user