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