1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.resolver.internal.ant;
20
21 import java.io.File;
22 import java.io.IOException;
23
24 import junit.framework.JUnit4TestAdapter;
25 import org.junit.Test;
26
27 import static org.hamcrest.MatcherAssert.*;
28 import static org.hamcrest.Matchers.*;
29
30 public class InstallTest extends AntBuildsTest {
31 public static junit.framework.Test suite() {
32 return new JUnit4TestAdapter(InstallTest.class);
33 }
34
35 @Test
36 public void testInstallGlobalPom() {
37 executeTarget("testInstallGlobalPom");
38 long tstamp = System.currentTimeMillis();
39
40 assertLogContaining("Installing");
41
42 assertUpdatedFile(tstamp, localRepoDir, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT.pom");
43 }
44
45 @Test
46 public void testInstallOverrideGlobalPom() {
47 executeTarget("testInstallOverrideGlobalPom");
48 long tstamp = System.currentTimeMillis();
49
50 assertLogContaining("Installing");
51
52 assertUpdatedFile(tstamp, localRepoDir, "test/other/0.1-SNAPSHOT/other-0.1-SNAPSHOT.pom");
53 }
54
55 @Test
56 public void testInstallOverrideGlobalPomByRef() {
57 long tstamp = System.currentTimeMillis();
58 executeTarget("testInstallOverrideGlobalPomByRef");
59
60 assertLogContaining("Installing");
61
62 assertUpdatedFile(tstamp, localRepoDir, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT.pom");
63 assertUpdatedFile(tstamp, localRepoDir, "test/other/0.1-SNAPSHOT/other-0.1-SNAPSHOT.pom");
64 }
65
66 @Test
67 public void testDefaultRepo() {
68 executeTarget("testDefaultRepo");
69 long tstamp = System.currentTimeMillis();
70
71 assertLogContaining("Installing");
72
73 assertUpdatedFile(tstamp, localRepoDir, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT.pom");
74 assertUpdatedFile(tstamp, localRepoDir, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT-ant.xml");
75 }
76
77 @Test
78 public void testCustomRepo() throws IOException {
79 File repoPath = new File(BUILD_DIR, "local-repo-custom");
80
81 executeTarget("testCustomRepo");
82 long tstamp = System.currentTimeMillis();
83
84 System.out.println(getLog());
85 assertLogContaining("Installing");
86
87 assertUpdatedFile(tstamp, repoPath, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT.pom");
88 assertUpdatedFile(tstamp, repoPath, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT-ant.xml");
89 }
90
91 private void assertUpdatedFile(long tstamp, File repoPath, String path) {
92 File file = new File(repoPath, path);
93 assertThat("File does not exist in default repo: " + file.getAbsolutePath(), file.exists());
94 assertThat(
95 "Files were not updated for 1s before/after timestamp",
96 file.lastModified(),
97 allOf(greaterThanOrEqualTo(((tstamp - 500) / 1000) * 1000), lessThanOrEqualTo(tstamp + 2000)));
98 }
99 }