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.util.Arrays;
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
31
32
33
34 public class DeployTest extends AntBuildsTest {
35 public static junit.framework.Test suite() {
36 return new JUnit4TestAdapter(DeployTest.class);
37 }
38
39 @Test
40 public void testDeployGlobalPom() {
41 long min = System.currentTimeMillis();
42 executeTarget("testDeployGlobalPom");
43 long max = System.currentTimeMillis();
44
45 assertLogContaining("Uploading");
46
47 assertUpdatedFile(min, max, distRepoDir, "test/dummy/0.1-SNAPSHOT/maven-metadata.xml");
48 }
49
50 @Test
51 public void testDeployOverrideGlobalPom() {
52 long min = System.currentTimeMillis();
53 executeTarget("testDeployOverrideGlobalPom");
54 long max = System.currentTimeMillis();
55
56 assertLogContaining("Uploading");
57
58 assertUpdatedFile(min, max, distRepoDir, "test/other/0.1-SNAPSHOT/maven-metadata.xml");
59 }
60
61 @Test
62 public void testDeployOverrideGlobalPomByRef() {
63 long min = System.currentTimeMillis();
64 executeTarget("testDeployOverrideGlobalPomByRef");
65 long max = System.currentTimeMillis();
66
67 assertLogContaining("Uploading");
68
69 assertUpdatedFile(min, max, distRepoDir, "test/dummy/0.1-SNAPSHOT/maven-metadata.xml");
70 assertUpdatedFile(min, max, distRepoDir, "test/other/0.1-SNAPSHOT/maven-metadata.xml");
71 }
72
73 @Test
74 public void testDeployAttachedArtifact() {
75 executeTarget("testDeployAttachedArtifact");
76
77 assertLogContaining("Uploading");
78
79 File dir = new File(distRepoDir, "test/dummy/0.1-SNAPSHOT/");
80 String[] files = dir.list();
81 assertThat(
82 "attached artifact not found: " + Arrays.toString(files), files, hasItemInArray(endsWith("-ant.xml")));
83 }
84
85 private void assertUpdatedFile(long min, long max, File repoPath, String path) {
86 File file = new File(repoPath, path);
87 min = (min / 1000) * 1000;
88 max = ((max + 999) / 1000) * 1000;
89 assertThat("File does not exist in default repo: " + file.getAbsolutePath(), file.exists());
90 assertThat(
91 "Files were not updated for 1s before/after timestamp",
92 file.lastModified(),
93 allOf(greaterThanOrEqualTo(min), lessThanOrEqualTo(max)));
94 }
95 }