1   package org.apache.dvsl;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.StringReader;
23  import java.io.StringWriter;
24  import java.io.FileReader;
25  
26  import junit.framework.TestCase;
27  
28  import org.dom4j.Document;
29  import org.dom4j.io.SAXReader;
30  
31  /**
32   *  Simple testcase to ensure things are basically working.
33   *  This tests both a serialized document as well as a 'live'
34   *  dom4j one.
35   *
36   *  @author <a href="mailto:geirm@apache.org>Geir Magnusson Jr.</a>
37   */
38  public class GrinderTest
39      extends TestCase
40  {
41      /*
42       * use simple in-memory style and input strings
43       */
44  
45      private String dvslstyle = "src/test/site.dvsl";
46      private String input = "src/test/user-guide.xml";
47  
48      public GrinderTest( String name )
49      {
50          super(name);
51      }
52  
53  
54      public void testSelection()
55      {
56          try
57          {
58              doit();
59          }
60          catch( Exception e )
61          {
62              fail( e.getMessage() );
63          }
64      }
65  
66      public void doit()
67          throws Exception
68      {
69          /*
70           * make a dvsl
71           */
72  
73          DVSL dvsl = new DVSL();
74  
75          /*
76           *  register the stylesheet
77           */
78  
79          dvsl.setStylesheet( new FileReader(dvslstyle) );
80  
81          /*
82           *  render the document as a Reader
83           */
84  
85          StringWriter sw = new StringWriter();
86          SAXReader sr = new SAXReader();
87          Document document = sr.read( new FileReader(input ));
88          sw = new StringWriter();
89  
90          while(true)
91          {
92              dvsl.transform( document, sw );
93          }
94      }
95  }