X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FTransformationPathsTest.java;fp=impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FTransformationPathsTest.java;h=a45853272272806d0441b8958c12796b1868919f;hb=b3f837bff31337a9a7cb6abeb22c5a981be39b51;hp=0000000000000000000000000000000000000000;hpb=19413a6699295b4bbebc1b3bdb9838fd4370e581;p=xmlrouter diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/TransformationPathsTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/TransformationPathsTest.java new file mode 100644 index 0000000..a458532 --- /dev/null +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/TransformationPathsTest.java @@ -0,0 +1,140 @@ +/* + * 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 junit.framework.Assert.*; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + +import javax.xml.transform.dom.DOMSource; + +import org.junit.Before; +import org.junit.Test; +import org.wamblee.xmlrouter.common.Id; +import org.wamblee.xmlrouter.config.Transformation; + +public class TransformationPathsTest { + + public static class MyTransformation implements Transformation { + + private String from; + private String to; + + public MyTransformation(String aFrom, String aTo) { + from = aFrom; + to = aTo; + } + + @Override + public String getName() { + return "myname"; + } + + @Override + public String getFromType() { + return from; + } + + @Override + public String getToType() { + return to; + } + + @Override + public DOMSource transform(DOMSource aDocument) { + return null; + } + + @Override + public String toString() { + return from + "->" + to; + } + } + + private TransformationPaths transformations; + + @Before + public void setUp() { + transformations = new TransformationPaths(); + } + + private Map, Transformation> createTransformations( + long aStartId, Transformation... aTransformations) { + Map, Transformation> res = new LinkedHashMap, Transformation>(); + + long id = aStartId; + for (Transformation t : aTransformations) { + res.put(new Id(id++), t); + } + return res; + } + + @Test + public void testOneTransformation() { + transformations.replaceTransformations(createTransformations(10L, + new MyTransformation("A", "B"))); + + System.out.println(transformations.toString()); + TransformationPath path = transformations.getPath("A", "B"); + assertEquals(1, path.size()); + assertNull(transformations.getPath("B", "A")); + + assertEquals(0, transformations.getPath("A", "A").size()); + assertEquals(0, transformations.getPath("B", "B").size()); + + Collection possibleTargets = transformations + .getPossibleTargetTypes("A"); + assertEquals(2, possibleTargets.size()); + assertTrue(possibleTargets.contains("A")); + assertTrue(possibleTargets.contains("B")); + } + + @Test + public void testMultipleTransformations() { + transformations.replaceTransformations(createTransformations(10L, + new MyTransformation("A", "B"), new MyTransformation("B", "C"), + new MyTransformation("C", "A"))); + + System.out.println(transformations); + assertEquals(2, transformations.getPath("C", "B").size()); + + transformations.replaceTransformations(createTransformations(10L, + new MyTransformation("B", "C"), new MyTransformation("C", "A"))); + + assertNull(transformations.getPath("C", "B")); + } + + @Test + public void testUnknownDestination() { + transformations.replaceTransformations(createTransformations(10L, + new MyTransformation("A", "B"))); + assertNull(transformations.getPath("A", "D")); + } + + @Test + public void testWithoutTransformations() { + Collection res = transformations.getPossibleTargetTypes("a"); + assertEquals(1, res.size()); + + TransformationPath path = transformations.getPath("A", "A"); + assertNotNull(path); + assertEquals(0, path.size()); + + assertNull(transformations.getPath("B", "C")); + } +}