1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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.Path;
24 import java.util.Arrays;
25
26 import com.github.tomakehurst.wiremock.common.ConsoleNotifier;
27 import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
28 import com.github.tomakehurst.wiremock.matching.UrlPathPattern;
29 import org.apache.commons.io.FileUtils;
30 import org.apache.maven.buildcache.its.junit.IntegrationTest;
31 import org.apache.maven.it.VerificationException;
32 import org.apache.maven.it.Verifier;
33 import org.junit.jupiter.api.AfterEach;
34 import org.junit.jupiter.api.BeforeEach;
35 import org.junit.jupiter.api.Test;
36 import org.junit.jupiter.api.extension.RegisterExtension;
37
38 import static com.github.tomakehurst.wiremock.client.WireMock.exactly;
39 import static com.github.tomakehurst.wiremock.client.WireMock.get;
40 import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
41 import static com.github.tomakehurst.wiremock.client.WireMock.notFound;
42 import static com.github.tomakehurst.wiremock.client.WireMock.ok;
43 import static com.github.tomakehurst.wiremock.client.WireMock.put;
44 import static com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor;
45 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
46 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
47
48
49
50
51 @IntegrationTest("src/test/projects/forked-executions-core-extension-remote")
52 public class ForkedExecutionsTest {
53
54 private static final String PROJECT_NAME = "org.apache.maven.caching.test.simple:forked-executions-core-extension";
55
56 @RegisterExtension
57 static WireMockExtension wm = WireMockExtension.newInstance()
58 .options(wireMockConfig().dynamicPort().notifier(new ConsoleNotifier(true)))
59 .build();
60
61 private Path tempDirectory;
62
63 @BeforeEach
64 void setUp() throws IOException {
65 tempDirectory = Files.createTempDirectory("build-cache-test-");
66 }
67
68 @AfterEach
69 void tearDown() throws IOException {
70 FileUtils.deleteDirectory(tempDirectory.toFile());
71 }
72
73 @Test
74 void testForkedExecution(Verifier verifier) throws VerificationException {
75
76 UrlPathPattern buildInfoPath = urlPathMatching(".*/buildinfo.xml");
77 wm.stubFor(get(buildInfoPath).willReturn(notFound()));
78 wm.stubFor(put(buildInfoPath).willReturn(ok()));
79
80 UrlPathPattern jarPath = urlPathMatching(".*/forked-executions-core-extension-remote.jar");
81 wm.stubFor(put(jarPath).willReturn(ok()));
82
83 UrlPathPattern cacheReportPath = urlPathMatching(".*/build-cache-report.xml");
84 wm.stubFor(put(cacheReportPath).willReturn(ok()));
85
86 verifier.setAutoclean(false);
87
88 verifier.setLogFileName("../log-1.txt");
89 verifier.setMavenDebug(true);
90 verifier.setCliOptions(Arrays.asList(
91 "-Dmaven.build.cache.location=" + tempDirectory.toAbsolutePath(),
92 "-Dmaven.build.cache.remote.url=http:////localhost:"
93 + wm.getRuntimeInfo().getHttpPort(),
94 "-Dmaven.build.cache.remote.save.enabled=true"));
95 verifier.executeGoal("verify");
96 verifier.verifyTextInLog("Started forked project");
97 verifier.verifyTextInLog("BUILD SUCCESS");
98
99 wm.verify(exactly(1), getRequestedFor(buildInfoPath));
100 wm.verify(exactly(1), putRequestedFor(buildInfoPath));
101 wm.verify(exactly(1), putRequestedFor(jarPath));
102 wm.verify(exactly(1), putRequestedFor(cacheReportPath));
103 }
104 }