1 package org.apache.anakia;
2
3
4 /*
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 */
22
23 import java.io.File;
24
25 import junit.framework.Test;
26 import junit.framework.TestCase;
27 import junit.framework.TestSuite;
28
29 import org.apache.anakia.test.Log;
30 import org.apache.anakia.test.TestUtil;
31
32
33 /**
34 * This is a test case for Anakia. Right now, it simply will compare
35 * two index.html files together. These are produced as a result of
36 * first running Anakia and then running this test.
37 *
38 * @version $Id: AnakiaTestCase.java 525405 2007-04-04 05:16:37Z wglass $
39 */
40 public class AnakiaTestCase 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 AnakiaTestCase(String name)
53 {
54 super(name);
55 }
56
57 public static Test suite()
58 {
59 return new TestSuite(AnakiaTestCase.class);
60 }
61
62 /**
63 * Find the directories.
64 */
65 public void setUp()
66 {
67 resultsDir = System.getProperty(RESULTS_DIR_KEY, "bin/test") + "/anakia";
68 compareDir = System.getProperty(TEST_DIR_KEY, "test") + "/anakia/compare";
69 }
70
71 /**
72 * Runs the test. This is empty on purpose because the
73 * code to do the Anakia output is in the .xml file that runs
74 * this test.
75 */
76 public void testAnakiaResults ()
77 throws Exception
78 {
79 TestUtil.assureResultsDirectoryExists(resultsDir);
80
81 // compare standard run
82 if (!TestUtil.compareFiles(
83 new File(compareDir, "index.html").toString(),
84 new File(resultsDir, "index.html").toString()))
85 {
86 fail("Anakia results are incorrect");
87 }
88 else
89 {
90 Log.log ("Passed (standard)!");
91 }
92 }
93
94 /**
95 * Runs the test. This is empty on purpose because the
96 * code to do the Anakia output is in the .xml file that runs
97 * this test.
98 */
99 public void testAnakiaCustomContextResults ()
100 throws Exception
101 {
102 TestUtil.assureResultsDirectoryExists(resultsDir);
103
104 // compare with custom context
105 if (!TestUtil.compareFiles(
106 new File(compareDir, "index.context.html").toString(),
107 new File(resultsDir, "index.context.html").toString()))
108 {
109 fail("Anakia results are incorrect");
110 }
111 else
112 {
113 Log.log ("Passed (custom context)!");
114 }
115 }
116
117
118 }