-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/org/jboss/pnc/konfluxbuilddriver/WireMockExtensions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, String> 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)); | ||
} | ||
} |