1 package org.apache.maven.resolver.internal.ant;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }