View Javadoc
1   package org.codehaus.modello.maven;
2   
3   /*
4    * Copyright (c) 2006, 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:brett@apache.org">Brett Porter</a>
37   */
38  public class ModelloConvertersMojoTest extends PlexusTestCase {
39      public void testModelloConvertersMojo() throws Exception {
40          ModelloCore modelloCore = (ModelloCore) lookup(ModelloCore.ROLE);
41  
42          BuildContext buildContext = (BuildContext) lookup(BuildContext.class);
43  
44          ModelloConvertersMojo mojo = new ModelloConvertersMojo();
45  
46          File outputDirectory = getTestFile("target/converters-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  
70          mojo.setProject(new MavenProject());
71  
72          mojo.execute();
73  
74          // ----------------------------------------------------------------------
75          // Assert
76          // ----------------------------------------------------------------------
77  
78          File javaFile =
79                  new File(outputDirectory, "org/codehaus/mojo/modello/javatest/v1_0_0/convert/VersionConverter.java");
80  
81          assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
82  
83          javaFile = new File(
84                  outputDirectory, "org/codehaus/mojo/modello/javatest/v1_0_0/convert/BasicVersionConverter.java");
85  
86          assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
87  
88          javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/v0_9_0/convert/VersionConverter.java");
89  
90          assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
91  
92          javaFile = new File(
93                  outputDirectory, "org/codehaus/mojo/modello/javatest/v0_9_0/convert/BasicVersionConverter.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/convert/VersionConverter.java");
98  
99          assertFalse("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
100 
101         javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/convert/BasicVersionConverter.java");
102 
103         assertFalse("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
104     }
105 
106     @Override
107     protected void customizeContainerConfiguration(ContainerConfiguration containerConfiguration) {
108         containerConfiguration.setClassPathScanning("cache");
109     }
110 }