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