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.ArrayList;
21 import java.util.Collection;
22 import java.util.List;
24 import javax.xml.transform.dom.DOMSource;
26 import org.junit.Test;
27 import org.wamblee.xmlrouter.common.Id;
28 import org.wamblee.xmlrouter.config.Transformation;
30 public class TransformationPathsTest {
32 public static class MyTransformation implements Transformation {
37 public MyTransformation(String aFrom, String aTo) {
43 public Id<Transformation> getId() {
44 return new Id<Transformation>("myname");
48 public String getFromType() {
53 public String getToType() {
58 public DOMSource transform(DOMSource aDocument) {
63 public String toString() {
64 return from + "->" + to;
68 private TransformationPaths transformations;
70 private List<Transformation> createTransformations(long aStartId,
71 Transformation... aTransformations) {
72 List<Transformation> res = new ArrayList<Transformation>();
74 for (Transformation t : aTransformations) {
81 public void testOneTransformation() {
82 transformations = new TransformationPaths(createTransformations(10L,
83 new MyTransformation("A", "B")));
85 System.out.println(transformations.toString());
86 TransformationPath path = transformations.getPath("A", "B");
87 assertEquals(1, path.size());
88 assertNull(transformations.getPath("B", "A"));
90 assertEquals(0, transformations.getPath("A", "A").size());
91 assertEquals(0, transformations.getPath("B", "B").size());
93 Collection<String> possibleTargets = transformations
94 .getPossibleTargetTypes("A");
95 assertEquals(2, possibleTargets.size());
96 assertTrue(possibleTargets.contains("A"));
97 assertTrue(possibleTargets.contains("B"));
101 public void testMultipleTransformations() {
102 transformations = new TransformationPaths(createTransformations(10L,
103 new MyTransformation("A", "B"), new MyTransformation("B", "C"),
104 new MyTransformation("C", "A")));
106 System.out.println(transformations);
107 assertEquals(2, transformations.getPath("C", "B").size());
109 transformations = new TransformationPaths(createTransformations(10L,
110 new MyTransformation("B", "C"), new MyTransformation("C", "A")));
112 assertNull(transformations.getPath("C", "B"));
116 public void testUnknownDestination() {
117 transformations = new TransformationPaths(createTransformations(10L,
118 new MyTransformation("A", "B")));
119 assertNull(transformations.getPath("A", "D"));
123 public void testWithoutTransformations() {
124 transformations = new TransformationPaths(
125 new ArrayList<Transformation>());
126 Collection<String> res = transformations.getPossibleTargetTypes("a");
127 assertEquals(1, res.size());
129 TransformationPath path = transformations.getPath("A", "A");
131 assertEquals(0, path.size());
133 assertNull(transformations.getPath("B", "C"));