From f70baadfd579f4d3aa2e8c9ee7d758fb37d7872f Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Sat, 30 Jul 2011 22:22:36 +0200 Subject: [PATCH] added first version of configuraiton api and simple function test. --- ...gServiceImpl.java => CompositeConfig.java} | 47 ++++---- .../xmlrouter/impl/CompositeRouterConfig.java | 57 ++++++++++ .../wamblee/xmlrouter/impl/ConfigImpl.java | 10 -- .../xmlrouter/impl/ExtendedConfig.java | 3 - .../xmlrouter/impl/ExtendedRouterConfig.java | 12 --- .../xmlrouter/impl/SingleRouterConfig.java | 14 --- .../org/wamblee/xmlrouter/impl/XMLRouter.java | 17 +-- .../impl/XMLRouterConfigService.java | 94 ++++++++++++++++ .../impl/XMLRouterConfiguration.java | 12 ++- .../impl/XMLRouterConfigurationImpl.java | 23 +++- .../xmlrouter/impl/ConfigImplTest.java | 11 -- .../impl/SingleRouterConfigTest.java | 15 --- .../xmlrouter/impl/XMLRouterFunctionTest.java | 102 ++++++++++++++++++ .../wamblee/xmlrouter/impl/XMLRouterTest.java | 13 ++- 14 files changed, 325 insertions(+), 105 deletions(-) rename impl/src/main/java/org/wamblee/xmlrouter/impl/{RouterConfigServiceImpl.java => CompositeConfig.java} (51%) create mode 100644 impl/src/main/java/org/wamblee/xmlrouter/impl/CompositeRouterConfig.java create mode 100644 impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfigService.java create mode 100644 impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterFunctionTest.java diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/RouterConfigServiceImpl.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/CompositeConfig.java similarity index 51% rename from impl/src/main/java/org/wamblee/xmlrouter/impl/RouterConfigServiceImpl.java rename to impl/src/main/java/org/wamblee/xmlrouter/impl/CompositeConfig.java index 76fd26f..b378052 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/RouterConfigServiceImpl.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/CompositeConfig.java @@ -15,35 +15,44 @@ */ package org.wamblee.xmlrouter.impl; +import java.util.LinkedHashMap; +import java.util.Map; + import org.wamblee.xmlrouter.common.Id; -import org.wamblee.xmlrouter.config.RouterConfig; -import org.wamblee.xmlrouter.config.RouterConfigService; +import org.wamblee.xmlrouter.config.Config; -/** - * Router configuration service providing an atomic configuration API for the - * XML router. - * - * @author Erik Brakkee - */ -public class RouterConfigServiceImpl implements RouterConfigService { +public class CompositeConfig implements ExtendedConfig { - @Override - public RouterConfig emptyConfig() { - // TODO Auto-generated method stub - return null; + private Map, T> configs; + + public CompositeConfig() { + configs = new LinkedHashMap, T>(); + } + + public void add(Config aConfig) { + for (Id id : aConfig.map().keySet()) { + configs.put(id, aConfig.map().get(id)); + } } @Override - public Id apply(RouterConfig aConfig, - Id aOldConfig) { - // TODO Auto-generated method stub - return null; + public Map, T> map() { + return configs; } @Override - public void clear(Id aConfig) { - // TODO Auto-generated method stub + public boolean remove(Id aId) { + notSupported(); + return false; + } + private void notSupported() { + throw new RuntimeException("readonly instance"); } + @Override + public Id add(T aT) { + notSupported(); + return null; + } } diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/CompositeRouterConfig.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/CompositeRouterConfig.java new file mode 100644 index 0000000..5ba6571 --- /dev/null +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/CompositeRouterConfig.java @@ -0,0 +1,57 @@ +/* + * 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 java.util.Collection; + +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; + +public class CompositeRouterConfig implements ExtendedRouterConfig { + + private CompositeConfig documentTypes; + private CompositeConfig transformations; + private CompositeConfig filters; + + public CompositeRouterConfig(Collection aConfigs) { + documentTypes = new CompositeConfig(); + transformations = new CompositeConfig(); + filters = new CompositeConfig(); + for (RouterConfig config : aConfigs) { + documentTypes.add(config.documentTypeConfig()); + transformations.add(config.transformationConfig()); + filters.add(config.filterConfig()); + } + } + + @Override + public Config documentTypeConfig() { + return documentTypes; + } + + @Override + public Config transformationConfig() { + return transformations; + } + + @Override + public Config filterConfig() { + return filters; + } +} diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java index 54c0c6d..e29725e 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java @@ -101,14 +101,4 @@ public abstract class ConfigImpl implements ExtendedConfig { throw new NullPointerException("Id is null"); } } - - @Override - public boolean isDirty() { - return dirty; - } - - @Override - public void resetDirty() { - dirty = false; - } } diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/ExtendedConfig.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/ExtendedConfig.java index 070a52a..232e54d 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/ExtendedConfig.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/ExtendedConfig.java @@ -19,7 +19,4 @@ import org.wamblee.xmlrouter.config.Config; public interface ExtendedConfig extends Config { - boolean isDirty(); - - void resetDirty(); } diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/ExtendedRouterConfig.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/ExtendedRouterConfig.java index 94b7128..f8b0f75 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/ExtendedRouterConfig.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/ExtendedRouterConfig.java @@ -29,16 +29,4 @@ public interface ExtendedRouterConfig extends RouterConfig { * Locks the configuration object from further changes. */ // void lock(); - - /** - * Checks whether or not the configuration has changed. - * - * @return True iff dirty. - */ - boolean isDirty(); - - /** - * Resets the router configuration dirty state. - */ - void resetDirty(); } diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/SingleRouterConfig.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/SingleRouterConfig.java index 36016ca..c58ef89 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/SingleRouterConfig.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/SingleRouterConfig.java @@ -78,18 +78,4 @@ public class SingleRouterConfig implements ExtendedRouterConfig { public Config filterConfig() { return filters; } - - @Override - public boolean isDirty() { - return documentTypes.isDirty() || transformations.isDirty() || - filters.isDirty(); - } - - @Override - public void resetDirty() { - documentTypes.resetDirty(); - filters.resetDirty(); - transformations.resetDirty(); - } - } 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 637440f..a203f93 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java @@ -83,13 +83,6 @@ public class XMLRouter implements Gateway, DestinationRegistry { private void publishImpl(String aSource, DOMSource aEvent) { long time = clock.currentTimeMillis(); - // TODO dirty flag will become unnecessary in the future. - if (config.routerConfig().isDirty()) { - config.transformations().replaceTransformations( - config.routerConfig().transformationConfig().map()); - config.routerConfig().resetDirty(); - } - Id id = new Id(nextEventId.getAndIncrement()); List types = determineDocumentTypes(aEvent); EventInfo info = new EventInfo(time, aSource, id, types, aEvent); @@ -132,7 +125,7 @@ public class XMLRouter implements Gateway, DestinationRegistry { boolean delivered = false; Set possibleTargetTypes = new HashSet(); - possibleTargetTypes.addAll(config.transformations() + possibleTargetTypes.addAll(config.getTransformations() .getPossibleTargetTypes(aInputType)); // ask each destination what target types, if any they want to have. @@ -145,8 +138,8 @@ public class XMLRouter implements Gateway, DestinationRegistry { if (!requested.isEmpty()) { // Deliver to the destination. for (String targetType : requested) { - TransformationPath path = config.transformations().getPath( - aInputType, targetType); + TransformationPath path = config.getTransformations() + .getPath(aInputType, targetType); List ts = path.getTransformations(); int i = 0; boolean allowed = true; @@ -196,7 +189,7 @@ public class XMLRouter implements Gateway, DestinationRegistry { private boolean isAllowedByFilters(String aType, DOMSource aEvent) { boolean allowed = true; - for (Filter filter : config.routerConfig().filterConfig().map() + for (Filter filter : config.getRouterConfig().filterConfig().map() .values()) { if (!filter.isAllowed(aType, aEvent)) { allowed = false; @@ -207,7 +200,7 @@ public class XMLRouter implements Gateway, DestinationRegistry { private List determineDocumentTypes(DOMSource aEvent) { List res = new ArrayList(); - for (DocumentType type : config.routerConfig().documentTypeConfig() + for (DocumentType type : config.getRouterConfig().documentTypeConfig() .map().values()) { if (type.isInstance(aEvent)) { res.add(type.getName()); diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfigService.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfigService.java new file mode 100644 index 0000000..ca5e417 --- /dev/null +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfigService.java @@ -0,0 +1,94 @@ +/* + * 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 java.util.concurrent.atomic.AtomicLong; + +import org.wamblee.xmlrouter.common.Id; +import org.wamblee.xmlrouter.config.Config; +import org.wamblee.xmlrouter.config.RouterConfig; +import org.wamblee.xmlrouter.config.RouterConfigService; + +/** + * Router configuration service providing an atomic configuration API for the + * XML router. + * + * @author Erik Brakkee + */ +public class XMLRouterConfigService implements RouterConfigService { + + private AtomicLong sequence; + private XMLRouterConfiguration config; + private Config routerConfigs; + + public XMLRouterConfigService(XMLRouterConfiguration aConfig) { + sequence = new AtomicLong(1L); + config = aConfig; + routerConfigs = new ConfigImpl(sequence) { + public RouterConfig wrap(Id aId, RouterConfig aT) { + return aT; + } + }; + } + + @Override + public RouterConfig emptyConfig() { + return new SingleRouterConfig(sequence); + } + + @Override + public Id apply(RouterConfig aConfig, + Id aOldConfig) { + config.startConfigurationChange(); + try { + return applyImpl(aConfig, aOldConfig); + } finally { + config.endConfigurationChange(); + } + } + + private Id applyImpl(RouterConfig aConfig, + Id aOldConfig) { + if (aOldConfig != null) { + routerConfigs.remove(aOldConfig); + } + Id id = routerConfigs.add(aConfig); + update(); + return id; + } + + @Override + public void clear(Id aConfig) { + config.startConfigurationChange(); + try { + clearImpl(aConfig); + } finally { + config.endConfigurationChange(); + } + } + + private void clearImpl(Id aConfig) { + routerConfigs.remove(aConfig); + update(); + } + + private void update() { + ExtendedRouterConfig newconfig = new CompositeRouterConfig( + routerConfigs.map().values()); + config.setRouterConfig(newconfig); + } + +} diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfiguration.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfiguration.java index 51c8cc7..25ae331 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfiguration.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfiguration.java @@ -53,10 +53,18 @@ public interface XMLRouterConfiguration { /** * @return Configuration data. */ - ExtendedRouterConfig routerConfig(); + ExtendedRouterConfig getRouterConfig(); + + /** + * Sets the configuration and updates derived data. + * + * @param aConfig + * Configuration to set. + */ + void setRouterConfig(ExtendedRouterConfig aConfig); /** * @return Transformation paths (derived data). */ - TransformationPaths transformations(); + TransformationPaths getTransformations(); } diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfigurationImpl.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfigurationImpl.java index b0b0271..99db0fd 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfigurationImpl.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfigurationImpl.java @@ -15,8 +15,11 @@ */ package org.wamblee.xmlrouter.impl; +import java.util.ArrayList; import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.wamblee.xmlrouter.config.RouterConfig; + /** * Implements the XML Router configuration interface including the required * locking. @@ -33,10 +36,13 @@ public class XMLRouterConfigurationImpl implements XMLRouterConfiguration { private ExtendedRouterConfig config; private TransformationPaths transformations; - public XMLRouterConfigurationImpl(ExtendedRouterConfig aConfig, - TransformationPaths aTransformations) { + public XMLRouterConfigurationImpl(ExtendedRouterConfig aConfig) { config = aConfig; - transformations = aTransformations; + transformations = new TransformationPaths(); + } + + public XMLRouterConfigurationImpl() { + this(new CompositeRouterConfig(new ArrayList())); } @Override @@ -60,12 +66,19 @@ public class XMLRouterConfigurationImpl implements XMLRouterConfiguration { } @Override - public ExtendedRouterConfig routerConfig() { + public ExtendedRouterConfig getRouterConfig() { return config; } @Override - public TransformationPaths transformations() { + public void setRouterConfig(ExtendedRouterConfig aConfig) { + config = aConfig; + transformations.replaceTransformations(config.transformationConfig() + .map()); + } + + @Override + public TransformationPaths getTransformations() { return transformations; } } diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/ConfigImplTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/ConfigImplTest.java index 98296d4..1e8cfc3 100644 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/ConfigImplTest.java +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/ConfigImplTest.java @@ -61,7 +61,6 @@ public class ConfigImplTest { @Test public void testAdd() { MyType type1 = mock(MyType.class); - assertFalse(config.isDirty()); Id id1 = config.add(type1); @@ -69,10 +68,6 @@ public class ConfigImplTest { assertEquals(1, config.map().size()); assertTrue(config.map().get(id1) instanceof MyTypeWrapper); assertSame(type1, ((MyTypeWrapper) config.map().get(id1)).getType()); - assertTrue(config.isDirty()); - - config.resetDirty(); - assertFalse(config.isDirty()); // add another one. MyType type2 = mock(MyType.class); @@ -80,8 +75,6 @@ public class ConfigImplTest { assertNotNull(id2); assertEquals(2, config.map().size()); assertFalse(id1.equals(id2)); - assertTrue(config.isDirty()); - } @Test @@ -92,12 +85,8 @@ public class ConfigImplTest { assertNotNull(id1); assertEquals(1, config.map().size()); - config.resetDirty(); - assertFalse(config.isDirty()); - config.remove(id1); assertTrue(config.map().isEmpty()); - assertTrue(config.isDirty()); } @Test(expected = UnsupportedOperationException.class) diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/SingleRouterConfigTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/SingleRouterConfigTest.java index c6f9920..af34737 100644 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/SingleRouterConfigTest.java +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/SingleRouterConfigTest.java @@ -43,15 +43,10 @@ public class SingleRouterConfigTest { DocumentType type1 = mock(DocumentType.class); DocumentType type2 = mock(DocumentType.class); - assertFalse(config.isDirty()); Id id1 = config.documentTypeConfig().add(type1); - assertTrue(config.isDirty()); - config.resetDirty(); - assertFalse(config.isDirty()); Id id2 = config.documentTypeConfig().add(type2); assertFalse(id1.equals(id2)); - assertTrue(config.isDirty()); assertEquals(2, config.documentTypeConfig().map().size()); assertTrue(config.documentTypeConfig().map().get(id1) instanceof RobustDocumentType); @@ -63,17 +58,12 @@ public class SingleRouterConfigTest { Transformation transformation1 = mock(Transformation.class); Transformation transformation2 = mock(Transformation.class); - assertFalse(config.isDirty()); Id id1 = config.transformationConfig().add( transformation1); - assertTrue(config.isDirty()); - config.resetDirty(); - assertFalse(config.isDirty()); Id id2 = config.transformationConfig().add( transformation2); assertFalse(id1.equals(id2)); - assertTrue(config.isDirty()); assertEquals(2, config.transformationConfig().map().size()); assertTrue(config.transformationConfig().map().get(id1) instanceof RobustTransformation); @@ -84,15 +74,10 @@ public class SingleRouterConfigTest { Filter filter1 = mock(Filter.class); Filter filter2 = mock(Filter.class); - assertFalse(config.isDirty()); Id id1 = config.filterConfig().add(filter1); - assertTrue(config.isDirty()); - config.resetDirty(); - assertFalse(config.isDirty()); Id id2 = config.filterConfig().add(filter2); assertFalse(id1.equals(id2)); - assertTrue(config.isDirty()); assertEquals(2, config.filterConfig().map().size()); assertTrue(config.filterConfig().map().get(id1) instanceof RobustFilter); diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterFunctionTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterFunctionTest.java new file mode 100644 index 0000000..46e36c0 --- /dev/null +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterFunctionTest.java @@ -0,0 +1,102 @@ +/* + * 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.config.DocumentType; +import org.wamblee.xmlrouter.config.RouterConfig; +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(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); + RouterConfig routerConfig = configService.emptyConfig(); + routerConfig.documentTypeConfig().add(type); + return routerConfig; + } + + @Test + public void testOneTransformationOneDestination() { + RouterConfig routerConfig = registerDocumentType("any"); + Transformation transformation = mock(Transformation.class); + when(transformation.getName()).thenReturn("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), anyLong(), 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)); + } +} 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 7da3de5..baa63a1 100644 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java @@ -80,8 +80,7 @@ public class XMLRouterTest { @Before public void setUp() { routerConfig = new SingleRouterConfig(new AtomicLong(1L)); - config = new XMLRouterConfigurationImpl(routerConfig, - new TransformationPaths()); + config = new XMLRouterConfigurationImpl(routerConfig); EventListener logListener = new LoggingEventListener(Level.INFO); listener = spy(logListener); router = new XMLRouter(new SystemClock(), config, listener); @@ -276,6 +275,8 @@ public class XMLRouterTest { when(transformation.getToType()).thenReturn("bla"); when(transformation.transform(same(source1))).thenReturn(source2); routerConfig.transformationConfig().add(transformation); + config.getTransformations().replaceTransformations( + routerConfig.transformationConfig().map()); Destination destination = mock(Destination.class); when( @@ -338,6 +339,8 @@ public class XMLRouterTest { source1, null); routerConfig.transformationConfig().add(transformation); + config.getTransformations().replaceTransformations( + routerConfig.transformationConfig().map()); Destination destination = mock(Destination.class); when( @@ -356,6 +359,8 @@ public class XMLRouterTest { source1, source2); routerConfig.transformationConfig().add(transformation2); + config.getTransformations().replaceTransformations( + routerConfig.transformationConfig().map()); when( destination.chooseFromTargetTypes((Collection) anyObject())) .thenReturn(Arrays.asList("bla", "bla2")); @@ -400,6 +405,8 @@ public class XMLRouterTest { Transformation transformation = createTransformation("any", "other", source1, source2); routerConfig.transformationConfig().add(transformation); + config.getTransformations().replaceTransformations( + routerConfig.transformationConfig().map()); router.publish("source", source1); verify(listener, times(2)).delivered(any(EventInfo.class), @@ -421,6 +428,8 @@ public class XMLRouterTest { Transformation t2 = createTransformation("intermediate", "other", source2, source3); routerConfig.transformationConfig().add(t2); + config.getTransformations().replaceTransformations( + routerConfig.transformationConfig().map()); router.publish("source", source1); verify(listener).delivered(any(EventInfo.class), -- 2.31.1