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 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 }