1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.xml.transform;
18
19 import java.io.IOException;
20 import javax.xml.transform.Result;
21 import javax.xml.transform.Source;
22 import javax.xml.transform.TransformerException;
23
24 import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.xml.sax.SAXException;
28
29 import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
30
31 public class TransformerHelperTest {
32
33 private TransformerHelper helper;
34
35 @Before
36 public void setUp() throws Exception {
37 helper = new TransformerHelper();
38 }
39
40 @Test
41 public void defaultTransformerFactory() throws TransformerException, IOException, SAXException {
42 doTest();
43 }
44
45 @Test
46 public void customTransformerFactory() throws TransformerException, IOException, SAXException {
47 helper.setTransformerFactoryClass(TransformerFactoryImpl.class);
48 doTest();
49 }
50
51 private void doTest() throws TransformerException, SAXException, IOException {
52 String xml = "<root xmlns='http://springframework.org/spring-ws'><child>text</child></root>";
53 Source source = new StringSource(xml);
54 Result result = new StringResult();
55
56 helper.transform(source, result);
57
58 assertXMLEqual(xml, result.toString());
59 }
60 }