INT-1903 polishing, more tests
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
<bean id="idGenerator" class="org.mockito.Mockito" factory-method="spy">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.core.MessageIdGenerationTests.SampleIdGeneratorA"/>
|
||||
<bean class="org.springframework.integration.core.MessageIdGenerationTests.SampleIdGenerator"/>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
|
||||
@@ -4,13 +4,7 @@
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
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-2.0.xsd">
|
||||
|
||||
<!-- <bean id="idGenerator" class="org.mockito.Mockito" factory-method="spy"> -->
|
||||
<!-- <constructor-arg> -->
|
||||
<!-- <bean class="org.springframework.integration.core.MessageIdGenerationTests.SampleIdGenerator"/> -->
|
||||
<!-- </constructor-arg> -->
|
||||
<!-- </bean> -->
|
||||
|
||||
|
||||
<int:channel id="input"/>
|
||||
|
||||
<int:service-activator input-channel="input" output-channel="nextA" expression="'nextA'"/>
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.UUID;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
@@ -123,9 +124,29 @@ public class MessageIdGenerationTests {
|
||||
verify(idGenerator, times(0)).generateId();
|
||||
parent.close();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void testCustomIdGenerationWithParentChileIndependentCreationTwoChildrenTwoRegistrars(){
|
||||
// similar to the last test, but should not fail because child AC is closed before second child AC is started
|
||||
@Test
|
||||
public void testCustomIdGenerationWithParentChildIndependentCreationChildrenRegistrarsOneAtTheTime(){
|
||||
ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass());
|
||||
|
||||
GenericXmlApplicationContext childA = new GenericXmlApplicationContext();
|
||||
childA.load("classpath:/org/springframework/integration/core/MessageIdGenerationTests-context-withGenerator.xml");
|
||||
childA.setParent(parent);
|
||||
childA.refresh();
|
||||
|
||||
childA.close();
|
||||
|
||||
GenericXmlApplicationContext childB = new GenericXmlApplicationContext();
|
||||
childB.load("classpath:/org/springframework/integration/core/MessageIdGenerationTests-context-withGenerator.xml");
|
||||
childB.setParent(parent);
|
||||
childB.refresh();
|
||||
|
||||
parent.close();
|
||||
childB.close();
|
||||
}
|
||||
// should fail because both parent and child define IdGenerator instances
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testCustomIdGenerationWithParentChildIndependentCreation(){
|
||||
ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context-withGenerator.xml", this.getClass());
|
||||
|
||||
GenericXmlApplicationContext childA = new GenericXmlApplicationContext();
|
||||
@@ -133,6 +154,21 @@ public class MessageIdGenerationTests {
|
||||
childA.setParent(parent);
|
||||
childA.refresh();
|
||||
}
|
||||
// should fail because second child attempts to register another instance of IdGenerator
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testCustomIdGenerationWithParentChildIndependentCreationChildrenRegistrars(){
|
||||
ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass());
|
||||
|
||||
GenericXmlApplicationContext childA = new GenericXmlApplicationContext();
|
||||
childA.load("classpath:/org/springframework/integration/core/MessageIdGenerationTests-context-withGenerator.xml");
|
||||
childA.setParent(parent);
|
||||
childA.refresh();
|
||||
|
||||
GenericXmlApplicationContext childB = new GenericXmlApplicationContext();
|
||||
childB.load("classpath:/org/springframework/integration/core/MessageIdGenerationTests-context-withGenerator.xml");
|
||||
childB.setParent(parent);
|
||||
childB.refresh();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@@ -178,15 +214,4 @@ public class MessageIdGenerationTests {
|
||||
return UUID.nameUUIDFromBytes(((System.currentTimeMillis() - System.nanoTime()) + "").getBytes());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class SampleIdGeneratorA implements IdGenerator {
|
||||
|
||||
public UUID generateId() {
|
||||
return UUID.nameUUIDFromBytes(((System.currentTimeMillis() - System.nanoTime()) + "").getBytes());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user