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 org.apache.maven.it.util.ResourceExtractor;
23  
24  import java.io.File;
25  
26  /**
27   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-1021">MNG-1021</a>.
28   *
29   * @author John Casey
30   *
31   */
32  public class MavenITmng1021EqualAttachmentBuildNumberTest
33      extends AbstractMavenIntegrationTestCase
34  {
35      public MavenITmng1021EqualAttachmentBuildNumberTest()
36      {
37          super( ALL_MAVEN_VERSIONS );
38      }
39  
40      /**
41       * Test that source attachments have the same build number and timestamp as the main
42       * artifact when deployed.
43       *
44       * @throws Exception in case of failure
45       */
46      public void testitMNG1021()
47          throws Exception
48      {
49          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-1021" );
50          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
51          verifier.setAutoclean( false );
52          verifier.deleteDirectory( "repo" );
53          verifier.deleteArtifacts( "org.apache.maven.its.mng1021" );
54          verifier.executeGoal( "initialize" );
55          verifier.verifyErrorFreeLog();
56          verifier.resetStreams();
57  
58          verifier.assertArtifactPresent( "org.apache.maven.its.mng1021", "test", "1-SNAPSHOT", "pom" );
59          verifier.assertArtifactPresent( "org.apache.maven.its.mng1021", "test", "1-SNAPSHOT", "jar" );
60  
61          String dir = "repo/org/apache/maven/its/mng1021/test/";
62          String snapshot = getSnapshotVersion( new File( testDir, dir + "1-SNAPSHOT" ) );
63          assertTrue( snapshot, snapshot.endsWith( "-1" ) );
64  
65          verifier.assertFilePresent( dir + "maven-metadata.xml" );
66          verifier.assertFilePresent( dir + "maven-metadata.xml.md5" );
67          verifier.assertFilePresent( dir + "maven-metadata.xml.sha1" );
68          verifier.assertFilePresent( dir + "1-SNAPSHOT/maven-metadata.xml" );
69          verifier.assertFilePresent( dir + "1-SNAPSHOT/maven-metadata.xml.md5" );
70          verifier.assertFilePresent( dir + "1-SNAPSHOT/maven-metadata.xml.sha1" );
71          verifier.assertFilePresent( dir + "1-SNAPSHOT/test-" + snapshot + ".pom" );
72          verifier.assertFilePresent( dir + "1-SNAPSHOT/test-" + snapshot + ".pom.md5" );
73          verifier.assertFilePresent( dir + "1-SNAPSHOT/test-" + snapshot + ".pom.sha1" );
74          verifier.assertFilePresent( dir + "1-SNAPSHOT/test-" + snapshot + ".jar" );
75          verifier.assertFilePresent( dir + "1-SNAPSHOT/test-" + snapshot + ".jar.md5" );
76          verifier.assertFilePresent( dir + "1-SNAPSHOT/test-" + snapshot + ".jar.sha1" );
77          verifier.assertFilePresent( dir + "1-SNAPSHOT/test-" + snapshot + "-it.jar" );
78          verifier.assertFilePresent( dir + "1-SNAPSHOT/test-" + snapshot + "-it.jar.md5" );
79          verifier.assertFilePresent( dir + "1-SNAPSHOT/test-" + snapshot + "-it.jar.sha1" );
80      }
81  
82      private String getSnapshotVersion( File artifactDir )
83      {
84          File[] files = artifactDir.listFiles();
85          for ( File file : files )
86          {
87              String name = file.getName();
88              if ( name.endsWith( ".pom" ) )
89              {
90                  return name.substring( "test-".length(), name.length() - ".pom".length() );
91              }
92          }
93          throw new IllegalStateException( "POM not found in " + artifactDir );
94      }
95  
96  }