View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.maven.it;
21  
22  import java.io.File;
23  import java.io.IOException;
24  import java.util.ArrayList;
25  import java.util.List;
26  import java.util.Properties;
27  
28  import org.apache.maven.it.util.ResourceExtractor;
29  import org.codehaus.plexus.util.ReaderFactory;
30  import org.codehaus.plexus.util.xml.Xpp3Dom;
31  import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
32  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
33  
34  /**
35   * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3057">MNG-3057</a>.
36   *
37   * @todo Fill in a better description of what this test verifies!
38   * 
39   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
40   * @author jdcasey
41   * 
42   */
43  public class MavenITmng3057VersionExprTransformationsTest
44      extends AbstractMavenIntegrationTestCase
45  {
46  
47      public MavenITmng3057VersionExprTransformationsTest()
48      {
49          super( "[2.1.0,2.1.1)" ); // only test in 2.1.0
50      }
51  
52      public void testitMNG3057 ()
53          throws Exception
54      {
55          requiresJavaVersion( "[1.5,)" );
56  
57          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3057" );
58          
59          File remoteRepo = new File( testDir, "target/deployment" );
60  
61          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
62          verifier.setAutoclean( false );
63          verifier.deleteDirectory( "target" );
64          verifier.deleteDirectory( "level2/target" );
65          verifier.deleteDirectory( "level2/level3/target" );
66          verifier.deleteArtifacts( "org.apache.maven.its.mng3057" );
67          
68          Properties properties = verifier.newDefaultFilterProperties();
69          properties.setProperty( "@deployTo@", remoteRepo.toURI().toURL().toExternalForm() );
70  
71          verifier.filterFile( "pom.xml", "pom-filtered.xml", "UTF-8", properties );
72  
73          verifier.getCliOptions().add( "-V" );
74          verifier.getCliOptions().add( "-DtestVersion=1" );
75          verifier.getCliOptions().add( "-f pom-filtered.xml" );
76  
77          verifier.executeGoal( "generate-sources" );
78          verifier.verifyErrorFreeLog();
79          verifier.resetStreams();
80  
81          assertVersions( new File( verifier.getArtifactPath( "org.apache.maven.its.mng3057", "mng-3057", "1", "pom" ) ), "1", null );
82          assertVersions( new File( verifier.getArtifactPath( "org.apache.maven.its.mng3057", "level2", "1", "pom" ) ), "1", "1" );
83          assertVersions( new File( verifier.getArtifactPath( "org.apache.maven.its.mng3057", "level3", "1", "pom" ) ), "1", "1" );
84          
85          assertVersions( new File( remoteRepo, "org/apache/maven/its/mng3057/mng-3057/1/mng-3057-1.pom" ), "1", null );
86          assertVersions( new File( remoteRepo, "org/apache/maven/its/mng3057/level2/1/level2-1.pom" ), "1", "1" );
87          assertVersions( new File( remoteRepo, "org/apache/maven/its/mng3057/level2/1/level2-1.pom" ), "1", "1" );
88      }
89  
90      private void assertVersions( File file, String version, String parentVersion )
91          throws XmlPullParserException, IOException
92      {
93          Xpp3Dom dom = Xpp3DomBuilder.build( ReaderFactory.newXmlReader( file ) );        
94          assertEquals( version, dom.getChild( "version" ).getValue() );
95          Xpp3Dom parent = dom.getChild( "parent" );
96          if ( parentVersion != null )
97          {
98              assertNotNull( parent );
99              assertEquals( parentVersion, parent.getChild( "version" ).getValue() );
100         }
101         else
102         {
103             assertNull( parent );
104         }
105     }    
106 
107 }