View Javadoc
1   package org.apache.maven.resolver.internal.ant;
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 junit.framework.JUnit4TestAdapter;
23  import org.junit.Test;
24  
25  import static org.hamcrest.MatcherAssert.*;
26  import static org.hamcrest.Matchers.*;
27  
28  import java.io.File;
29  import java.util.Arrays;
30  
31  /*
32   * still missing:
33   * - deploy snapshots/releases into correct repos
34   */
35  public class DeployTest
36      extends AntBuildsTest
37  {
38      public static junit.framework.Test suite()
39      {
40          return new JUnit4TestAdapter( DeployTest.class );
41      }
42  
43      @Test
44      public void testDeployGlobalPom()
45      {
46          long min = System.currentTimeMillis();
47          executeTarget( "testDeployGlobalPom" );
48          long max = System.currentTimeMillis();
49  
50          assertLogContaining( "Uploading" );
51  
52          assertUpdatedFile( min, max, distRepoDir, "test/dummy/0.1-SNAPSHOT/maven-metadata.xml" );
53      }
54  
55      @Test
56      public void testDeployOverrideGlobalPom()
57      {
58          long min = System.currentTimeMillis();
59          executeTarget( "testDeployOverrideGlobalPom" );
60          long max = System.currentTimeMillis();
61  
62          assertLogContaining( "Uploading" );
63  
64          assertUpdatedFile( min, max, distRepoDir, "test/other/0.1-SNAPSHOT/maven-metadata.xml" );
65      }
66  
67      @Test
68      public void testDeployOverrideGlobalPomByRef()
69      {
70          long min = System.currentTimeMillis();
71          executeTarget( "testDeployOverrideGlobalPomByRef" );
72          long max = System.currentTimeMillis();
73  
74          assertLogContaining( "Uploading" );
75  
76          assertUpdatedFile( min, max, distRepoDir, "test/dummy/0.1-SNAPSHOT/maven-metadata.xml" );
77          assertUpdatedFile( min, max, distRepoDir, "test/other/0.1-SNAPSHOT/maven-metadata.xml" );
78      }
79  
80      @Test
81      public void testDeployAttachedArtifact()
82      {
83          executeTarget( "testDeployAttachedArtifact" );
84  
85          assertLogContaining( "Uploading" );
86  
87          File dir = new File(distRepoDir, "test/dummy/0.1-SNAPSHOT/" );
88          String[] files = dir.list();
89          assertThat( "attached artifact not found: " + Arrays.toString( files ), files,
90                      hasItemInArray( endsWith( "-ant.xml" ) ) );
91      }
92  
93      private void assertUpdatedFile( long min, long max, File repoPath, String path )
94      {
95          File file = new File( repoPath, path );
96          min = (min / 1000) * 1000;
97          max = ((max + 999) / 1000) * 1000;
98          assertThat( "File does not exist in default repo: " + file.getAbsolutePath(), file.exists() );
99          assertThat( "Files were not updated for 1s before/after timestamp", file.lastModified(),
100                     allOf( greaterThanOrEqualTo( min ), lessThanOrEqualTo( max ) ) );
101     }
102 }