PredixEventMapper { public AuditEventV2 map(final AuditEvent auditEvent) { Map<String, String> auditPayload = new HashMap<>(); auditPayload.put("httpMethod", auditEvent.getMethod()); auditPayload.put("requestBody", auditEvent.getRequestBody()); auditPayload.put("responseBody", auditEvent.getResponseBody()); String payload = ""; try { payload = OBJECT_MAPPER.writeValueAsString(auditPayload); } catch (JsonProcessingException e) { LOGGER.warn("Unable to convert audit payload to json: {}" + auditPayload, e); } String correlationId = auditEvent.getCorrelationId(); if (correlationId.length() == 16) { correlationId = "0000000000000000" + correlationId; } correlationId = REGEX.matcher(correlationId).replaceFirst("$1-$2-$3-$4-$5"); AuditEventV2Builder auditEventBuilder = AuditEventV2.builder().timestamp(auditEvent.getTime().toEpochMilli()) .correlationId(correlationId).tenantUuid(auditEvent.getZoneId()) .publisherType(PublisherType.APP_SERVICE).categoryType(CategoryType.API_CALLS).payload(payload); if (isSuccessful(auditEvent)) { auditEventBuilder = auditEventBuilder.eventType(EventType.SUCCESS_API_REQUEST) .classifier(Classifier.SUCCESS); } else { auditEventBuilder = auditEventBuilder.eventType(EventType.FAILURE_API_REQUEST) .classifier(Classifier.FAILURE); } return auditEventBuilder.build(); }  AuditEventV2 map(final AuditEvent auditEvent);  }
@Test(dataProvider = "predixMapperDataProvider") public void testPredixAuditEventMapper(final String requestBody, final String methodType, final int status, final String responseBody, final String zoneId, final String correlationId, final PublisherType publisherType, final CategoryType categoryType, final EventType eventType, final Classifier classifier) throws IOException { PredixEventMapper mapper = new PredixEventMapper(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setContent(requestBody.getBytes()); MockHttpServletResponse response = new MockHttpServletResponse(); request.setMethod(methodType); request.setRequestURI("not-used"); response.setStatus(status); ContentCachingRequestWrapper cachedRequest = new ContentCachingRequestWrapper(request); ContentCachingResponseWrapper cachedResponse = new ContentCachingResponseWrapper(response); cachedResponse.getWriter().write(responseBody); cachedRequest.getReader().readLine(); AuditEvent event = new AuditEvent(cachedRequest, cachedResponse, zoneId, correlationId); AuditEventV2 predixEvent = mapper.map(event); Assert.assertTrue(predixEvent.getPayload().contains(requestBody)); Assert.assertTrue(predixEvent.getPayload().contains(methodType)); Assert.assertTrue(predixEvent.getPayload().contains(responseBody)); Assert.assertEquals(predixEvent.getPublisherType(), publisherType); Assert.assertEquals(predixEvent.getCategoryType(), categoryType); Assert.assertEquals(predixEvent.getEventType(), eventType); Assert.assertEquals(predixEvent.getClassifier(), classifier); }