LogMaskerService { public void execute(String filterType, Boolean deleteBody, Boolean deleteUri, Boolean headers, List<String> ignoredHeaders) { RequestResponseParser requestResponseParser = null; switch (filterType) { case PRE_TYPE: requestResponseParser = TraceContextHolder.getInstance().getActualTrace().getRequest(); break; case POST_TYPE: requestResponseParser = TraceContextHolder.getInstance().getActualTrace().getResponse(); break; default: break; } if (requestResponseParser != null) { if (deleteBody) requestResponseParser.setBody(null); if (deleteUri) requestResponseParser.setUri(null); if (headers) { if (ignoredHeaders.isEmpty()) { requestResponseParser.setHeaders(null); } else { final Map<String, String> requestResponseHeaders = requestResponseParser.getHeaders(); ignoredHeaders.forEach(requestResponseHeaders::remove); } } } }  void execute(String filterType,
                        Boolean deleteBody,
                        Boolean deleteUri,
                        Boolean headers,
                        List<String> ignoredHeaders);  }
@Test public void requestDeleteAll() { logMaskerService.execute(PRE_TYPE, true, true, true, new ArrayList<>()); RequestResponseParser request = TraceContextHolder.getInstance().getActualTrace().getRequest(); assertNull(request.getBody()); assertNull(request.getUri()); assertNull(request.getHeaders()); }
@Test public void requestDeleteBody() { logMaskerService.execute(PRE_TYPE, true, false, false, new ArrayList<>()); RequestResponseParser request = TraceContextHolder.getInstance().getActualTrace().getRequest(); assertNull(request.getBody()); assertNotNull(request.getUri()); assertNotNull(request.getHeaders()); }
@Test public void requestDeleteUri() { logMaskerService.execute(PRE_TYPE, false, true, false, new ArrayList<>()); RequestResponseParser request = TraceContextHolder.getInstance().getActualTrace().getRequest(); assertNotNull(request.getBody()); assertNull(request.getUri()); assertNotNull(request.getHeaders()); }
@Test public void requestDeleteAllHeaders() { logMaskerService.execute(PRE_TYPE, false, false, true, new ArrayList<>()); RequestResponseParser request = TraceContextHolder.getInstance().getActualTrace().getRequest(); assertNotNull(request.getBody()); assertNotNull(request.getUri()); assertNull(request.getHeaders()); }
@Test public void requestDeleteSomeHeaders() { List<String> ignoredHeaders = Arrays.asList("simpleHeader", "host"); logMaskerService.execute(PRE_TYPE, false, false, true, ignoredHeaders); RequestResponseParser request = TraceContextHolder.getInstance().getActualTrace().getRequest(); assertNotNull(request.getBody()); assertNotNull(request.getUri()); assertNotNull(request.getHeaders()); assertNull(request.getHeaders().get("simpleHeader")); assertNull(request.getHeaders().get("host")); }
@Test public void requestDeleteAbsentHeaders() { List<String> ignoredHeaders = Arrays.asList("simpleHeader", "host", "someOtherHeader"); logMaskerService.execute(PRE_TYPE, false, false, true, ignoredHeaders); RequestResponseParser request = TraceContextHolder.getInstance().getActualTrace().getRequest(); assertNotNull(request.getBody()); assertNotNull(request.getUri()); assertNotNull(request.getHeaders()); assertNull(request.getHeaders().get("simpleHeader")); assertNull(request.getHeaders().get("host")); assertNull(request.getHeaders().get("someOtherHeader")); }
@Test public void responseDeleteAll() { logMaskerService.execute(POST_TYPE, true, true, true, new ArrayList<>()); RequestResponseParser response = TraceContextHolder.getInstance().getActualTrace().getResponse(); assertNull(response.getBody()); assertNull(response.getUri()); assertNull(response.getHeaders()); }
@Test public void responseDeleteBody() { logMaskerService.execute(POST_TYPE, true, false, false, new ArrayList<>()); RequestResponseParser response = TraceContextHolder.getInstance().getActualTrace().getResponse(); assertNull(response.getBody()); assertNotNull(response.getUri()); assertNotNull(response.getHeaders()); }
@Test public void responseDeleteUri() { logMaskerService.execute(POST_TYPE, false, true, false, new ArrayList<>()); RequestResponseParser response = TraceContextHolder.getInstance().getActualTrace().getResponse(); assertNotNull(response.getBody()); assertNull(response.getUri()); assertNotNull(response.getHeaders()); }
@Test public void responseDeleteAllHeaders() { logMaskerService.execute(POST_TYPE, false, false, true, new ArrayList<>()); RequestResponseParser response = TraceContextHolder.getInstance().getActualTrace().getResponse(); assertNotNull(response.getBody()); assertNotNull(response.getUri()); assertNull(response.getHeaders()); }
@Test public void responseDeleteSomeHeaders() { List<String> ignoredHeaders = Arrays.asList("simpleHeader", "host"); logMaskerService.execute(POST_TYPE, false, false, true, ignoredHeaders); RequestResponseParser response = TraceContextHolder.getInstance().getActualTrace().getResponse(); assertNotNull(response.getBody()); assertNotNull(response.getUri()); assertNotNull(response.getHeaders()); assertNull(response.getHeaders().get("simpleHeader")); assertNull(response.getHeaders().get("host")); }
@Test public void responseDeleteAbsentHeaders() { List<String> ignoredHeaders = Arrays.asList("simpleHeader", "host", "someOtherHeader"); logMaskerService.execute(POST_TYPE, false, false, true, ignoredHeaders); RequestResponseParser response = TraceContextHolder.getInstance().getActualTrace().getResponse(); assertNotNull(response.getBody()); assertNotNull(response.getUri()); assertNotNull(response.getHeaders()); assertNull(response.getHeaders().get("simpleHeader")); assertNull(response.getHeaders().get("host")); assertNull(response.getHeaders().get("someOtherHeader")); }