use of org.mockserver.model.ExpectationId in project mockserver by mock-server.
the class MockServerEventLog method verify.
public void verify(VerificationSequence verificationSequence, Consumer<String> resultConsumer) {
if (verificationSequence != null) {
final String logCorrelationId = UUIDService.getUUID();
if (MockServerLogger.isEnabled(Level.INFO)) {
mockServerLogger.logEvent(new LogEntry().setType(VERIFICATION).setLogLevel(Level.INFO).setCorrelationId(logCorrelationId).setHttpRequests(verificationSequence.getHttpRequests().toArray(new RequestDefinition[0])).setMessageFormat(VERIFICATION_REQUEST_SEQUENCES_MESSAGE_FORMAT).setArguments(verificationSequence));
}
if (verificationSequence.getExpectationIds() != null && !verificationSequence.getExpectationIds().isEmpty()) {
retrieveAllRequests(verificationSequence.getExpectationIds().stream().map(ExpectationId::getId).collect(Collectors.toList()), allRequests -> {
List<RequestDefinition> requestDefinitions = allRequests.stream().map(RequestAndExpectationId::getRequestDefinition).collect(Collectors.toList());
try {
String failureMessage = "";
int requestLogCounter = 0;
for (ExpectationId expectationId : verificationSequence.getExpectationIds()) {
if (expectationId != null) {
boolean foundRequest = false;
for (; !foundRequest && requestLogCounter < allRequests.size(); requestLogCounter++) {
if (allRequests.get(requestLogCounter).matches(expectationId)) {
// move on to next request
foundRequest = true;
}
}
if (!foundRequest) {
failureMessage = verificationSequenceFailureMessage(verificationSequence, logCorrelationId, requestDefinitions);
break;
}
}
}
verificationSequenceSuccessMessage(verificationSequence, resultConsumer, logCorrelationId, failureMessage);
} catch (Throwable throwable) {
verificationSequenceExceptionHandler(verificationSequence, resultConsumer, logCorrelationId, throwable, "exception:{} while processing verification sequence:{}", "exception while processing verification sequence");
}
});
} else {
retrieveAllRequests(false, allRequests -> {
try {
String failureMessage = "";
int requestLogCounter = 0;
for (RequestDefinition verificationHttpRequest : verificationSequence.getHttpRequests()) {
if (verificationHttpRequest != null) {
verificationHttpRequest.withLogCorrelationId(logCorrelationId);
HttpRequestMatcher httpRequestMatcher = matcherBuilder.transformsToMatcher(verificationHttpRequest);
boolean foundRequest = false;
for (; !foundRequest && requestLogCounter < allRequests.size(); requestLogCounter++) {
if (httpRequestMatcher.matches(allRequests.get(requestLogCounter).cloneWithLogCorrelationId())) {
// move on to next request
foundRequest = true;
}
}
if (!foundRequest) {
failureMessage = verificationSequenceFailureMessage(verificationSequence, logCorrelationId, allRequests);
break;
}
}
}
verificationSequenceSuccessMessage(verificationSequence, resultConsumer, logCorrelationId, failureMessage);
} catch (Throwable throwable) {
verificationSequenceExceptionHandler(verificationSequence, resultConsumer, logCorrelationId, throwable, "exception:{} while processing verification sequence:{}", "exception while processing verification sequence");
}
});
}
} else {
resultConsumer.accept("");
}
}
use of org.mockserver.model.ExpectationId in project app-Tiger by gematik.
the class TigerProxy method removeRoute.
@Override
public void removeRoute(final String routeId) {
if (!mockServer.isRunning()) {
return;
}
mockServerClient.clear(new ExpectationId().withId(routeId));
final TigerRoute route = tigerRouteMap.remove(routeId);
log.info("Deleted route {}. Current # expectations {}", route, mockServerClient.retrieveActiveExpectations(request()).length);
}
use of org.mockserver.model.ExpectationId in project mockserver by mock-server.
the class VerificationSequenceSerializerIntegrationTest method shouldDeserializeCompleteObjectWithExpectationIds.
@Test
public void shouldDeserializeCompleteObjectWithExpectationIds() {
// given
String requestBytes = "{" + NEW_LINE + " \"expectationIds\" : [ {" + NEW_LINE + " \"id\" : \"one\"" + NEW_LINE + " }, {" + NEW_LINE + " \"id\" : \"two\"" + NEW_LINE + " } ]" + NEW_LINE + "}";
// when
VerificationSequence verificationSequence = new VerificationSequenceSerializer(new MockServerLogger()).deserialize(requestBytes);
// then
assertEquals(new VerificationSequenceDTO().setExpectationIds(Arrays.asList(new ExpectationId().withId("one"), new ExpectationId().withId("two"))).buildObject(), verificationSequence);
}
Aggregations