From: Erik Brakkee Date: Sat, 30 Jul 2011 18:27:48 +0000 (+0200) Subject: XML router now uses config object passed in through constructor. X-Git-Tag: PAX_EXAM_MOCKITO_ISSUE~30 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=d96c59e2c9e5b15c4ce2023ac93d70b4c0ddf568;p=xmlrouter XML router now uses config object passed in through constructor. --- diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java index ca0637b..d74c93d 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java @@ -31,10 +31,8 @@ import javax.xml.transform.dom.DOMSource; import org.wamblee.general.Clock; import org.wamblee.xml.XMLDocument; import org.wamblee.xmlrouter.common.Id; -import org.wamblee.xmlrouter.config.Config; import org.wamblee.xmlrouter.config.DocumentType; import org.wamblee.xmlrouter.config.Filter; -import org.wamblee.xmlrouter.config.RouterConfig; import org.wamblee.xmlrouter.config.Transformation; import org.wamblee.xmlrouter.listener.EventInfo; import org.wamblee.xmlrouter.listener.EventListener; @@ -48,7 +46,7 @@ import org.wamblee.xmlrouter.subscribe.DestinationRegistry; * @author Erik Brakkee * */ -public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry { +public class XMLRouter implements Gateway, DestinationRegistry { private static final Logger LOGGER = Logger.getLogger(XMLRouter.class .getName()); @@ -63,31 +61,17 @@ public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry { private Map, Destination> destinations; - public XMLRouter(Clock aClock, EventListener aListener) { + public XMLRouter(Clock aClock, ExtendedRouterConfig aRouterConfig, + EventListener aListener) { sequenceNumbers = new AtomicLong(1); listener = aListener; clock = aClock; nextEventId = new AtomicLong(clock.currentTimeMillis()); - routerConfig = new SingleRouterConfig(sequenceNumbers); + routerConfig = aRouterConfig; transformations = new TransformationPaths(); destinations = new LinkedHashMap, Destination>(); } - @Override - public Config documentTypeConfig() { - return routerConfig.documentTypeConfig(); - } - - @Override - public Config transformationConfig() { - return routerConfig.transformationConfig(); - } - - @Override - public Config filterConfig() { - return routerConfig.filterConfig(); - } - @Override public void publish(String aSource, DOMSource aEvent) { long time = clock.currentTimeMillis(); diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java index 4bcf2a4..eeb05aa 100644 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.*; import java.util.Arrays; import java.util.Collection; +import java.util.concurrent.atomic.AtomicLong; import java.util.logging.Level; import javax.xml.transform.dom.DOMSource; @@ -65,6 +66,7 @@ public class XMLRouterTest { } } + private ExtendedRouterConfig routerConfig; private XMLRouter router; private DOMSource source1; private DOMSource source2; @@ -76,9 +78,10 @@ public class XMLRouterTest { @Before public void setUp() { + routerConfig = new SingleRouterConfig(new AtomicLong(1L)); EventListener logListener = new LoggingEventListener(Level.INFO); listener = spy(logListener); - router = new XMLRouter(new SystemClock(), listener); + router = new XMLRouter(new SystemClock(), routerConfig, listener); source1 = mock(DOMSource.class); source2 = mock(DOMSource.class); source3 = mock(DOMSource.class); @@ -99,7 +102,7 @@ public class XMLRouterTest { DocumentType type = mock(DocumentType.class); doThrow(new RuntimeException("x")).when(type).isInstance( any(DOMSource.class)); - router.documentTypeConfig().add(type); + routerConfig.documentTypeConfig().add(type); router.publish("xx", mock(DOMSource.class)); verify(listener).notDelivered(any(EventInfo.class)); // no exception should occur. @@ -111,7 +114,7 @@ public class XMLRouterTest { Filter filter = mock(Filter.class); doThrow(new RuntimeException("x")).when(filter).isAllowed(anyString(), any(DOMSource.class)); - router.filterConfig().add(filter); + routerConfig.filterConfig().add(filter); router.publish("xx", mock(DOMSource.class)); verify(listener).notDelivered(any(EventInfo.class)); // no exception should occur. @@ -144,14 +147,14 @@ public class XMLRouterTest { DocumentType type = mock(DocumentType.class); when(type.isInstance(any(DOMSource.class))).thenReturn(true); when(type.getName()).thenReturn(aType); - Id typeId = router.documentTypeConfig().add(type); + Id typeId = routerConfig.documentTypeConfig().add(type); } private void registerDocumentType(String aType, DOMSource aSource) { DocumentType type = mock(DocumentType.class); when(type.isInstance(same(aSource))).thenReturn(true); when(type.getName()).thenReturn(aType); - Id typeId = router.documentTypeConfig().add(type); + Id typeId = routerConfig.documentTypeConfig().add(type); } private Destination registerDestination(boolean aResult, String... types) { @@ -269,7 +272,7 @@ public class XMLRouterTest { when(transformation.getFromType()).thenReturn("any"); when(transformation.getToType()).thenReturn("bla"); when(transformation.transform(same(source1))).thenReturn(source2); - router.transformationConfig().add(transformation); + routerConfig.transformationConfig().add(transformation); Destination destination = mock(Destination.class); when( @@ -301,7 +304,7 @@ public class XMLRouterTest { when(transformation.getToType()).thenReturn("bla"); doThrow(new RuntimeException("x")).when(transformation).transform( same(source1)); - router.transformationConfig().add(transformation); + routerConfig.transformationConfig().add(transformation); Destination destination = mock(Destination.class); when( @@ -331,7 +334,7 @@ public class XMLRouterTest { Transformation transformation = createTransformation("any", "bla", source1, null); - router.transformationConfig().add(transformation); + routerConfig.transformationConfig().add(transformation); Destination destination = mock(Destination.class); when( @@ -349,7 +352,7 @@ public class XMLRouterTest { Transformation transformation2 = createTransformation("any", "bla2", source1, source2); - router.transformationConfig().add(transformation2); + routerConfig.transformationConfig().add(transformation2); when( destination.chooseFromTargetTypes((Collection) anyObject())) .thenReturn(Arrays.asList("bla", "bla2")); @@ -393,7 +396,7 @@ public class XMLRouterTest { registerDocumentType("other", source2); Transformation transformation = createTransformation("any", "other", source1, source2); - router.transformationConfig().add(transformation); + routerConfig.transformationConfig().add(transformation); router.publish("source", source1); verify(listener, times(2)).delivered(any(EventInfo.class), @@ -411,10 +414,10 @@ public class XMLRouterTest { Transformation t1 = createTransformation("any", "intermediate", source1, source2); - router.transformationConfig().add(t1); + routerConfig.transformationConfig().add(t1); Transformation t2 = createTransformation("intermediate", "other", source2, source3); - router.transformationConfig().add(t2); + routerConfig.transformationConfig().add(t2); router.publish("source", source1); verify(listener).delivered(any(EventInfo.class),