Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #30 from tobiasgindler/master
Browse files Browse the repository at this point in the history
[#22] Activated itests in build process.
  • Loading branch information
tobiasgindler committed May 18, 2015
2 parents 0e53dec + 938e8ab commit 76d18ed
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 46 deletions.
4 changes: 4 additions & 0 deletions integration-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<groupId>io.tracee.contextlogger</groupId>
<artifactId>contextlogger-core</artifactId>
</dependency>
<dependency>
<groupId>io.tracee.contextlogger</groupId>
<artifactId>testhelper</artifactId>
</dependency>

<!-- dependecies for unittests -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,28 @@
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 {

@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']\"}"));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 !!!']\"}"));

}

Expand All @@ -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"));

}

Expand All @@ -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!!!']\"}"));

}

Expand All @@ -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"));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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[]\""));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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']\"}"));

}

Expand All @@ -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[]\""));

}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<module>core</module>

<!-- tests and test related -->
<!-- <module>integration-test</module> -->
<module>integration-test</module>
<module>testhelper</module>

</modules>
Expand Down

0 comments on commit 76d18ed

Please sign in to comment.