From 938e8abefcf48bf11ab031307b6a5e2bb85b7b4e Mon Sep 17 00:00:00 2001 From: Tobias Gindler Date: Tue, 19 May 2015 00:26:24 +0200 Subject: [PATCH] [#22] Activated itests in build process. --- integration-test/pom.xml | 4 +++ ...TestBrokenImplicitContextDataProvider.java | 18 ++++++++----- ...ntextLoggerExternalBasicProfile.properties | 2 ++ ...xtLoggerExternalEnhancedProfile.properties | 2 ++ ...ontextLoggerExternalFullProfile.properties | 2 ++ .../BrokenExternalWrapperIntegrationTest.java | 20 ++++++--------- .../ExternalWrapperIntegrationTest.java | 25 ++++++++----------- .../ImplicitContextIntegrationTest.java | 16 +++++++----- .../MissingConstructorIntegrationTest.java | 13 ++++++---- pom.xml | 2 +- 10 files changed, 58 insertions(+), 46 deletions(-) diff --git a/integration-test/pom.xml b/integration-test/pom.xml index 96b8167..9324f79 100644 --- a/integration-test/pom.xml +++ b/integration-test/pom.xml @@ -34,6 +34,10 @@ io.tracee.contextlogger contextlogger-core + + io.tracee.contextlogger + testhelper + diff --git a/integration-test/src/main/java/io/tracee/contextlogger/integrationtest/TestBrokenImplicitContextDataProvider.java b/integration-test/src/main/java/io/tracee/contextlogger/integrationtest/TestBrokenImplicitContextDataProvider.java index 5576009..ed24a74 100644 --- a/integration-test/src/main/java/io/tracee/contextlogger/integrationtest/TestBrokenImplicitContextDataProvider.java +++ b/integration-test/src/main/java/io/tracee/contextlogger/integrationtest/TestBrokenImplicitContextDataProvider.java @@ -10,12 +10,18 @@ @TraceeContextProvider(displayName = "testBrokenImplicitContextData", order = 200) public class TestBrokenImplicitContextDataProvider implements CustomImplicitContextData { - public static final String PROPERTY_NAME = "io.tracee.contextlogger.integrationtest.TestBrokenImplicitContextDataProvider.output"; + public static final String PROPERTY_NAME = "io.tracee.contextlogger.integrationtest.TestBrokenImplicitContextDataProvider.output"; - @SuppressWarnings("unused") - @TraceeContextProviderMethod(displayName = "output", order = 10) - public final String getOutput() { - throw new NullPointerException("Whoops!!!"); - } + @SuppressWarnings("unused") + @TraceeContextProviderMethod(displayName = "output", order = 10) + public final String getOutput() { + throw new NullPointerException("Whoops!!!"); + } + + @SuppressWarnings("unused") + @TraceeContextProviderMethod(displayName = "workingOutput", order = 20) + public final String getWorkingOutput() { + return "IT_WORKS"; + } } diff --git a/integration-test/src/main/resources/TraceeContextLoggerExternalBasicProfile.properties b/integration-test/src/main/resources/TraceeContextLoggerExternalBasicProfile.properties index ae604af..d6e31fb 100644 --- a/integration-test/src/main/resources/TraceeContextLoggerExternalBasicProfile.properties +++ b/integration-test/src/main/resources/TraceeContextLoggerExternalBasicProfile.properties @@ -5,3 +5,5 @@ io.tracee.contextlogger.integrationtest.TestImplicitContextDataProvider.output=f io.tracee.contextlogger.integrationtest.BrokenCustomContextDataWrapper.output=false io.tracee.contextlogger.integrationtest.TestImplicitContextDataProvider.testBrokenOutputPropertyName=false io.tracee.contextlogger.integrationtest.TestBrokenImplicitContentDataProviderWithoutDefaultConstructor.testOutputPropertyName=false +io.tracee.contextlogger.integrationtest.TestBrokenImplicitContextDataProvider.output=true +io.tracee.contextlogger.integrationtest.TestBrokenImplicitContextDataProvider.workingOutput=true diff --git a/integration-test/src/main/resources/TraceeContextLoggerExternalEnhancedProfile.properties b/integration-test/src/main/resources/TraceeContextLoggerExternalEnhancedProfile.properties index f5f481a..62fe36d 100644 --- a/integration-test/src/main/resources/TraceeContextLoggerExternalEnhancedProfile.properties +++ b/integration-test/src/main/resources/TraceeContextLoggerExternalEnhancedProfile.properties @@ -3,3 +3,5 @@ io.tracee.contextlogger.integrationtest.TestContextDataWrapper.output=true io.tracee.contextlogger.integrationtest.TestImplicitContextDataProvider.output=true io.tracee.contextlogger.integrationtest.BrokenCustomContextDataWrapper.output=true io.tracee.contextlogger.integrationtest.TestBrokenImplicitContentDataProviderWithoutDefaultConstructor.testOutputPropertyName=true +io.tracee.contextlogger.integrationtest.TestBrokenImplicitContextDataProvider.output=true +io.tracee.contextlogger.integrationtest.TestBrokenImplicitContextDataProvider.workingOutput=true diff --git a/integration-test/src/main/resources/TraceeContextLoggerExternalFullProfile.properties b/integration-test/src/main/resources/TraceeContextLoggerExternalFullProfile.properties index f5f481a..62fe36d 100644 --- a/integration-test/src/main/resources/TraceeContextLoggerExternalFullProfile.properties +++ b/integration-test/src/main/resources/TraceeContextLoggerExternalFullProfile.properties @@ -3,3 +3,5 @@ io.tracee.contextlogger.integrationtest.TestContextDataWrapper.output=true io.tracee.contextlogger.integrationtest.TestImplicitContextDataProvider.output=true io.tracee.contextlogger.integrationtest.BrokenCustomContextDataWrapper.output=true io.tracee.contextlogger.integrationtest.TestBrokenImplicitContentDataProviderWithoutDefaultConstructor.testOutputPropertyName=true +io.tracee.contextlogger.integrationtest.TestBrokenImplicitContextDataProvider.output=true +io.tracee.contextlogger.integrationtest.TestBrokenImplicitContextDataProvider.workingOutput=true diff --git a/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/BrokenExternalWrapperIntegrationTest.java b/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/BrokenExternalWrapperIntegrationTest.java index 8ff7d80..75ab580 100644 --- a/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/BrokenExternalWrapperIntegrationTest.java +++ b/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/BrokenExternalWrapperIntegrationTest.java @@ -5,6 +5,7 @@ import org.junit.Test; import io.tracee.contextlogger.TraceeContextLogger; +import io.tracee.contextlogger.outputgenerator.writer.BasicOutputWriterConfiguration; import io.tracee.contextlogger.profile.Profile; public class BrokenExternalWrapperIntegrationTest { @@ -12,27 +13,20 @@ public class BrokenExternalWrapperIntegrationTest { @Test public void should_ignore_properties_for_wrapper_that_throw_an_exception() { - // should not break because of the thrown NPE, Exception is handled internally ==> getter with exception should be ignored + // should not break because of the thrown NPE - Exception is handled internally ==> getter with exception should be ignored + // instances with no valid output field will be ignored, so this test has no instances to render and returns "null" String result = TraceeContextLogger.create().enforceProfile(Profile.ENHANCED).apply().toString(new WrappedBrokenTestContextData()); - MatcherAssert.assertThat(result, Matchers.is("{\"brokenCustomContextDataWrapper\":{}}")); - - } - - @Test - public void should_ignore_properties_for_custom_implicit_context_data_provider_that_throw_an_exception() { - - // should not break because of the thrown NPE, Exception is handled internally ==> getter with exception should be ignored - String result = TraceeContextLogger.create().enforceProfile(Profile.ENHANCED).apply().toString(new TestBrokenImplicitContextDataProvider()); MatcherAssert.assertThat(result, Matchers.is("null")); } @Test - public void should_ignore_properties_for_custom_implicit_context_data_provider_that_throw_an_exception2() { + public void should_ignore_properties_for_custom_implicit_context_data_provider_that_throw_an_exception() { // should not break because of the thrown NPE, Exception is handled internally ==> getter with exception should be ignored - String result = TraceeContextLogger.create().enforceProfile(Profile.ENHANCED).apply().toString(TestBrokenImplicitContextDataProvider.class); - MatcherAssert.assertThat(result, Matchers.is("{\"testBrokenImplicitContextData\":{}}")); + String result = TraceeContextLogger.create().enforceOutputWriterConfiguration(BasicOutputWriterConfiguration.JSON_INLINE) + .enforceProfile(Profile.ENHANCED).apply().toString(new TestBrokenImplicitContextDataProvider()); + MatcherAssert.assertThat(result, Matchers.is("{\"TYPE\":\"testBrokenImplicitContextData\",\"workingOutput\":\"String['IT_WORKS']\"}")); } diff --git a/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/ExternalWrapperIntegrationTest.java b/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/ExternalWrapperIntegrationTest.java index 1aa7389..4fe60b5 100644 --- a/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/ExternalWrapperIntegrationTest.java +++ b/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/ExternalWrapperIntegrationTest.java @@ -15,23 +15,17 @@ public void should_wrap_with_external_wrappers_correctly_using_basic_profile() { String result = TraceeContextLogger.create().enforceProfile(Profile.BASIC).apply().toString(new WrappedTestContextData()); - MatcherAssert.assertThat(result, Matchers.is("{\"testdata\":{}}")); + MatcherAssert.assertThat(result, Matchers.is("null")); } @Test public void should_wrap_with_external_wrappers_correctly_using_enhanced_profile() { - String result = TraceeContextLogger.create().enforceProfile(Profile.ENHANCED).apply().toString(new WrappedTestContextData()); + String result = TraceeContextLogger.create().enforceOutputWriterConfiguration(BasicOutputWriterConfiguration.JSON_INLINE) + .enforceProfile(Profile.ENHANCED).apply().toString(new WrappedTestContextData()); - /* - * System.out.println(TraceeContextLogger.create().config().enforceOutputWriterConfiguration(OutputWriterConfiguration.JSON_INLINE).apply().build() - * .wrap("ABC", "DEF", "IHK", this).toString()); - */ - System.out.println(TraceeContextLogger.create().enforceOutputWriterConfiguration(BasicOutputWriterConfiguration.JSON_INLINE).apply() - .wrap("ABC", "DEF", "IHK", 23.8, 25L, 32434.324, this).toString()); - - MatcherAssert.assertThat(result, Matchers.is("{\"testdata\":{\"testoutput\":\"IT WORKS !!!\"}}")); + MatcherAssert.assertThat(result, Matchers.is("{\"TYPE\":\"testdata\",\"testoutput\":\"String['IT WORKS !!!']\"}")); } @@ -41,7 +35,7 @@ public void should_wrap_with_external_wrappers_correctly_using_enhanced_profile_ String result = TraceeContextLogger.create().enforceProfile(Profile.ENHANCED).disable(TestContextDataWrapper.PROPERTY_NAME).apply() .toString(new WrappedTestContextData()); - MatcherAssert.assertThat(result, Matchers.is("{\"testdata\":{}}")); + MatcherAssert.assertThat(result, Matchers.is("null")); } @@ -50,16 +44,17 @@ public void should_wrap_with_implicit_context_provider_correctly_using_basic_pro String result = TraceeContextLogger.create().enforceProfile(Profile.BASIC).apply().toString(new TestImplicitContextDataProvider()); - MatcherAssert.assertThat(result, Matchers.is("{\"testImplicitContextData\":{}}")); + MatcherAssert.assertThat(result, Matchers.is("null")); } @Test public void should_wrap_with_implicit_context_provider_correctly_using_enhanced_profile() { - String result = TraceeContextLogger.create().enforceProfile(Profile.ENHANCED).apply().toString(new TestImplicitContextDataProvider()); + String result = TraceeContextLogger.create().enforceOutputWriterConfiguration(BasicOutputWriterConfiguration.JSON_INLINE) + .enforceProfile(Profile.ENHANCED).apply().toString(new TestImplicitContextDataProvider()); - MatcherAssert.assertThat(result, Matchers.is("{\"testImplicitContextData\":{\"output\":\"IT WORKS TOO!!!\"}}")); + MatcherAssert.assertThat(result, Matchers.is("{\"TYPE\":\"testImplicitContextData\",\"output\":\"String['IT WORKS TOO!!!']\"}")); } @@ -69,7 +64,7 @@ public void should_wrap_with_implicit_context_provider_correctly_using_enhanced_ String result = TraceeContextLogger.create().enforceProfile(Profile.ENHANCED).disable(TestImplicitContextDataProvider.PROPERTY_NAME).apply() .toString(new TestImplicitContextDataProvider()); - MatcherAssert.assertThat(result, Matchers.is("{\"testImplicitContextData\":{}}")); + MatcherAssert.assertThat(result, Matchers.is("null")); } diff --git a/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/ImplicitContextIntegrationTest.java b/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/ImplicitContextIntegrationTest.java index 805a697..9f150ee 100644 --- a/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/ImplicitContextIntegrationTest.java +++ b/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/ImplicitContextIntegrationTest.java @@ -6,7 +6,9 @@ import io.tracee.contextlogger.TraceeContextLogger; import io.tracee.contextlogger.api.ImplicitContext; +import io.tracee.contextlogger.outputgenerator.writer.BasicOutputWriterConfiguration; import io.tracee.contextlogger.profile.Profile; +import io.tracee.contextlogger.util.test.RegexMatcher; /** * Integration test for {@link io.tracee.contextlogger.api.ImplicitContext} wrapping. @@ -15,30 +17,32 @@ public class ImplicitContextIntegrationTest { @Test public void shouldOutputImplicitContextCorrectly() { - String result = TraceeContextLogger.create().enforceProfile(Profile.BASIC).apply().toString(ImplicitContext.COMMON, ImplicitContext.TRACEE); + String result = TraceeContextLogger.create().enforceOutputWriterConfiguration(BasicOutputWriterConfiguration.JSON_INLINE) + .enforceProfile(Profile.BASIC).apply().toString(ImplicitContext.COMMON, ImplicitContext.TRACEE); - MatcherAssert.assertThat(result, Matchers.is("{\"testImplicitContextData\":{}}")); + MatcherAssert.assertThat(result, RegexMatcher.matches("\\[\"TYPE:Object\\[]\",\\{\"TYPE\":\"common\",\"thread-id\".*")); } @Test public void shouldOutputSingleEmptyImplicitContextCorrectly() { - String result = TraceeContextLogger.create().enforceProfile(Profile.BASIC).apply().toString(ImplicitContext.TRACEE); + String result = TraceeContextLogger.create().enforceOutputWriterConfiguration(BasicOutputWriterConfiguration.JSON_INLINE) + .enforceProfile(Profile.BASIC).apply().toString(ImplicitContext.TRACEE); - MatcherAssert.assertThat(result, Matchers.is("null")); + MatcherAssert.assertThat(result, Matchers.is("{\"TYPE\":\"tracee\",\"DYNAMIC\":null}")); } @Test public void should_write_instance_for_multiple_referenced_instances() { String result = TraceeContextLogger.create().enforceProfile(Profile.BASIC).apply().toString("ABC"); - MatcherAssert.assertThat(result, Matchers.is("null")); + MatcherAssert.assertThat(result, Matchers.is("\"String['ABC']\"")); } @Test public void should_write_this_instance_without_tostring_overwrite_correctly() { String result = TraceeContextLogger.create().enforceProfile(Profile.BASIC).apply().toString(this); - MatcherAssert.assertThat(result, Matchers.is("null")); + MatcherAssert.assertThat(result, Matchers.is("\"ImplicitContextIntegrationTest[]\"")); } } diff --git a/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/MissingConstructorIntegrationTest.java b/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/MissingConstructorIntegrationTest.java index a8190fe..c39d332 100644 --- a/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/MissingConstructorIntegrationTest.java +++ b/integration-test/src/test/java/io/tracee/contextlogger/integrationtest/MissingConstructorIntegrationTest.java @@ -5,6 +5,7 @@ import org.junit.Test; import io.tracee.contextlogger.TraceeContextLogger; +import io.tracee.contextlogger.outputgenerator.writer.BasicOutputWriterConfiguration; import io.tracee.contextlogger.profile.Profile; /** @@ -16,9 +17,12 @@ public class MissingConstructorIntegrationTest { public void should_handle_missing_no_args_constructor_gently() { // should not break because of the missing no args constructor => type will be deserialized instead - String result = TraceeContextLogger.create().enforceProfile(Profile.ENHANCED).apply() - .toString(TestBrokenImplicitContentDataProviderWithoutDefaultConstructor.class); - MatcherAssert.assertThat(result, Matchers.startsWith("{\"java.lang.Class\"")); + String result = TraceeContextLogger.create().enforceOutputWriterConfiguration(BasicOutputWriterConfiguration.JSON_INLINE) + .enforceProfile(Profile.ENHANCED).apply().toString(TestBrokenImplicitContentDataProviderWithoutDefaultConstructor.class); + MatcherAssert + .assertThat( + result, + Matchers.equalTo("{\"TYPE\":\"Class\",\"enumConstants\":null,\"name\":\"String['io.tracee.contextlogger.integrationtest.TestBrokenImplicitContentDataProviderWithoutDefaultConstructor']\"}")); } @@ -28,8 +32,7 @@ public void should_wrap_with_external_wrappers_correctly_using_enhanced_profile( // should not default deserialization mechanism, because context data provider wrapper can't be created. String result = TraceeContextLogger.create().enforceProfile(Profile.ENHANCED).apply() .toString(new BrokenCustomContextDataWrapperWithMissingNoargsConstructor()); - MatcherAssert.assertThat(result, - Matchers.startsWith("{\"io.tracee.contextlogger.integrationtest.BrokenCustomContextDataWrapperWithMissingNoargsConstructor\"")); + MatcherAssert.assertThat(result, Matchers.startsWith("\"BrokenCustomContextDataWrapperWithMissingNoargsConstructor[]\"")); } diff --git a/pom.xml b/pom.xml index 2b2b1c7..450c80e 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ core - + integration-test testhelper