X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FXMLRouterTest.java;h=4bcf2a46929b734e060e9b009b548585d86202ca;hb=19413a6699295b4bbebc1b3bdb9838fd4370e581;hp=47eb21a9d7226708946e0f0da4b4cb5a62f33a31;hpb=20807d81708bd33b3b5a4616fadcf3ae91bf9508;p=xmlrouter 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 47eb21a..4bcf2a4 100644 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java @@ -29,6 +29,7 @@ import org.junit.Test; 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.Transformation; import org.wamblee.xmlrouter.listener.EventInfo; import org.wamblee.xmlrouter.listener.EventListener; @@ -93,6 +94,29 @@ public class XMLRouterTest { verify(listener).notDelivered(any(EventInfo.class)); } + @Test + public void testMisBehavingDocumentType() { + DocumentType type = mock(DocumentType.class); + doThrow(new RuntimeException("x")).when(type).isInstance( + any(DOMSource.class)); + router.documentTypeConfig().add(type); + router.publish("xx", mock(DOMSource.class)); + verify(listener).notDelivered(any(EventInfo.class)); + // no exception should occur. + } + + @Test + public void testMisBehavingFilter() { + registerDocumentType("any"); + Filter filter = mock(Filter.class); + doThrow(new RuntimeException("x")).when(filter).isAllowed(anyString(), + any(DOMSource.class)); + router.filterConfig().add(filter); + router.publish("xx", mock(DOMSource.class)); + verify(listener).notDelivered(any(EventInfo.class)); + // no exception should occur. + } + @Test public void testOneDestinationNoTransformationSuccess() { destinationSpy = registerDestination(true, "any"); @@ -120,14 +144,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.addDocumentType(type); + Id typeId = router.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.addDocumentType(type); + Id typeId = router.documentTypeConfig().add(type); } private Destination registerDestination(boolean aResult, String... types) { @@ -245,7 +269,7 @@ public class XMLRouterTest { when(transformation.getFromType()).thenReturn("any"); when(transformation.getToType()).thenReturn("bla"); when(transformation.transform(same(source1))).thenReturn(source2); - router.addTransformation(transformation); + router.transformationConfig().add(transformation); Destination destination = mock(Destination.class); when( @@ -268,6 +292,29 @@ public class XMLRouterTest { verify(listener).notDelivered(any(EventInfo.class)); } + @Test + public void testMisbehavingTransformationOneDestination() { + registerDocumentType("any"); + Transformation transformation = mock(Transformation.class); + when(transformation.getName()).thenReturn("trans"); + when(transformation.getFromType()).thenReturn("any"); + when(transformation.getToType()).thenReturn("bla"); + doThrow(new RuntimeException("x")).when(transformation).transform( + same(source1)); + router.transformationConfig().add(transformation); + + Destination destination = mock(Destination.class); + when( + destination.chooseFromTargetTypes((Collection) anyObject())) + .thenReturn(Arrays.asList("bla")); + + router.registerDestination(destination); + + when(destination.receive(any(DOMSource.class))).thenReturn(true); + router.publish("bla", source1); + verify(listener).notDelivered(any(EventInfo.class)); + } + private Transformation createTransformation(String aFrom, String aTo, DOMSource aSource, DOMSource aTarget) { Transformation transformation = mock(Transformation.class); @@ -284,7 +331,7 @@ public class XMLRouterTest { Transformation transformation = createTransformation("any", "bla", source1, null); - router.addTransformation(transformation); + router.transformationConfig().add(transformation); Destination destination = mock(Destination.class); when( @@ -302,7 +349,7 @@ public class XMLRouterTest { Transformation transformation2 = createTransformation("any", "bla2", source1, source2); - router.addTransformation(transformation2); + router.transformationConfig().add(transformation2); when( destination.chooseFromTargetTypes((Collection) anyObject())) .thenReturn(Arrays.asList("bla", "bla2")); @@ -346,7 +393,7 @@ public class XMLRouterTest { registerDocumentType("other", source2); Transformation transformation = createTransformation("any", "other", source1, source2); - router.addTransformation(transformation); + router.transformationConfig().add(transformation); router.publish("source", source1); verify(listener, times(2)).delivered(any(EventInfo.class), @@ -364,10 +411,10 @@ public class XMLRouterTest { Transformation t1 = createTransformation("any", "intermediate", source1, source2); - router.addTransformation(t1); + router.transformationConfig().add(t1); Transformation t2 = createTransformation("intermediate", "other", source2, source3); - router.addTransformation(t2); + router.transformationConfig().add(t2); router.publish("source", source1); verify(listener).delivered(any(EventInfo.class),