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.buildcache.its;
20  
21  import java.io.IOException;
22  import java.nio.file.Files;
23  import java.nio.file.Paths;
24  import java.util.List;
25  
26  import org.apache.maven.buildcache.its.junit.IntegrationTest;
27  import org.apache.maven.it.VerificationException;
28  import org.apache.maven.it.Verifier;
29  import org.junit.jupiter.api.Test;
30  
31  import static java.util.Arrays.asList;
32  
33  @IntegrationTest("src/test/projects/mbuildcache-99")
34  class Issue99Test {
35  
36      @Test
37      void renamedFileInvalidatesCache(Verifier verifier) throws VerificationException, IOException {
38          verifier.setAutoclean(false);
39  
40          verifier.setLogFileName("../log-0.txt");
41          verifier.executeGoals(asList("package"));
42          verifier.verifyErrorFreeLog();
43          verifier.verifyTextInLog("Local build was not found");
44          verifyTextNotInLog(verifier, "Found cached build");
45  
46          verifier.setLogFileName("../log-1.txt");
47          verifier.executeGoals(asList("package"));
48          verifier.verifyErrorFreeLog();
49          verifier.verifyTextInLog("Found cached build");
50          verifyTextNotInLog(verifier, "Local build was not found");
51  
52          Files.move(
53                  Paths.get(verifier.getBasedir(), "test-module/src/main/resources/test.properties"),
54                  Paths.get(verifier.getBasedir(), "test-module/src/main/resources/test2.properties"));
55  
56          verifier.setLogFileName("../log-2.txt");
57          verifier.executeGoals(asList("package"));
58          verifier.verifyErrorFreeLog();
59          verifier.verifyTextInLog("Local build was not found");
60          verifyTextNotInLog(verifier, "Found cached build");
61      }
62  
63      private static void verifyTextNotInLog(Verifier verifier, String text) throws VerificationException {
64          List<String> lines = verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false);
65          for (String line : lines) {
66              if (Verifier.stripAnsi(line).contains(text)) {
67                  throw new VerificationException("Text found in log: " + text);
68              }
69          }
70      }
71  }