View Javadoc

1   package org.apache.torque.generator.configuration.outlet;
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 static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertTrue;
24  
25  import java.io.File;
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  import org.apache.commons.io.FileUtils;
30  import org.apache.torque.generator.configuration.UnitDescriptor;
31  import org.apache.torque.generator.configuration.paths.CustomProjectPaths;
32  import org.apache.torque.generator.configuration.paths.DefaultTorqueGeneratorPaths;
33  import org.apache.torque.generator.configuration.paths.Maven2DirectoryProjectPaths;
34  import org.apache.torque.generator.control.Controller;
35  import org.junit.Before;
36  import org.junit.Test;
37  
38  /**
39   * Tests that another template language can easily integrated.
40   *
41   * @version $Id: OtherTemplateLanguageTest.java 1337543 2012-05-12 13:48:45Z tfischer $
42   */
43  public class OtherTemplateLanguageTest
44  {
45      private static final File TARGET_DIR
46              = new File("target/test/otherTemplateLanguages");
47  
48      private static final File OUTPUT_FILE
49              = new File(TARGET_DIR, "output.txt");
50  
51      @Before
52      public void setUp() throws Exception
53      {
54          FileUtils.deleteDirectory(TARGET_DIR);
55      }
56  
57      /**
58       * Tests that Groovy outlets can be used.
59       *
60       * @throws Exception if an error occurs.
61       */
62      @Test
63      public void testOtherTemplateLanguages() throws Exception
64      {
65          Controller controller = new Controller();
66          List<UnitDescriptor> unitDescriptors = new ArrayList<UnitDescriptor>();
67          CustomProjectPaths projectPaths = new CustomProjectPaths(
68                  new Maven2DirectoryProjectPaths(
69                          new File("src/test/otherTemplateLanguages")));
70          projectPaths.setOutputDirectory(null, TARGET_DIR);
71          unitDescriptors.add(new UnitDescriptor(
72                  UnitDescriptor.Packaging.DIRECTORY,
73                  projectPaths,
74                  new DefaultTorqueGeneratorPaths()));
75          controller.run(unitDescriptors);
76          // TODO: check outcome against reference file
77          assertTrue(OUTPUT_FILE.exists());
78          assertEquals(
79                  "groovy test output",
80                  FileUtils.readFileToString(OUTPUT_FILE));
81      }
82  }