View Javadoc

1   package org.apache.torque.generator.control;
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.io.FileReader;
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  import org.apache.commons.io.FileUtils;
31  import org.apache.torque.generator.BaseTest;
32  import org.apache.torque.generator.configuration.UnitDescriptor;
33  import org.apache.torque.generator.configuration.paths.CustomProjectPaths;
34  import org.apache.torque.generator.configuration.paths.DefaultTorqueGeneratorPaths;
35  import org.apache.torque.generator.configuration.paths.Maven2DirectoryProjectPaths;
36  import org.junit.Test;
37  
38  /**
39   * Tests nested mergepoints in a depth of 10 calls, and checks that the
40   * outcome is correct.
41   */
42  public class DeeplyNestedMergepointsTest extends BaseTest
43  {
44      @Test
45      public void testDeeplyNestedMergepointsGeneration() throws Exception
46      {
47          File targetDir = new File("target/test/deeplyNestedMergepoints");
48          FileUtils.deleteDirectory(targetDir);
49          Controller controller = new Controller();
50          List<UnitDescriptor> unitDescriptors = new ArrayList<UnitDescriptor>();
51          CustomProjectPaths projectPaths = new CustomProjectPaths(
52                  new Maven2DirectoryProjectPaths(
53                          new File("src/test/deeplyNestedMergepoints")));
54          projectPaths.setOutputDirectory(null, targetDir);
55          unitDescriptors.add(new UnitDescriptor(
56                  UnitDescriptor.Packaging.DIRECTORY,
57                  projectPaths,
58                  new DefaultTorqueGeneratorPaths()));
59          controller.run(unitDescriptors);
60  
61          assertTrue(targetDir.exists());
62          File targetFile = new File(targetDir, "output.txt");
63          assertTrue(targetFile.exists());
64  
65          FileReader fileReader = new FileReader(targetFile);
66          StringBuilder content = new StringBuilder();
67          int readChars;
68          char[] buffer = new char[50];
69          do
70          {
71              readChars = fileReader.read(buffer);
72              if (readChars != -1)
73              {
74                  content.append(buffer, 0, readChars);
75              }
76          }
77          while (readChars != -1);
78          assertEquals("content", content.toString());
79      }
80  }