Now using RouterConfig internally inside the XML Router.
[xmlrouter] / impl / src / test / java / org / wamblee / xmlrouter / impl / TransformationsTest.java
index 9da9c3524abff1a0ecf579336f517525b6b63581..775e5000b8dc7c01121881f18e5d6731d17e3122 100644 (file)
  * 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;
 
@@ -37,7 +39,7 @@ public class TransformationsTest {
             from = aFrom;
             to = aTo;
         }
-        
+
         @Override
         public String getName() {
             return "myname";
@@ -71,10 +73,22 @@ public class TransformationsTest {
         transformations = new Transformations();
     }
 
+    private Map<Id<Transformation>, Transformation> createTransformations(
+        long aStartId, Transformation... aTransformations) {
+        Map<Id<Transformation>, Transformation> res = new LinkedHashMap<Id<Transformation>, Transformation>();
+
+        long id = aStartId;
+        for (Transformation t : aTransformations) {
+            res.put(new Id<Transformation>(id++), t);
+        }
+        return res;
+    }
+
     @Test
     public void testOneTransformation() {
-        Id<Transformation> seqno = transformations
-            .addTransformation(new MyTransformation("A", "B"));
+        transformations.replaceTransformations(createTransformations(10L,
+            new MyTransformation("A", "B")));
+
         System.out.println(transformations.toString());
         TransformationPath path = transformations.getPath("A", "B");
         assertEquals(1, path.size());
@@ -92,22 +106,26 @@ public class TransformationsTest {
 
     @Test
     public void testMultipleTransformations() {
-        Id<Transformation> seqno1 = transformations
-            .addTransformation(new MyTransformation("A", "B"));
-        Id<Transformation> seqno2 = transformations
-            .addTransformation(new MyTransformation("B", "C"));
-        Id<Transformation> seqno3 = transformations
-            .addTransformation(new MyTransformation("C", "A"));
+        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());
-        assertFalse(seqno1.equals(seqno2));
-        assertFalse(seqno2.equals(seqno3));
-        assertFalse(seqno1.equals(seqno3));
 
-        transformations.removeTransformation(seqno1);
+        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<String> res = transformations.getPossibleTargetTypes("a");