View Javadoc
1   package org.codehaus.modello.maven;
2   
3   /*
4    * Copyright (c) 2004, Codehaus.org
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy of
7    * this software and associated documentation files (the "Software"), to deal in
8    * the Software without restriction, including without limitation the rights to
9    * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10   * of the Software, and to permit persons to whom the Software is furnished to do
11   * so, subject to the following conditions:
12   *
13   * The above copyright notice and this permission notice shall be included in all
14   * copies or substantial portions of the Software.
15   *
16   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22   * SOFTWARE.
23   */
24  
25  import java.io.File;
26  import java.util.Arrays;
27  
28  import org.apache.maven.project.MavenProject;
29  import org.codehaus.modello.core.ModelloCore;
30  import org.codehaus.plexus.ContainerConfiguration;
31  import org.codehaus.plexus.PlexusTestCase;
32  import org.codehaus.plexus.build.BuildContext;
33  import org.codehaus.plexus.util.FileUtils;
34  
35  /**
36   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
37   */
38  public class ModelloJavaMojoTest extends PlexusTestCase {
39      public void testModelloJavaMojo() throws Exception {
40          ModelloCore modelloCore = (ModelloCore) lookup(ModelloCore.ROLE);
41  
42          BuildContext buildContext = (BuildContext) lookup(BuildContext.class);
43  
44          ModelloJavaMojo mojo = new ModelloJavaMojo();
45  
46          File outputDirectory = getTestFile("target/java-test");
47  
48          FileUtils.deleteDirectory(outputDirectory);
49  
50          // ----------------------------------------------------------------------
51          // Call the mojo
52          // ----------------------------------------------------------------------
53  
54          mojo.setOutputDirectory(outputDirectory);
55  
56          String models[] = new String[1];
57          models[0] = getTestPath("src/test/resources/java-model.mdo");
58          mojo.setModels(models);
59  
60          mojo.setVersion("1.0.0");
61  
62          mojo.setPackageWithVersion(false);
63  
64          mojo.setPackagedVersions(Arrays.asList(new String[] {"0.9.0", "1.0.0"}));
65  
66          mojo.setModelloCore(modelloCore);
67  
68          mojo.setBuildContext(buildContext);
69          mojo.setProject(new MavenProject());
70  
71          mojo.execute();
72  
73          // ----------------------------------------------------------------------
74          // Assert
75          // ----------------------------------------------------------------------
76  
77          File javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/Model.java");
78  
79          assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
80  
81          javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/NewModel.java");
82  
83          assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
84  
85          javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/v1_0_0/Model.java");
86  
87          assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
88  
89          javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/v1_0_0/NewModel.java");
90  
91          assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
92  
93          javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/v0_9_0/Model.java");
94  
95          assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
96  
97          javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/v0_9_0/NewModel.java");
98  
99          assertFalse(
100                 "The generated java file shouldn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
101     }
102 
103     @Override
104     protected void customizeContainerConfiguration(ContainerConfiguration containerConfiguration) {
105         containerConfiguration.setClassPathScanning("cache");
106     }
107 }