View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * still missing:
32   * - deploy snapshots/releases into correct repos
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  }