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.*;
19 import static org.mockito.Matchers.*;
20 import static org.mockito.Mockito.*;
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 RobustTransformationTest {
30 private Transformation transformation;
31 private Transformation robust;
32 private DOMSource source;
33 private DOMSource resSource;
37 transformation = mock(Transformation.class);
38 robust = new RobustTransformation(new Id<Transformation>(100),
40 source = mock(DOMSource.class);
41 resSource = mock(DOMSource.class);
45 public void testNormalFlow() {
46 when(transformation.getFromType()).thenReturn("from");
47 when(transformation.getToType()).thenReturn("to");
49 when(transformation.transform(same(source))).thenReturn(resSource);
51 assertEquals("from", robust.getFromType());
52 assertEquals("to", robust.getToType());
54 assertSame(resSource, robust.transform(source));
58 public void testFromReturnsNull() {
59 when(transformation.getFromType()).thenReturn(null);
60 assertEquals(Constants.UNKNOWN_DOCUMENT_TYPE.toString(),
61 robust.getFromType());
65 public void testToReturnsNull() {
66 when(transformation.getToType()).thenReturn(null);
67 assertEquals(Constants.UNKNOWN_DOCUMENT_TYPE.toString(),
72 public void testFromThrowsException() {
73 doThrow(new RuntimeException("x")).when(transformation).getFromType();
74 assertEquals(Constants.UNKNOWN_DOCUMENT_TYPE.toString(),
75 robust.getFromType());
79 public void testToThrowsException() {
80 doThrow(new RuntimeException("x")).when(transformation).getFromType();
81 assertEquals(Constants.UNKNOWN_DOCUMENT_TYPE.toString(),
82 robust.getFromType());
86 public void testTransformReturnsNull() {
87 when(transformation.transform(any(DOMSource.class))).thenReturn(null);
88 assertEquals(null, robust.transform(source));
92 public void testTransformationThrowsException() {
93 doThrow(new RuntimeException("x")).when(transformation).transform(
94 any(DOMSource.class));
95 assertEquals(null, robust.transform(source));