use of org.mockserver.dashboard.model.DashboardLogEntryDTOGroup in project mockserver by mock-server.
the class DashboardLogEntryDTOGroupSerializerTest method shouldSerialiseGroupWithSingleEvent.
@Test
public void shouldSerialiseGroupWithSingleEvent() throws JsonProcessingException {
// given
DashboardLogEntryDTOGroup dashboardLogEntryDTOGroup = new DashboardLogEntryDTOGroup(descriptionProcessor);
LogEntry logEntry = new LogEntry().setLogLevel(Level.WARN).setEpochTime(epochTime).setType(LogEntry.LogMessageType.TEMPLATE_GENERATED).setMessageFormat("some random{}formatted string{}").setArguments("one", "two");
dashboardLogEntryDTOGroup.getLogEntryDTOS().add(new DashboardLogEntryDTO(logEntry).setDescription(getDescription(logEntry)));
// when
String json = objectWriter.writeValueAsString(dashboardLogEntryDTOGroup);
// then
assertThat(json, is("{" + NEW_LINE + " \"key\" : \"" + logEntry.id() + "_log\"," + NEW_LINE + " \"value\" : {" + NEW_LINE + " \"description\" : \"" + timeStamp + " TEMPLATE_GENERATED \"," + NEW_LINE + " \"style\" : {" + NEW_LINE + " \"paddingBottom\" : \"4px\"," + NEW_LINE + " \"whiteSpace\" : \"nowrap\"," + NEW_LINE + " \"overflow\" : \"auto\"," + NEW_LINE + " \"color\" : \"rgb(241, 186, 27)\"," + NEW_LINE + " \"paddingTop\" : \"4px\"" + NEW_LINE + " }," + NEW_LINE + " \"messageParts\" : [ {" + NEW_LINE + " \"key\" : \"" + logEntry.id() + "_0msg\"," + NEW_LINE + " \"value\" : \"some random\"" + NEW_LINE + " }, {" + NEW_LINE + " \"key\" : \"" + logEntry.id() + "_0arg\"," + NEW_LINE + " \"multiline\" : false," + NEW_LINE + " \"argument\" : true," + NEW_LINE + " \"value\" : \"\\\"one\\\"\"" + NEW_LINE + " }, {" + NEW_LINE + " \"key\" : \"" + logEntry.id() + "_1msg\"," + NEW_LINE + " \"value\" : \"formatted string\"" + NEW_LINE + " }, {" + NEW_LINE + " \"key\" : \"" + logEntry.id() + "_1arg\"," + NEW_LINE + " \"multiline\" : false," + NEW_LINE + " \"argument\" : true," + NEW_LINE + " \"value\" : \"\\\"two\\\"\"" + NEW_LINE + " } ]" + NEW_LINE + " }" + NEW_LINE + "}"));
}
use of org.mockserver.dashboard.model.DashboardLogEntryDTOGroup in project mockserver by mock-server.
the class DashboardLogEntryDTOGroupSerializerTest method shouldSerialiseGroupWithMultipleEvents.
@Test
public void shouldSerialiseGroupWithMultipleEvents() throws JsonProcessingException {
// given
DashboardLogEntryDTOGroup dashboardLogEntryDTOGroup = new DashboardLogEntryDTOGroup(descriptionProcessor);
LogEntry logEntryForwardRequest = new LogEntry().setLogLevel(Level.WARN).setEpochTime(epochTime).setType(LogEntry.LogMessageType.FORWARDED_REQUEST).setMessageFormat("some random{}formatted string{}").setArguments("one", "two");
dashboardLogEntryDTOGroup.getLogEntryDTOS().add(new DashboardLogEntryDTO(logEntryForwardRequest).setDescription(getDescription(logEntryForwardRequest)));
LogEntry logEntryExpectationNotMatched = new LogEntry().setLogLevel(Level.WARN).setEpochTime(epochTime).setType(LogEntry.LogMessageType.EXPECTATION_NOT_MATCHED).setMessageFormat("some random{}formatted string{}").setArguments("one", "two");
dashboardLogEntryDTOGroup.getLogEntryDTOS().add(new DashboardLogEntryDTO(logEntryExpectationNotMatched).setDescription(getDescription(logEntryExpectationNotMatched)));
// when
String json = objectWriter.writeValueAsString(dashboardLogEntryDTOGroup);
// then
assertThat(json, is("{\n" + " \"key\" : \"" + logEntryForwardRequest.id() + "_log_group\",\n" + " \"group\" : {\n" + " \"key\" : \"" + logEntryForwardRequest.id() + "_log\",\n" + " \"value\" : {\n" + " \"description\" : \"" + timeStamp + " FORWARDED_REQUEST \",\n" + " \"style\" : {\n" + " \"paddingBottom\" : \"4px\",\n" + " \"whiteSpace\" : \"nowrap\",\n" + " \"overflow\" : \"auto\",\n" + " \"color\" : \"rgb(152, 208, 255)\",\n" + " \"paddingTop\" : \"4px\"\n" + " }\n" + " }\n" + " },\n" + " \"value\" : [ {\n" + " \"key\" : \"" + logEntryForwardRequest.id() + "_log\",\n" + " \"value\" : {\n" + " \"description\" : \"" + timeStamp + " FORWARDED_REQUEST \",\n" + " \"style\" : {\n" + " \"paddingBottom\" : \"4px\",\n" + " \"whiteSpace\" : \"nowrap\",\n" + " \"overflow\" : \"auto\",\n" + " \"color\" : \"rgb(152, 208, 255)\",\n" + " \"paddingTop\" : \"4px\"\n" + " },\n" + " \"messageParts\" : [ {\n" + " \"key\" : \"" + logEntryForwardRequest.id() + "_0msg\",\n" + " \"value\" : \"some random\"\n" + " }, {\n" + " \"key\" : \"" + logEntryForwardRequest.id() + "_0arg\",\n" + " \"multiline\" : false,\n" + " \"argument\" : true,\n" + " \"value\" : \"\\\"one\\\"\"\n" + " }, {\n" + " \"key\" : \"" + logEntryForwardRequest.id() + "_1msg\",\n" + " \"value\" : \"formatted string\"\n" + " }, {\n" + " \"key\" : \"" + logEntryForwardRequest.id() + "_1arg\",\n" + " \"multiline\" : false,\n" + " \"argument\" : true,\n" + " \"value\" : \"\\\"two\\\"\"\n" + " } ]\n" + " }\n" + " }, {\n" + " \"key\" : \"" + logEntryExpectationNotMatched.id() + "_log\",\n" + " \"value\" : {\n" + " \"description\" : \"" + timeStamp + " EXPECTATION_NOT_MATCHED \",\n" + " \"style\" : {\n" + " \"paddingBottom\" : \"4px\",\n" + " \"whiteSpace\" : \"nowrap\",\n" + " \"overflow\" : \"auto\",\n" + " \"color\" : \"rgb(204,165,163)\",\n" + " \"paddingTop\" : \"4px\"\n" + " },\n" + " \"messageParts\" : [ {\n" + " \"key\" : \"" + logEntryExpectationNotMatched.id() + "_0msg\",\n" + " \"value\" : \"some random\"\n" + " }, {\n" + " \"key\" : \"" + logEntryExpectationNotMatched.id() + "_0arg\",\n" + " \"multiline\" : false,\n" + " \"argument\" : true,\n" + " \"value\" : \"\\\"one\\\"\"\n" + " }, {\n" + " \"key\" : \"" + logEntryExpectationNotMatched.id() + "_1msg\",\n" + " \"value\" : \"formatted string\"\n" + " }, {\n" + " \"key\" : \"" + logEntryExpectationNotMatched.id() + "_1arg\",\n" + " \"multiline\" : false,\n" + " \"argument\" : true,\n" + " \"value\" : \"\\\"two\\\"\"\n" + " } ]\n" + " }\n" + " } ]\n" + "}"));
}
use of org.mockserver.dashboard.model.DashboardLogEntryDTOGroup in project mockserver by mock-server.
the class DashboardWebSocketHandler method sendUpdate.
private void sendUpdate(ChannelOutboundInvoker ctx, RequestDefinition httpRequest, int retryCount) {
DescriptionProcessor activeExpectationsDescriptionProcessor = new DescriptionProcessor();
DescriptionProcessor logMessagesDescriptionProcessor = new DescriptionProcessor();
DescriptionProcessor recordedRequestsDescriptionProcessor = new DescriptionProcessor();
DescriptionProcessor proxiedRequestsDescriptionProcessor = new DescriptionProcessor();
mockServerEventLog.retrieveLogEntriesInReverseForUI(httpRequest, logEntry -> true, DashboardLogEntryDTO::new, reverseLogEventsStream -> {
List<ImmutableMap<String, Object>> activeExpectations = requestMatchers.retrieveRequestMatchers(httpRequest).stream().limit(UI_UPDATE_ITEM_LIMIT).map(requestMatcher -> {
JsonNode expectationJsonNode = objectMapper.valueToTree(new ExpectationDTO(requestMatcher.getExpectation()));
if (requestMatcher.getExpectation().getHttpRequest() instanceof OpenAPIDefinition) {
JsonNode httpRequestJsonNode = expectationJsonNode.get("httpRequest");
if (httpRequestJsonNode instanceof ObjectNode) {
((ObjectNode) httpRequestJsonNode).set("requestMatchers", objectMapper.valueToTree(requestMatcher.getHttpRequests()));
}
}
Description description = activeExpectationsDescriptionProcessor.description(requestMatcher.getExpectation().getHttpRequest(), requestMatcher.getExpectation().getId());
return ImmutableMap.of("key", requestMatcher.getExpectation().getId(), "description", description != null ? description : requestMatcher.getExpectation().getId(), "value", expectationJsonNode);
}).collect(Collectors.toList());
List<Map<String, Object>> proxiedRequests = new LinkedList<>();
List<Map<String, Object>> recordedRequests = new LinkedList<>();
List<Object> logMessages = new LinkedList<>();
Map<String, DashboardLogEntryDTOGroup> logEntryGroups = new HashMap<>();
reverseLogEventsStream.forEach(logEntryDTO -> {
if (logEntryDTO != null) {
if (logMessages.size() < UI_UPDATE_ITEM_LIMIT) {
DashboardLogEntryDTO dashboardLogEntryDTO = logEntryDTO.setDescription(logMessagesDescriptionProcessor.description(logEntryDTO));
if (isNotBlank(logEntryDTO.getCorrelationId()) && logEntryDTO.getType() != TRACE) {
DashboardLogEntryDTOGroup logEntryGroup = logEntryGroups.get(logEntryDTO.getCorrelationId());
if (logEntryGroup == null) {
logEntryGroup = new DashboardLogEntryDTOGroup(logMessagesDescriptionProcessor);
logEntryGroups.put(logEntryDTO.getCorrelationId(), logEntryGroup);
logMessages.add(logEntryGroup);
}
logEntryGroup.getLogEntryDTOS().add(dashboardLogEntryDTO);
} else {
logMessages.add(dashboardLogEntryDTO);
}
}
if (recordedRequestsPredicate.test(logEntryDTO) && recordedRequests.size() < UI_UPDATE_ITEM_LIMIT) {
for (RequestDefinition request : logEntryDTO.getHttpRequests()) {
if (request != null) {
Map<String, Object> entry = new HashMap<>();
entry.put("key", logEntryDTO.getId() + "_request");
Description description = recordedRequestsDescriptionProcessor.description(request);
if (description != null) {
entry.put("description", description);
}
entry.put("value", request);
recordedRequests.add(entry);
}
}
}
if (proxiedRequestsPredicate.test(logEntryDTO) && proxiedRequests.size() < UI_UPDATE_ITEM_LIMIT) {
Map<String, Object> value = new HashMap<>();
if (logEntryDTO.getHttpRequest() != null) {
value.put("httpRequest", logEntryDTO.getHttpRequest());
}
if (logEntryDTO.getHttpResponse() != null) {
value.put("httpResponse", logEntryDTO.getHttpResponse());
}
Map<String, Object> entry = new HashMap<>();
entry.put("key", logEntryDTO.getId() + "_proxied");
Description description = proxiedRequestsDescriptionProcessor.description(logEntryDTO.getHttpRequest());
if (description != null) {
entry.put("description", description);
}
entry.put("value", value);
if (!value.isEmpty()) {
proxiedRequests.add(entry);
}
}
}
});
sendMessage(ctx, httpRequest, ImmutableMap.of("logMessages", logMessages, "activeExpectations", activeExpectations, "recordedRequests", recordedRequests, // reverse
"proxiedRequests", // reverse
proxiedRequests), retryCount);
});
}
Aggregations