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.config.Transformation;
28 public class RobustTransformationTest {
29 private Transformation transformation;
30 private Transformation robust;
31 private DOMSource source;
32 private DOMSource resSource;
36 transformation = mock(Transformation.class);
37 robust = new RobustTransformation("transformation", transformation);
38 source = mock(DOMSource.class);
39 resSource = mock(DOMSource.class);
43 public void testNormalFlow() {
44 when(transformation.getFromType()).thenReturn("from");
45 when(transformation.getToType()).thenReturn("to");
47 when(transformation.transform(same(source))).thenReturn(resSource);
49 assertEquals("from", robust.getFromType());
50 assertEquals("to", robust.getToType());
52 assertSame(resSource, robust.transform(source));
56 public void testFromReturnsNull() {
57 when(transformation.getFromType()).thenReturn(null);
58 assertEquals(Constants.UNKNOWN_DOCUMENT_TYPE.toString(),
59 robust.getFromType());
63 public void testToReturnsNull() {
64 when(transformation.getToType()).thenReturn(null);
65 assertEquals(Constants.UNKNOWN_DOCUMENT_TYPE.toString(),
70 public void testFromThrowsException() {
71 doThrow(new RuntimeException("x")).when(transformation).getFromType();
72 assertEquals(Constants.UNKNOWN_DOCUMENT_TYPE.toString(),
73 robust.getFromType());
77 public void testToThrowsException() {
78 doThrow(new RuntimeException("x")).when(transformation).getFromType();
79 assertEquals(Constants.UNKNOWN_DOCUMENT_TYPE.toString(),
80 robust.getFromType());
84 public void testTransformReturnsNull() {
85 when(transformation.transform(any(DOMSource.class))).thenReturn(null);
86 assertEquals(null, robust.transform(source));
90 public void testTransformationThrowsException() {
91 doThrow(new RuntimeException("x")).when(transformation).transform(
92 any(DOMSource.class));
93 assertEquals(null, robust.transform(source));