--- /dev/null
+package org.wamblee.xmlrouter.impl;
+
+import static junit.framework.Assert.*;
+
+import java.util.Collection;
+
+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 TransformationsTest {
+
+ 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 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 Transformations transformations;
+
+ @Before
+ public void setUp() {
+ transformations = new Transformations();
+ }
+
+ @Test
+ public void testOneTransformation() {
+ Id<Transformation> seqno = transformations
+ .addTransformation(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<String> possibleTargets = transformations
+ .getPossibleTargetTypes("A");
+ assertEquals(2, possibleTargets.size());
+ assertTrue(possibleTargets.contains("A"));
+ assertTrue(possibleTargets.contains("B"));
+ }
+
+ @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"));
+ 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);
+ assertNull(transformations.getPath("C", "B"));
+ }
+
+ @Test
+ public void testWithoutTransformations() {
+ Collection<String> 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"));
+ }
+}