View Javadoc
1   /*
2    * Copyright 2009 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  package org.openehealth.ipf.commons.xml;
17  
18  import static org.junit.Assert.assertTrue;
19  
20  import java.io.IOException;
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import javax.xml.transform.Source;
25  import javax.xml.transform.stream.StreamSource;
26  
27  import org.junit.Before;
28  import org.junit.Ignore;
29  import org.junit.Test;
30  
31  /**
32   * Tests passing in global parameters (e.g. services) into a stylesheet. See
33   * parameter.xslt.
34   *
35   * Note that with Saxon-HE, this feature is not available anymore
36   * 
37   * @author Christian Ohr
38   * 
39   */
40  @Ignore
41  public class XslTransmogrifierWithGlobalParameterTest {
42  
43      private XsltTransmogrifier<String> transformer;
44      Map<String, Object> parameters;
45  
46      @Before
47      public void setUp() throws Exception {
48          parameters = new HashMap<>();
49          parameters.put("service", new XsltTestService());
50          transformer = new XsltTransmogrifier<>(String.class);
51      }
52  
53      /**
54       * Demonstrates how to include a Groovy class to be used in an XSLT script
55       * 
56       * @throws IOException
57       */
58      @Test
59      public void testConvertString() throws IOException {
60          Source content = new StreamSource(getClass().getResourceAsStream("/xslt/parameterExample.xml"));
61          String s = transformer.zap(content, "/xslt/parameter.xslt", parameters);
62          assertTrue(s.contains("ein negeR mi tgaz ellezaG tim regeN niE"));
63      }
64  
65  }