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 class ForkedExecutionsTest {
53
54 @RegisterExtension
55 static WireMockExtension wm = WireMockExtension.newInstance()
56 .options(wireMockConfig().dynamicPort().notifier(new ConsoleNotifier(true)))
57 .build();
58
59 private Path tempDirectory;
60
61 @BeforeEach
62 void setUp() throws IOException {
63 tempDirectory = Files.createTempDirectory("build-cache-test-");
64 }
65
66 @AfterEach
67 void tearDown() throws IOException {
68 FileUtils.deleteDirectory(tempDirectory.toFile());
69 }
70
71 @Test
72 void testForkedExecution(Verifier verifier) throws VerificationException {
73
74 UrlPathPattern buildInfoPath = urlPathMatching(".*/buildinfo.xml");
75 wm.stubFor(get(buildInfoPath).willReturn(notFound()));
76 wm.stubFor(put(buildInfoPath).willReturn(ok()));
77
78 UrlPathPattern jarPath = urlPathMatching(".*/forked-executions-core-extension-remote.jar");
79 wm.stubFor(put(jarPath).willReturn(ok()));
80
81 UrlPathPattern cacheReportPath = urlPathMatching(".*/build-cache-report.xml");
82 wm.stubFor(put(cacheReportPath).willReturn(ok()));
83
84 verifier.setAutoclean(false);
85
86 verifier.setLogFileName("../log-1.txt");
87 verifier.setMavenDebug(true);
88 verifier.setCliOptions(Arrays.asList(
89 "-Dmaven.build.cache.location=" + tempDirectory.toAbsolutePath(),
90 "-Dmaven.build.cache.remote.url=http:////localhost:"
91 + wm.getRuntimeInfo().getHttpPort(),
92 "-Dmaven.build.cache.remote.save.enabled=true"));
93 verifier.executeGoal("verify");
94 verifier.verifyTextInLog("Started forked project");
95 verifier.verifyTextInLog("BUILD SUCCESS");
96
97 wm.verify(exactly(1), getRequestedFor(buildInfoPath));
98 wm.verify(exactly(1), putRequestedFor(buildInfoPath));
99 wm.verify(exactly(1), putRequestedFor(jarPath));
100 wm.verify(exactly(1), putRequestedFor(cacheReportPath));
101 }
102 }