View Javadoc
1   package org.apache.maven.it;
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 java.io.File;
23  import java.io.IOException;
24  import java.util.Properties;
25  
26  import org.apache.maven.it.util.ResourceExtractor;
27  import org.codehaus.plexus.util.ReaderFactory;
28  import org.codehaus.plexus.util.xml.Xpp3Dom;
29  import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
30  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
31  
32  /**
33   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-3057">MNG-3057</a>.
34   *
35   * todo Fill in a better description of what this test verifies!
36   *
37   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
38   * @author jdcasey
39   *
40   */
41  public class MavenITmng3057VersionExprTransformationsTest
42      extends AbstractMavenIntegrationTestCase
43  {
44  
45      public MavenITmng3057VersionExprTransformationsTest()
46      {
47          super( "[2.1.0,2.1.1)" ); // only test in 2.1.0
48      }
49  
50      public void testitMNG3057 ()
51          throws Exception
52      {
53          requiresJavaVersion( "[1.5,)" );
54  
55          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3057" );
56  
57          File remoteRepo = new File( testDir, "target/deployment" );
58  
59          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
60          verifier.setAutoclean( false );
61          verifier.deleteDirectory( "target" );
62          verifier.deleteDirectory( "level2/target" );
63          verifier.deleteDirectory( "level2/level3/target" );
64          verifier.deleteArtifacts( "org.apache.maven.its.mng3057" );
65  
66          Properties properties = verifier.newDefaultFilterProperties();
67          properties.setProperty( "@deployTo@", remoteRepo.toURI().toURL().toExternalForm() );
68  
69          verifier.filterFile( "pom.xml", "pom-filtered.xml", "UTF-8", properties );
70  
71          verifier.addCliOption( "-V" );
72          verifier.addCliOption( "-DtestVersion=1" );
73          verifier.addCliOption( "-f pom-filtered.xml" );
74  
75          verifier.executeGoal( "generate-sources" );
76          verifier.verifyErrorFreeLog();
77          verifier.resetStreams();
78  
79          assertVersions( new File( verifier.getArtifactPath( "org.apache.maven.its.mng3057", "mng-3057", "1", "pom" ) ), "1", null );
80          assertVersions( new File( verifier.getArtifactPath( "org.apache.maven.its.mng3057", "level2", "1", "pom" ) ), "1", "1" );
81          assertVersions( new File( verifier.getArtifactPath( "org.apache.maven.its.mng3057", "level3", "1", "pom" ) ), "1", "1" );
82  
83          assertVersions( new File( remoteRepo, "org/apache/maven/its/mng3057/mng-3057/1/mng-3057-1.pom" ), "1", null );
84          assertVersions( new File( remoteRepo, "org/apache/maven/its/mng3057/level2/1/level2-1.pom" ), "1", "1" );
85          assertVersions( new File( remoteRepo, "org/apache/maven/its/mng3057/level2/1/level2-1.pom" ), "1", "1" );
86      }
87  
88      private void assertVersions( File file, String version, String parentVersion )
89          throws XmlPullParserException, IOException
90      {
91          Xpp3Dom dom = Xpp3DomBuilder.build( ReaderFactory.newXmlReader( file ) );
92          assertEquals( version, dom.getChild( "version" ).getValue() );
93          Xpp3Dom parent = dom.getChild( "parent" );
94          if ( parentVersion != null )
95          {
96              assertNotNull( parent );
97              assertEquals( parentVersion, parent.getChild( "version" ).getValue() );
98          }
99          else
100         {
101             assertNull( parent );
102         }
103     }
104 
105 }