Skip to content

Commit

Permalink
Add more logs to the wiremock invocations for easier debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
vibe13 committed Jun 28, 2024
1 parent 8140490 commit ef0f81b
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
import org.junitpioneer.jupiter.SetSystemProperty;

import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.http.HttpHeaders;
import com.github.tomakehurst.wiremock.http.RequestListener;
import com.github.tomakehurst.wiremock.http.RequestMethod;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
Expand Down Expand Up @@ -67,20 +70,48 @@ public void beforeEach() {
public AnalyzeResourceWithMockedBrewTest() throws URISyntaxException {
}

public class LoggingRequestListener implements RequestListener {

@Override
public void requestReceived(
com.github.tomakehurst.wiremock.http.Request request,
com.github.tomakehurst.wiremock.http.Response response) {

RequestMethod method = request.getMethod();
String url = request.getUrl();
String body = request.getBodyAsString();
int port = request.getPort();
HttpHeaders headers = request.getHeaders();
String protocol = request.getProtocol();

LOGGER.info(
"Received request: method={}, url={}, protocol={}, port={}, headers={}, body={}",
method,
url,
protocol,
port,
headers,
body);
}
}

@Test
@SetSystemProperty(key = "org.spdx.useJARLicenseInfoOnly", value = "true")
public void analyzeTestOKSimple() throws InterruptedException {
// given
// callback
wiremock.addMockServiceRequestListener(new LoggingRequestListener());
wiremock.stubFor(post(urlEqualTo(callbackRelativePath)).willReturn(aResponse().withStatus(HTTP_OK)));

// Remote servers stubs
WireMockServer pncServer = new WireMockServer(
options().port(8083).usingFilesUnderClasspath("analyzeTestOKSimple/pnc"));
pncServer.addMockServiceRequestListener(new LoggingRequestListener());
pncServer.start();

WireMockServer brewHub = new WireMockServer(
options().port(8084).usingFilesUnderClasspath("analyzeTestOKSimple/brewHub"));
brewHub.addMockServiceRequestListener(new LoggingRequestListener());
brewHub.start();

// when
Expand Down

0 comments on commit ef0f81b

Please sign in to comment.