use of com.newrelic.agent.config.StripExceptionConfigImpl in project newrelic-java-agent by newrelic.
the class ErrorMessageReplacerTest method shouldHandleNullMessages.
@Test
public void shouldHandleNullMessages() {
ErrorMessageReplacer target = new ErrorMessageReplacer(new StripExceptionConfigImpl(true, Collections.singleton(RuntimeException.class.getName())));
assertEquals("", target.getMessage(null));
assertEquals("", target.getMessage(new RuntimeException((String) null)));
}
use of com.newrelic.agent.config.StripExceptionConfigImpl in project newrelic-java-agent by newrelic.
the class ErrorMessageReplacerTest method shouldAllowSpecificClassesWhenEnabled.
@Test
public void shouldAllowSpecificClassesWhenEnabled() {
ErrorMessageReplacer target = new ErrorMessageReplacer(new StripExceptionConfigImpl(true, Collections.singleton(RuntimeException.class.getName())));
assertEquals(ErrorMessageReplacer.STRIPPED_EXCEPTION_REPLACEMENT, target.getMessage(new Throwable("stripped")));
assertEquals("NOT stripped", target.getMessage(new RuntimeException("NOT stripped")));
}
use of com.newrelic.agent.config.StripExceptionConfigImpl in project newrelic-java-agent by newrelic.
the class ErrorMessageReplacerTest method shouldReplaceWhenEnabled.
@Test
public void shouldReplaceWhenEnabled() {
ErrorMessageReplacer target = new ErrorMessageReplacer(new StripExceptionConfigImpl(true, null));
assertEquals(ErrorMessageReplacer.STRIPPED_EXCEPTION_REPLACEMENT, target.getMessage(new Throwable("stripped")));
}
use of com.newrelic.agent.config.StripExceptionConfigImpl in project newrelic-java-agent by newrelic.
the class ErrorMessageReplacerTest method shouldAllowAllClassesWhenDisabled.
@Test
public void shouldAllowAllClassesWhenDisabled() {
ErrorMessageReplacer target = new ErrorMessageReplacer(new StripExceptionConfigImpl(false, Collections.singleton(RuntimeException.class.getName())));
assertEquals("NOT stripped!", target.getMessage(new Throwable("NOT stripped!")));
assertEquals("NOT stripped", target.getMessage(new RuntimeException("NOT stripped")));
}
use of com.newrelic.agent.config.StripExceptionConfigImpl in project newrelic-java-agent by newrelic.
the class TracedErrorTest method nestedExceptionsStripAll.
@Test
public void nestedExceptionsStripAll() {
Exception nested2 = new NullPointerException("Null Pointer Exception should be stripped");
Exception nested1 = new IOException("IO Exception should be stripped", nested2);
Exception top = new RuntimeException("RuntimeException should be stripped", nested1);
Exception suppressed = new IllegalStateException("IllegalStateException should be stripped");
top.addSuppressed(suppressed);
ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
TracedError error = ThrowableError.builder(errorCollectorConfig, null, null, top, System.currentTimeMillis()).errorMessageReplacer(new ErrorMessageReplacer(new StripExceptionConfigImpl(true, Collections.<String>emptySet()))).build();
assertEquals(error.getMessage(), "Message removed by New Relic 'strip_exception_messages' setting");
Collection<String> stackTrace = error.stackTrace();
assertNotNull(stackTrace);
Iterator<String> it = stackTrace.iterator();
String next = findNextContaining(it, "Suppressed:");
assertTrue(next, next.contains("Suppressed: java.lang.IllegalStateException: Message removed by New Relic 'strip_exception_messages' setting"));
assertFalse(next.contains(suppressed.toString()));
next = findNextCausedBy(it);
assertTrue(next, next.contains("caused by java.io.IOException: Message removed by New Relic 'strip_exception_messages' setting"));
assertFalse(next.contains(nested1.toString()));
next = findNextCausedBy(it);
assertTrue(next, next.contains("caused by java.lang.NullPointerException: Message removed by New Relic 'strip_exception_messages' setting"));
assertFalse(next.contains(nested2.toString()));
}
Aggregations