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