LoggingUtils { public static boolean isContentTypeLoggable(final String contentType, final ExecutionContext executionContext) { if (EXCLUDED_CONTENT_TYPES_PATTERN == null) { try { final String responseTypes = (String) executionContext.getAttribute(ExecutionContext.ATTR_PREFIX + "logging.response.excluded.types"); EXCLUDED_CONTENT_TYPES_PATTERN = Pattern.compile(responseTypes); } catch (Exception e) { EXCLUDED_CONTENT_TYPES_PATTERN = Pattern.compile(DEFAULT_EXCLUDED_CONTENT_TYPES); } } return contentType == null || !EXCLUDED_CONTENT_TYPES_PATTERN.matcher(contentType).find(); }  static int getMaxSizeLogMessage(ExecutionContext executionContext); static boolean isContentTypeLoggable(final String contentType, final ExecutionContext executionContext); static void appendBuffer(Buffer buffer, Buffer chunk, int maxLength);  }
@Test public void shouldNotLogCustom() throws Exception { resetStatic(); ExecutionContext executionContext = mock(ExecutionContext.class); when(executionContext.getAttribute("gravitee.attribute.logging.response.excluded.types")).thenReturn("foo/bar"); assertFalse(LoggingUtils.isContentTypeLoggable("foo/bar", executionContext)); }
@Test public void shouldLogCustom() throws Exception { resetStatic(); ExecutionContext executionContext = mock(ExecutionContext.class); assertTrue(LoggingUtils.isContentTypeLoggable("foo/bar", executionContext)); }
@Test public void shouldLogByDefault() throws Exception { resetStatic(); ExecutionContext executionContext = mock(ExecutionContext.class); assertTrue(LoggingUtils.isContentTypeLoggable("application/json", executionContext)); }
@Test public void shouldNotLogImageByDefault() throws Exception { resetStatic(); ExecutionContext executionContext = mock(ExecutionContext.class); assertFalse(LoggingUtils.isContentTypeLoggable("image/png", executionContext)); }
@Test public void shouldNotLogAudioByDefault() throws Exception { resetStatic(); ExecutionContext executionContext = mock(ExecutionContext.class); assertFalse(LoggingUtils.isContentTypeLoggable("audio/ogg", executionContext)); }
@Test public void shouldNotLogVideoByDefault() throws Exception { resetStatic(); ExecutionContext executionContext = mock(ExecutionContext.class); assertFalse(LoggingUtils.isContentTypeLoggable("video/ogg", executionContext)); }
@Test public void shouldNotLogPDFByDefault() throws Exception { resetStatic(); ExecutionContext executionContext = mock(ExecutionContext.class); assertFalse(LoggingUtils.isContentTypeLoggable("application/pdf", executionContext)); }