|
7 | 7 | import io.dropwizard.logging.common.async.AsyncLoggingEventAppenderFactory; |
8 | 8 | import io.dropwizard.logging.common.filter.ThresholdLevelFilterFactory; |
9 | 9 | import io.dropwizard.logging.common.layout.DropwizardLayoutFactory; |
| 10 | +import io.sentry.SentryOptions; |
10 | 11 | import io.sentry.logback.SentryAppender; |
| 12 | +import org.dhatim.dropwizard.sentry.SentryConfigurator; |
| 13 | +import org.hamcrest.collection.IsIterableContainingInOrder; |
| 14 | +import org.hamcrest.collection.IsMapContaining; |
11 | 15 | import org.junit.jupiter.api.Test; |
12 | 16 |
|
13 | 17 | import java.io.IOException; |
| 18 | +import java.util.List; |
| 19 | +import java.util.Map; |
14 | 20 |
|
15 | 21 | import static org.hamcrest.CoreMatchers.instanceOf; |
16 | 22 | import static org.hamcrest.MatcherAssert.assertThat; |
17 | | -import static org.junit.jupiter.api.Assertions.assertNull; |
18 | | -import static org.junit.jupiter.api.Assertions.assertThrows; |
| 23 | +import static org.junit.jupiter.api.Assertions.*; |
19 | 24 |
|
20 | 25 | public class SentryAppenderFactoryTest { |
21 | 26 |
|
@@ -50,4 +55,42 @@ public void buildSentryAppenderShouldWorkWithValidConfiguration() { |
50 | 55 | assertThat(appender, instanceOf(SentryAppender.class)); |
51 | 56 | } |
52 | 57 |
|
| 58 | + @Test |
| 59 | + void buildSentryAppenderFullConfiguration() { |
| 60 | + SentryAppenderFactory factory = new SentryAppenderFactory(); |
| 61 | + factory. dsn = "https://user:[email protected]/id"; |
| 62 | + factory.environment = "test"; |
| 63 | + factory.tags = Map.of("tag1", "value1"); |
| 64 | + factory.release = "1.0.0"; |
| 65 | + factory.serverName = "10.0.0.1"; |
| 66 | + factory.inAppIncludes = List.of("com.example"); |
| 67 | + factory.inAppExcludes = List.of("com.thirdparty"); |
| 68 | + factory.contextTags = List.of("contextTag1"); |
| 69 | + factory.configurator = CaptureSentryConfigurator.class.getName(); |
| 70 | + |
| 71 | + Appender<ILoggingEvent> appender = factory.build(context, "", layoutFactory, levelFilterFactory, asyncAppenderFactory); |
| 72 | + assertThat(appender, instanceOf(SentryAppender.class)); |
| 73 | + |
| 74 | + SentryOptions capturedOptions = CaptureSentryConfigurator.capturedOptions; |
| 75 | + assertNotNull(capturedOptions); |
| 76 | + |
| 77 | + assertEquals( "https://user:[email protected]/id", capturedOptions. getDsn()); |
| 78 | + assertEquals("test", capturedOptions.getEnvironment()); |
| 79 | + assertEquals("1.0.0", capturedOptions.getRelease()); |
| 80 | + assertThat(capturedOptions.getContextTags(), IsIterableContainingInOrder.contains("contextTag1")); |
| 81 | + assertEquals("10.0.0.1", capturedOptions.getServerName()); |
| 82 | + assertThat(capturedOptions.getTags(), IsMapContaining.hasEntry("tag1", "value1")); |
| 83 | + assertThat(capturedOptions.getInAppIncludes(), IsIterableContainingInOrder.contains("com.example")); |
| 84 | + assertThat(capturedOptions.getInAppExcludes(), IsIterableContainingInOrder.contains("com.thirdparty")); |
| 85 | + |
| 86 | + } |
| 87 | + |
| 88 | + protected static class CaptureSentryConfigurator implements SentryConfigurator { |
| 89 | + static SentryOptions capturedOptions; |
| 90 | + @Override |
| 91 | + public void configure(SentryOptions options) { |
| 92 | + capturedOptions = options; |
| 93 | + } |
| 94 | + } |
| 95 | + |
53 | 96 | } |
0 commit comments