1   package org.apache.texen;
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.File;
23  
24  import org.apache.texen.test.Log;
25  import org.apache.texen.test.TestUtil;
26  
27  import junit.framework.TestCase;
28  import junit.framework.TestSuite;
29  
30  
31  
32  /**
33   * This is a test case for Texen. Simply executes a simple
34   * generative task and compares the output.
35   *
36   * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
37   * @version $Id: TexenTestCase.java 525422 2007-04-04 05:54:17Z wglass $
38   */
39  public class TexenTestCase extends TestCase
40  {
41      public static final String TEST_DIR_KEY = "test.compare.dir";
42      public static final String RESULTS_DIR_KEY = "test.results.dir";
43      
44      private String resultsDir;
45      private String compareDir;
46  
47      /**
48       * Creates a new instance.
49       *
50       */
51      public TexenTestCase(String name)
52      {
53          super(name);
54      }
55  
56      public static junit.framework.Test suite()
57      {
58          return new TestSuite(TexenTestCase.class);
59      }
60  
61      /**
62       * Find the directories.
63       */
64      public void setUp()
65      {
66          resultsDir = System.getProperty(RESULTS_DIR_KEY, "bin/test") + "/texen";
67          compareDir = System.getProperty(TEST_DIR_KEY, "test") + "/texen/compare";
68      }
69  
70      /**
71       * Runs the test.
72       */
73      public void testTexenResults ()
74              throws Exception
75      {
76          TestUtil.assureResultsDirectoryExists(resultsDir);
77  
78          // compare with custom context
79          if (!TestUtil.compareFiles(
80                  new File(compareDir, "TurbineWeather.java").toString(),
81                  new File(resultsDir, "TurbineWeather.java").toString()) ||
82              !TestUtil.compareFiles(
83                      new File(compareDir, "TurbineWeatherService.java").toString(),
84                      new File(resultsDir, "TurbineWeatherService.java").toString()) ||
85              !TestUtil.compareFiles(
86                      new File(compareDir, "WeatherService.java").toString(),
87                      new File(resultsDir, "WeatherService.java").toString()) ||
88              !TestUtil.compareFiles(
89                      new File(compareDir, "book.txt").toString(),
90                      new File(resultsDir, "book.txt").toString()) ||
91              !TestUtil.compareFiles(
92                      new File(compareDir, "Text.txt").toString(),
93                      new File(resultsDir, "Text.txt").toString()) )
94          {
95              fail("Texen results are incorrect.");
96          }
97          else
98          {
99              Log.log ("Passed!");
100         }
101     }
102 }