View Javadoc

1   package org.apache.torque.generator.source.transform;
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 junitx.framework.FileAssert.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.BaseTest;
31  import org.apache.torque.generator.configuration.UnitDescriptor;
32  import org.apache.torque.generator.configuration.paths.CustomProjectPaths;
33  import org.apache.torque.generator.configuration.paths.DefaultTorqueGeneratorPaths;
34  import org.apache.torque.generator.configuration.paths.Maven2DirectoryProjectPaths;
35  import org.apache.torque.generator.control.Controller;
36  import org.junit.Test;
37  
38  /**
39   * Tests whether the loadAllSourceTransformer works correctly.
40   */
41  public class LoadAllSourceFilesTransformerTest extends BaseTest
42  {
43      private static final String TEST_RESOURCES_ROOT
44              = "src/test/loadAllSourceFilesTransformer";
45  
46      @Test
47      public void testLoadAllSourceFilesTransformerGeneration() throws Exception
48      {
49          File targetDir = new File("target/test/loadAllSourceFilesTransformer");
50          FileUtils.deleteDirectory(targetDir);
51          Controller controller = new Controller();
52          List<UnitDescriptor> unitDescriptors = new ArrayList<UnitDescriptor>();
53          CustomProjectPaths projectPaths = new CustomProjectPaths(
54                  new Maven2DirectoryProjectPaths(
55                          new File(TEST_RESOURCES_ROOT)));
56          projectPaths.setOutputDirectory(null, targetDir);
57          unitDescriptors.add(new UnitDescriptor(
58                  UnitDescriptor.Packaging.DIRECTORY,
59                  projectPaths,
60                  new DefaultTorqueGeneratorPaths()));
61          controller.run(unitDescriptors);
62  
63          assertTrue(targetDir.exists());
64          File targetFile = new File(targetDir, "output_for_source1.xml");
65          assertTrue(targetFile.exists());
66          File expectedFile = new File(TEST_RESOURCES_ROOT, "expected1.xml");
67          assertEquals(expectedFile, targetFile);
68          targetFile = new File(targetDir, "output_for_source2.xml");
69          assertTrue(targetFile.exists());
70          expectedFile = new File(TEST_RESOURCES_ROOT, "expected2.xml");
71          assertEquals(expectedFile, targetFile);
72      }
73  }