X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FXMLRouterFunctionTest.java;fp=impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FXMLRouterFunctionTest.java;h=0000000000000000000000000000000000000000;hb=8e41cb29f75362a792292d21b481bd06a9506296;hp=cc663438a2b5853727b6af25dab2c7a3607a383e;hpb=9dbc2844950b55ae552fe74840954ea71b754c7a;p=xmlrouter diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterFunctionTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterFunctionTest.java deleted file mode 100644 index cc66343..0000000 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterFunctionTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2005-2011 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.wamblee.xmlrouter.impl; - -import static org.mockito.Matchers.*; -import static org.mockito.Mockito.*; - -import java.util.Arrays; -import java.util.Collection; -import java.util.logging.Level; - -import javax.xml.transform.dom.DOMSource; - -import org.junit.Before; -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.Transformation; -import org.wamblee.xmlrouter.listener.EventInfo; -import org.wamblee.xmlrouter.listener.EventListener; -import org.wamblee.xmlrouter.listener.LoggingEventListener; -import org.wamblee.xmlrouter.subscribe.Destination; - -public class XMLRouterFunctionTest { - - private XMLRouterConfiguration config; - private XMLRouter routerService; - private XMLRouterConfigService configService; - - private EventListener listener; - - private DOMSource source1; - private DOMSource source2; - - @Before - public void setUp() { - config = new XMLRouterConfigurationImpl(); - EventListener logListener = new LoggingEventListener(Level.INFO); - listener = spy(logListener); - routerService = new XMLRouter(new SystemClock(), config, listener); - configService = new XMLRouterConfigService("app", config); - - source1 = mock(DOMSource.class); - source2 = mock(DOMSource.class); - } - - private RouterConfig registerDocumentType(String aType) { - DocumentType type = mock(DocumentType.class); - when(type.isInstance(any(DOMSource.class))).thenReturn(true); - when(type.getName()).thenReturn(aType); - when(type.getId()).thenReturn(new Id(aType)); - RouterConfig routerConfig = configService.emptyConfig("app"); - routerConfig.documentTypeConfig().add(type); - return routerConfig; - } - - @Test - public void testOneTransformationOneDestination() { - RouterConfig routerConfig = registerDocumentType("any"); - Transformation transformation = mock(Transformation.class); - when(transformation.getId()) - .thenReturn(new Id("trans")); - when(transformation.getFromType()).thenReturn("any"); - when(transformation.getToType()).thenReturn("bla"); - when(transformation.transform(same(source1))).thenReturn(source2); - routerConfig.transformationConfig().add(transformation); - - configService.apply(routerConfig, null); - - Destination destination = mock(Destination.class); - when( - destination.chooseFromTargetTypes((Collection) anyObject())) - .thenReturn(Arrays.asList("bla")); - - routerService.registerDestination(destination); - - when(destination.receive(any(DOMSource.class))).thenReturn(true); - routerService.publish("bla", source1); - verify(listener).delivered(any(EventInfo.class), - anyListOf(Transformation.class), anyString(), eq(true)); - - verify(transformation).transform(source1); - verify(destination).receive(same(source2)); - - // now the same when the destination rejects the event. - when(destination.receive(any(DOMSource.class))).thenReturn(false); - routerService.publish("bla", source1); - verify(listener).notDelivered(any(EventInfo.class)); - } -}