diff --git a/pom.xml b/pom.xml
index 2a0d1f7..97b3c2b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -146,6 +146,12 @@
quarkus-test-kubernetes-client
test
+
+ org.wiremock
+ wiremock
+ 3.10.0
+ test
+
diff --git a/src/test/java/org/jboss/pnc/konfluxbuilddriver/DriverTest.java b/src/test/java/org/jboss/pnc/konfluxbuilddriver/DriverTest.java
index 7b1fa23..3411df3 100644
--- a/src/test/java/org/jboss/pnc/konfluxbuilddriver/DriverTest.java
+++ b/src/test/java/org/jboss/pnc/konfluxbuilddriver/DriverTest.java
@@ -5,21 +5,30 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.List;
import java.util.logging.LogRecord;
+import javax.ws.rs.core.MediaType;
+
import jakarta.inject.Inject;
import org.eclipse.microprofile.rest.client.inject.RestClient;
+import org.jboss.pnc.api.constants.HttpHeaders;
+import org.jboss.pnc.api.dto.Request;
import org.jboss.pnc.konfluxbuilddriver.clients.IndyService;
import org.jboss.pnc.konfluxbuilddriver.clients.IndyTokenRequestDTO;
import org.jboss.pnc.konfluxbuilddriver.clients.IndyTokenResponseDTO;
import org.jboss.pnc.konfluxbuilddriver.dto.BuildRequest;
import org.jboss.pnc.konfluxbuilddriver.dto.BuildResponse;
import org.jboss.pnc.konfluxbuilddriver.dto.CancelRequest;
+import org.jboss.pnc.konfluxbuilddriver.dto.PipelineNotification;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import com.github.tomakehurst.wiremock.WireMockServer;
+
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import io.fabric8.tekton.client.TektonClient;
@@ -34,10 +43,13 @@
@WithKubernetesTestServer
@QuarkusTest
@QuarkusTestResource(value = LogCollectingTestResource.class, restrictToAnnotatedClass = true, initArgs = @ResourceArg(name = LogCollectingTestResource.LEVEL, value = "FINE"))
+@QuarkusTestResource(WireMockExtensions.class)
public class DriverTest {
private static final String namespace = "test-namespace";
+ private WireMockServer wireMockServer;
+
@KubernetesTestServer
KubernetesServer mockServer;
@@ -60,7 +72,7 @@ public void setup() {
}
@Test
- void verify() {
+ void cancel() {
BuildRequest request = BuildRequest.builder().namespace(namespace).podMemoryOverride("1Gi").build();
BuildResponse response = driver.create(request);
@@ -78,4 +90,19 @@ void verify() {
assertTrue(logRecords.stream().anyMatch(r -> LogCollectingTestResource.format(r)
.contains("Retrieved pipeline run-mw-pipeline--00000000-0000-0000-0000-000000000005")));
}
+
+ @Test
+ public void testCompleted() throws URISyntaxException {
+
+ Request request = Request.builder()
+ .method(Request.Method.PUT)
+ .header(new Request.Header(HttpHeaders.CONTENT_TYPE_STRING, MediaType.APPLICATION_JSON))
+ .attachment(null)
+ .uri(new URI(wireMockServer.baseUrl() + "/invoker"))
+ .build();
+
+ driver.completed(
+ PipelineNotification.builder().completionCallback(request).buildId("1234").status("Succeeded").build());
+ assertEquals(200, wireMockServer.getServeEvents().getServeEvents().getFirst().getResponse().getStatus());
+ }
}
diff --git a/src/test/java/org/jboss/pnc/konfluxbuilddriver/WireMockExtensions.java b/src/test/java/org/jboss/pnc/konfluxbuilddriver/WireMockExtensions.java
new file mode 100644
index 0000000..05b1e92
--- /dev/null
+++ b/src/test/java/org/jboss/pnc/konfluxbuilddriver/WireMockExtensions.java
@@ -0,0 +1,45 @@
+package org.jboss.pnc.konfluxbuilddriver;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
+import static com.github.tomakehurst.wiremock.client.WireMock.put;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+
+import java.util.Map;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.common.ConsoleNotifier;
+
+import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
+
+public class WireMockExtensions implements QuarkusTestResourceLifecycleManager {
+ private WireMockServer wireMockServer;
+
+ @Override
+ public Map start() {
+ wireMockServer = new WireMockServer(wireMockConfig().notifier(new ConsoleNotifier(true)));
+ wireMockServer.start();
+
+ wireMockServer.stubFor(
+ put(urlEqualTo("/invoker"))
+ .withRequestBody(
+ equalToJson("{\"status\":\"Succeeded\",\"buildId\":\"1234\"}"))
+ .willReturn(aResponse()
+ .withStatus(200)));
+
+ return Map.of("quarkus.rest-client.wiremockextensions.url", wireMockServer.baseUrl());
+ }
+
+ @Override
+ public void stop() {
+ if (wireMockServer != null) {
+ wireMockServer.stop();
+ }
+ }
+
+ @Override
+ public void inject(TestInjector testInjector) {
+ testInjector.injectIntoFields(wireMockServer, new TestInjector.MatchesType(WireMockServer.class));
+ }
+}