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.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  }