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