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.io.IOException;
27  
28  public class InstallTest
29      extends AntBuildsTest
30  {
31  
32      public void testInstallGlobalPom()
33      {
34          executeTarget( "testInstallGlobalPom" );
35          long tstamp = System.currentTimeMillis();
36  
37          assertLogContaining( "Installing" );
38          
39          assertUpdatedFile( tstamp, localRepoDir, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT.pom" );
40      }
41  
42      public void testInstallOverrideGlobalPom()
43      {
44          executeTarget( "testInstallOverrideGlobalPom" );
45          long tstamp = System.currentTimeMillis();
46  
47          assertLogContaining( "Installing" );
48  
49          assertUpdatedFile( tstamp, localRepoDir, "test/other/0.1-SNAPSHOT/other-0.1-SNAPSHOT.pom" );
50      }
51  
52      public void testInstallOverrideGlobalPomByRef()
53      {
54          long tstamp = System.currentTimeMillis();
55          executeTarget( "testInstallOverrideGlobalPomByRef" );
56  
57          assertLogContaining( "Installing" );
58  
59          assertUpdatedFile( tstamp, localRepoDir, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT.pom" );
60          assertUpdatedFile( tstamp, localRepoDir, "test/other/0.1-SNAPSHOT/other-0.1-SNAPSHOT.pom" );
61      }
62  
63      public void testDefaultRepo()
64      {
65          executeTarget( "testDefaultRepo" );
66          long tstamp = System.currentTimeMillis();
67  
68          assertLogContaining( "Installing" );
69  
70          assertUpdatedFile( tstamp, localRepoDir, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT.pom" );
71          assertUpdatedFile( tstamp, localRepoDir, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT-ant.xml" );
72      }
73  
74      public void testCustomRepo()
75          throws IOException
76      {
77          File repoPath = new File( BUILD_DIR, "local-repo-custom" );
78  
79          executeTarget( "testCustomRepo" );
80          long tstamp = System.currentTimeMillis();
81  
82          System.out.println( getLog() );
83          assertLogContaining( "Installing" );
84  
85          assertUpdatedFile( tstamp, repoPath, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT.pom" );
86          assertUpdatedFile( tstamp, repoPath, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT-ant.xml" );
87      }
88  
89      private void assertUpdatedFile( long tstamp, File repoPath, String path )
90      {
91          File file = new File( repoPath, path );
92          assertThat( "File does not exist in default repo: " + file.getAbsolutePath(), file.exists() );
93          assertThat( "Files were not updated for 1s before/after timestamp",
94                      file.lastModified(),
95                      allOf( greaterThanOrEqualTo( ( ( tstamp - 500 ) / 1000 ) * 1000 ),
96                             lessThanOrEqualTo( tstamp + 2000 ) ) );
97      }
98  }