From b9e846933c375efa04ee58497e0d317cb67dac6e Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Mon, 16 May 2011 17:03:55 -0400 Subject: [PATCH] INT-1903 polishing --- .../config/IdGeneratorConfigurer.java | 6 +-- .../core/MessageIdGenerationTests.java | 49 +++++++++---------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IdGeneratorConfigurer.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IdGeneratorConfigurer.java index dda730fef3..e679ee6171 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/IdGeneratorConfigurer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IdGeneratorConfigurer.java @@ -71,11 +71,7 @@ public final class IdGeneratorConfigurer implements ApplicationListener(0)); verify(idGenerator, times(4)).generateId(); reset(idGenerator); - context.close(); + child.close(); new GenericMessage(0); verify(idGenerator, times(1)).generateId(); } @Test public void testCustomIdGenerationWithParentRegistrarClosed(){ - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context-a.xml", this.getClass()); - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"MessageIdGenerationTests-context.xml"}, this.getClass(), ctx); + ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context-a.xml", this.getClass()); + ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(new String[]{"MessageIdGenerationTests-context.xml"}, this.getClass(), parent); - IdGenerator idGenerator = context.getBean("idGenerator", IdGenerator.class); - MessageChannel inputChannel = context.getBean("input", MessageChannel.class); + IdGenerator idGenerator = child.getBean("idGenerator", IdGenerator.class); + MessageChannel inputChannel = child.getBean("input", MessageChannel.class); inputChannel.send(new GenericMessage(0)); verify(idGenerator, times(4)).generateId(); reset(idGenerator); - ctx.close(); + parent.close(); new GenericMessage(0); verify(idGenerator, times(0)).generateId(); } @Test public void testCustomIdGenerationWithChildRegistrar(){ - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass()); - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"MessageIdGenerationTests-context-a.xml"}, this.getClass(), ctx); + ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass()); + ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(new String[]{"MessageIdGenerationTests-context-a.xml"}, this.getClass(), parent); - IdGenerator idGenerator = context.getBean("idGenerator", IdGenerator.class); - MessageChannel inputChannel = context.getBean("input", MessageChannel.class); + IdGenerator idGenerator = child.getBean("idGenerator", IdGenerator.class); + MessageChannel inputChannel = child.getBean("input", MessageChannel.class); inputChannel.send(new GenericMessage(0)); verify(idGenerator, times(4)).generateId(); reset(idGenerator); - ctx.close(); + parent.close(); new GenericMessage(0); verify(idGenerator, times(1)).generateId(); } @Test public void testCustomIdGenerationWithChildRegistrarClosed(){ - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass()); - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"MessageIdGenerationTests-context-a.xml"}, this.getClass(), ctx); + ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass()); + ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(new String[]{"MessageIdGenerationTests-context-a.xml"}, this.getClass(), parent); - IdGenerator idGenerator = context.getBean("idGenerator", IdGenerator.class); - MessageChannel inputChannel = context.getBean("input", MessageChannel.class); + IdGenerator idGenerator = child.getBean("idGenerator", IdGenerator.class); + MessageChannel inputChannel = child.getBean("input", MessageChannel.class); inputChannel.send(new GenericMessage(0)); verify(idGenerator, times(4)).generateId(); reset(idGenerator); - context.close(); + child.close(); new GenericMessage(0); verify(idGenerator, times(0)).generateId(); } @@ -142,9 +142,7 @@ public class MessageIdGenerationTests { public static class SampleIdGenerator implements IdGenerator { - public SampleIdGenerator(){ - System.out.println("Generator"); - } + public UUID generateId() { return UUID.nameUUIDFromBytes(((System.currentTimeMillis() - System.nanoTime()) + "").getBytes()); } @@ -152,10 +150,7 @@ public class MessageIdGenerationTests { } public static class SampleIdGeneratorA implements IdGenerator { - public SampleIdGeneratorA(){ - System.out.println("Generator A"); - } - + public UUID generateId() { return UUID.nameUUIDFromBytes(((System.currentTimeMillis() - System.nanoTime()) + "").getBytes()); }