Skip to content

Instantly share code, notes, and snippets.

@rmcdouga
Created December 8, 2022 22:03
Show Gist options
  • Save rmcdouga/11359c2b1b87195dc5688f165d0461f3 to your computer and use it in GitHub Desktop.
Save rmcdouga/11359c2b1b87195dc5688f165d0461f3 to your computer and use it in GitHub Desktop.
@WireMockTest
class SampleTest {
private static final boolean WIREMOCK_RECORDING = false; // true tells WIREMOCK to call AEM and record the result
private static final boolean SAVE_RESULTS = false; // true saves the resuts in the actualResults directory
@BeforeEach
void setUp(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {
underTest = new Sample(createAemConfig("localhost", wmRuntimeInfo.getHttpPort()));
if (WIREMOCK_RECORDING) {
String realServiceBaseUri = TestUtils.getBaseUri(4502).toString();
WireMock.startRecording(realServiceBaseUri);
}
}
@AfterEach
void tearDown() throws Exception {
if (WIREMOCK_RECORDING) {
SnapshotRecordResult recordings = WireMock.stopRecording();
List<StubMapping> mappings = recordings.getStubMappings();
System.out.println("Found " + mappings.size() + " recordings.");
for (StubMapping mapping : mappings) {
ResponseDefinition response = mapping.getResponse();
var jsonBody = response.getJsonBody();
System.out.println(jsonBody == null ? "JsonBody is null" : jsonBody.toPrettyString());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment