1   /*
2    * Copyright 2005-2010 the original author or authors.
3    *
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
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
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.
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  }