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 org.codehaus.modello.core.ModelloCore;
26  import org.codehaus.plexus.PlexusTestCase;
27  import org.sonatype.plexus.build.incremental.BuildContext;
28  import org.codehaus.plexus.util.FileUtils;
29  
30  import java.io.File;
31  import java.util.Arrays;
32  
33  /**
34   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
35   */
36  public class ModelloConvertersMojoTest
37      extends PlexusTestCase
38  {
39      public void testModelloConvertersMojo()
40          throws Exception
41      {
42          ModelloCore modelloCore = (ModelloCore) lookup( ModelloCore.ROLE );
43  
44          BuildContext buildContext = (BuildContext) lookup( BuildContext.class );
45  
46          ModelloConvertersMojo mojo = new ModelloConvertersMojo();
47  
48          File outputDirectory = getTestFile( "target/converters-test" );
49  
50          FileUtils.deleteDirectory( outputDirectory );
51  
52          // ----------------------------------------------------------------------
53          // Call the mojo
54          // ----------------------------------------------------------------------
55  
56          mojo.setOutputDirectory( outputDirectory );
57  
58          String models[] = new String[1];
59          models[0] = getTestPath( "src/test/resources/java-model.mdo" );
60          mojo.setModels( models );
61  
62          mojo.setVersion( "1.0.0" );
63  
64          mojo.setPackageWithVersion( false );
65  
66          mojo.setPackagedVersions( Arrays.asList( new String[] { "0.9.0", "1.0.0" } ) );
67  
68          mojo.setModelloCore( modelloCore );
69          
70          mojo.setBuildContext( buildContext );
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 =
84              new File( 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 =
89              new File( outputDirectory, "org/codehaus/mojo/modello/javatest/v0_9_0/convert/VersionConverter.java" );
90  
91          assertTrue( "The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists() );
92  
93          javaFile =
94              new File( outputDirectory, "org/codehaus/mojo/modello/javatest/v0_9_0/convert/BasicVersionConverter.java" );
95  
96          assertTrue( "The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists() );
97  
98          javaFile = new File( outputDirectory, "org/codehaus/mojo/modello/javatest/convert/VersionConverter.java" );
99  
100         assertFalse( "The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.",
101                      javaFile.exists() );
102 
103         javaFile = new File( outputDirectory, "org/codehaus/mojo/modello/javatest/convert/BasicVersionConverter.java" );
104 
105         assertFalse( "The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.",
106                      javaFile.exists() );
107     }
108 }