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