2 * Copyright 2005-2011 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.xmlrouter.impl;
18 import static junit.framework.Assert.*;
20 import java.util.Collection;
22 import javax.xml.transform.dom.DOMSource;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.wamblee.xmlrouter.common.Id;
27 import org.wamblee.xmlrouter.config.Transformation;
29 public class TransformationsTest {
31 public static class MyTransformation implements Transformation {
36 public MyTransformation(String aFrom, String aTo) {
42 public String getName() {
47 public String getFromType() {
52 public String getToType() {
57 public DOMSource transform(DOMSource aDocument) {
62 public String toString() {
63 return from + "->" + to;
67 private Transformations transformations;
71 transformations = new Transformations();
75 public void testOneTransformation() {
76 Id<Transformation> seqno = transformations
77 .addTransformation(new MyTransformation("A", "B"));
78 System.out.println(transformations.toString());
79 TransformationPath path = transformations.getPath("A", "B");
80 assertEquals(1, path.size());
81 assertNull(transformations.getPath("B", "A"));
83 assertEquals(0, transformations.getPath("A", "A").size());
84 assertEquals(0, transformations.getPath("B", "B").size());
86 Collection<String> possibleTargets = transformations
87 .getPossibleTargetTypes("A");
88 assertEquals(2, possibleTargets.size());
89 assertTrue(possibleTargets.contains("A"));
90 assertTrue(possibleTargets.contains("B"));
94 public void testMultipleTransformations() {
95 Id<Transformation> seqno1 = transformations
96 .addTransformation(new MyTransformation("A", "B"));
97 Id<Transformation> seqno2 = transformations
98 .addTransformation(new MyTransformation("B", "C"));
99 Id<Transformation> seqno3 = transformations
100 .addTransformation(new MyTransformation("C", "A"));
101 System.out.println(transformations);
102 assertEquals(2, transformations.getPath("C", "B").size());
103 assertFalse(seqno1.equals(seqno2));
104 assertFalse(seqno2.equals(seqno3));
105 assertFalse(seqno1.equals(seqno3));
107 transformations.removeTransformation(seqno1);
108 assertNull(transformations.getPath("C", "B"));
112 public void testWithoutTransformations() {
113 Collection<String> res = transformations.getPossibleTargetTypes("a");
114 assertEquals(1, res.size());
116 TransformationPath path = transformations.getPath("A", "A");
118 assertEquals(0, path.size());
120 assertNull(transformations.getPath("B", "C"));