INT-1903 polishing, more tests

This commit is contained in:
Oleg Zhurakousky
2011-05-17 09:11:03 -04:00
parent 396b8ecb3c
commit a494414b64
4 changed files with 63 additions and 29 deletions

View File

@@ -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>

View File

@@ -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'"/>

View File

@@ -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());
}
}
}
}}