checking non-null in compositeconfig.
[xmlrouter] / impl / src / test / java / org / wamblee / xmlrouter / impl / XMLRouterTest.java
index 4bcf2a46929b734e060e9b009b548585d86202ca..2746253de58653f31b04a21d63ef990f89680b44 100644 (file)
@@ -30,6 +30,7 @@ import org.wamblee.general.SystemClock;
 import org.wamblee.xmlrouter.common.Id;
 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;
@@ -65,6 +66,8 @@ public class XMLRouterTest {
         }
     }
 
+    private ExtendedRouterConfig routerConfig;
+    private XMLRouterConfiguration config;
     private XMLRouter router;
     private DOMSource source1;
     private DOMSource source2;
@@ -76,9 +79,12 @@ public class XMLRouterTest {
 
     @Before
     public void setUp() {
+        routerConfig = new SingleRouterConfig(new Id<RouterConfig>(
+            "routerconfig"));
+        config = new XMLRouterConfigurationImpl(routerConfig);
         EventListener logListener = new LoggingEventListener(Level.INFO);
         listener = spy(logListener);
-        router = new XMLRouter(new SystemClock(), listener);
+        router = new XMLRouter(new SystemClock(), config, listener);
         source1 = mock(DOMSource.class);
         source2 = mock(DOMSource.class);
         source3 = mock(DOMSource.class);
@@ -99,7 +105,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 +117,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.
@@ -124,7 +130,7 @@ public class XMLRouterTest {
 
         router.publish("any", source1);
         verify(listener).delivered(any(EventInfo.class),
-            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
+            anyListOf(Transformation.class), anyString(), eq(true));
         verify(destinationSpy).receive(same(source1));
 
         // Unregister the destination.
@@ -144,14 +150,14 @@ public class XMLRouterTest {
         DocumentType type = mock(DocumentType.class);
         when(type.isInstance(any(DOMSource.class))).thenReturn(true);
         when(type.getName()).thenReturn(aType);
-        Id<DocumentType> typeId = router.documentTypeConfig().add(type);
+        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<DocumentType> typeId = router.documentTypeConfig().add(type);
+        routerConfig.documentTypeConfig().add(type);
     }
 
     private Destination registerDestination(boolean aResult, String... types) {
@@ -195,7 +201,7 @@ public class XMLRouterTest {
 
         router.publish("any", source1);
         verify(listener).delivered(any(EventInfo.class),
-            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
+            anyListOf(Transformation.class), anyString(), eq(true));
 
         verify(destinationSpy2).receive(same(source1));
 
@@ -224,7 +230,7 @@ public class XMLRouterTest {
             .registerDestination(destinationSpy2);
         router.publish("any", source1);
         verify(listener).delivered(any(EventInfo.class),
-            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
+            anyListOf(Transformation.class), anyString(), eq(true));
 
         verify(destinationSpy, never()).receive(same(source1));
         verify(destinationSpy2).receive(same(source1));
@@ -255,7 +261,7 @@ public class XMLRouterTest {
             .registerDestination(destinationSpy2);
         router.publish("any", source1);
         verify(listener).delivered(any(EventInfo.class),
-            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
+            anyListOf(Transformation.class), anyString(), eq(true));
 
         verify(destinationSpy, never()).receive(same(source1));
         verify(destinationSpy2).receive(same(source1));
@@ -265,11 +271,13 @@ public class XMLRouterTest {
     public void testOneTransformationOneDestination() {
         registerDocumentType("any");
         Transformation transformation = mock(Transformation.class);
-        when(transformation.getName()).thenReturn("trans");
+        when(transformation.getId())
+            .thenReturn(new Id<Transformation>("trans"));
         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);
+        config.setRouterConfig(routerConfig);
 
         Destination destination = mock(Destination.class);
         when(
@@ -281,7 +289,7 @@ public class XMLRouterTest {
         when(destination.receive(any(DOMSource.class))).thenReturn(true);
         router.publish("bla", source1);
         verify(listener).delivered(any(EventInfo.class),
-            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
+            anyListOf(Transformation.class), anyString(), eq(true));
 
         verify(transformation).transform(source1);
         verify(destination).receive(same(source2));
@@ -296,12 +304,13 @@ public class XMLRouterTest {
     public void testMisbehavingTransformationOneDestination() {
         registerDocumentType("any");
         Transformation transformation = mock(Transformation.class);
-        when(transformation.getName()).thenReturn("trans");
+        when(transformation.getId())
+            .thenReturn(new Id<Transformation>("trans"));
         when(transformation.getFromType()).thenReturn("any");
         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(
@@ -318,7 +327,8 @@ public class XMLRouterTest {
     private Transformation createTransformation(String aFrom, String aTo,
         DOMSource aSource, DOMSource aTarget) {
         Transformation transformation = mock(Transformation.class);
-        when(transformation.getName()).thenReturn("trans");
+        when(transformation.getId())
+            .thenReturn(new Id<Transformation>("trans"));
         when(transformation.getFromType()).thenReturn(aFrom);
         when(transformation.getToType()).thenReturn(aTo);
         when(transformation.transform(same(aSource))).thenReturn(aTarget);
@@ -331,8 +341,8 @@ public class XMLRouterTest {
         Transformation transformation = createTransformation("any", "bla",
             source1, null);
 
-        router.transformationConfig().add(transformation);
-
+        routerConfig.transformationConfig().add(transformation);
+        config.setRouterConfig(routerConfig);
         Destination destination = mock(Destination.class);
         when(
             destination.chooseFromTargetTypes((Collection<String>) anyObject()))
@@ -349,13 +359,15 @@ public class XMLRouterTest {
         Transformation transformation2 = createTransformation("any", "bla2",
             source1, source2);
 
-        router.transformationConfig().add(transformation2);
+        routerConfig.transformationConfig().add(transformation2);
+        config.setRouterConfig(routerConfig);
         when(
             destination.chooseFromTargetTypes((Collection<String>) anyObject()))
             .thenReturn(Arrays.asList("bla", "bla2"));
 
         reset(transformation);
-        when(transformation.getName()).thenReturn("trans");
+        when(transformation.getId())
+            .thenReturn(new Id<Transformation>("trans"));
         when(transformation.getFromType()).thenReturn("any");
         when(transformation.getToType()).thenReturn("bla");
         when(transformation.transform(same(source1))).thenReturn(null);
@@ -363,7 +375,7 @@ public class XMLRouterTest {
         when(destination.receive(any(DOMSource.class))).thenReturn(true);
         router.publish("bla", source1);
         verify(listener).delivered(any(EventInfo.class),
-            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
+            anyListOf(Transformation.class), anyString(), eq(true));
 
         verify(transformation).transform(source1);
         verify(transformation2).transform(source1);
@@ -380,7 +392,7 @@ public class XMLRouterTest {
 
         router.publish("source", source1);
         verify(listener, times(2)).delivered(any(EventInfo.class),
-            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
+            anyListOf(Transformation.class), anyString(), eq(true));
 
         verify(dest1).receive(same(source1));
         verify(dest2).receive(same(source1));
@@ -393,11 +405,12 @@ public class XMLRouterTest {
         registerDocumentType("other", source2);
         Transformation transformation = createTransformation("any", "other",
             source1, source2);
-        router.transformationConfig().add(transformation);
+        routerConfig.transformationConfig().add(transformation);
+        config.setRouterConfig(routerConfig);
 
         router.publish("source", source1);
         verify(listener, times(2)).delivered(any(EventInfo.class),
-            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
+            anyListOf(Transformation.class), anyString(), eq(true));
 
         verify(dest).receive(same(source1));
         verify(dest).receive(same(source2));
@@ -411,14 +424,15 @@ 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);
+        config.setRouterConfig(routerConfig);
 
         router.publish("source", source1);
         verify(listener).delivered(any(EventInfo.class),
-            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
+            anyListOf(Transformation.class), anyString(), eq(true));
 
         verify(dest).receive(same(source3));
     }
@@ -438,7 +452,7 @@ public class XMLRouterTest {
         router.publish("source", source1);
 
         verify(listener).delivered(any(EventInfo.class),
-            anyListOf(Transformation.class), anyLong(), anyString(), eq(false));
+            anyListOf(Transformation.class), anyString(), eq(false));
 
     }
 }