Skip to content

Commit

Permalink
improved issue #12 implementation: marking diffs in expected result too
Browse files Browse the repository at this point in the history
  • Loading branch information
S1artie committed Jul 18, 2014
1 parent 1576601 commit 8127e84
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ packagedef mypackage with
testdef beanTest uses de.gebit.integrity.experiments.fixtures.BeanFixture#beanInput

calldef untypedBeanCall uses de.gebit.integrity.experiments.fixtures.BeanFixture#untypedBeanEcho
testdef untypedBeanTest uses de.gebit.integrity.experiments.fixtures.BeanFixture#untypedBeanEcho

calldef extendedResult uses de.gebit.integrity.experiments.fixtures.ExtendedResultTestFixture#returnExtendedStuff
testdef extendedResultTest uses de.gebit.integrity.experiments.fixtures.ExtendedResultTestFixture#returnExtendedStuff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Hashtable;
import java.util.Map;

import de.gebit.integrity.comparator.MapComparisonResult;
import de.gebit.integrity.dsl.KeyValuePair;
import de.gebit.integrity.dsl.NestedObject;
import de.gebit.integrity.operations.UnexecutableException;
Expand Down Expand Up @@ -39,6 +40,11 @@ public abstract class AbstractNestedObjectToString<T> extends Conversion<NestedO
*/
private static Map<Thread, Integer> nestedObjectDepthMap = new Hashtable<Thread, Integer>();

/**
* The property in the {@link ConversionContext} used to transport the path in the map.
*/
protected static final String NESTEDOBJECT_PATH_PROPERTY = "path";

/**
* Converts the provided {@link NestedObject} to a {@link FormattedString}.
*
Expand All @@ -51,6 +57,8 @@ public abstract class AbstractNestedObjectToString<T> extends Conversion<NestedO
*/
protected FormattedString convertToFormattedString(NestedObject aSource, ConversionContext aConversionContext)
throws ConversionFailedException {
String tempParentObjectPath = (String) aConversionContext.getProperty(NESTEDOBJECT_PATH_PROPERTY);

FormattedString tempBuffer = new FormattedString("{");
tempBuffer.add(new FormatTokenElement(FormatTokenType.NEWLINE));

Expand All @@ -65,6 +73,14 @@ protected FormattedString convertToFormattedString(NestedObject aSource, Convers
try {
boolean tempFirst = true;
for (KeyValuePair tempAttribute : aSource.getAttributes()) {
String tempCurrentObjectPath = (tempParentObjectPath != null ? tempParentObjectPath + "." : "")
+ IntegrityDSLUtil.getIdentifierFromKeyValuePair(tempAttribute);
aConversionContext.withProperty(NESTEDOBJECT_PATH_PROPERTY, tempCurrentObjectPath);

boolean tempCurrentPathFailed = (aConversionContext.getComparisonResult() instanceof MapComparisonResult)
&& ((MapComparisonResult) aConversionContext.getComparisonResult()).getFailedPaths().contains(
tempCurrentObjectPath);

Object tempConvertedValue;
try {
tempConvertedValue = convertValueRecursive(FormattedString[].class, null, tempAttribute.getValue(),
Expand Down Expand Up @@ -105,8 +121,16 @@ protected FormattedString convertToFormattedString(NestedObject aSource, Convers
}

tempBuffer.addMultiple(new FormatTokenElement(FormatTokenType.TAB), tempDepth);
if (tempCurrentPathFailed) {
tempBuffer.add(new FormatTokenElement(FormatTokenType.UNDERLINE_START));
tempBuffer.add(new FormatTokenElement(FormatTokenType.BOLD_START));
}
tempBuffer.add(IntegrityDSLUtil.getIdentifierFromKeyValuePair(tempAttribute) + " = ");
tempBuffer.add(tempConvertedValueStringBuffer);
if (tempCurrentPathFailed) {
tempBuffer.add(new FormatTokenElement(FormatTokenType.BOLD_END));
tempBuffer.add(new FormatTokenElement(FormatTokenType.UNDERLINE_END));
}
tempFirst = false;
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,8 @@ protected void onAnyKindOfSubTestFinish(MethodReference aMethod, SuiteStatementW
tempComparisonResultElement.setAttribute(
RESULT_EXPECTED_VALUE_ATTRIBUTE,
valueConverter.convertValueToFormattedString(
(tempExpectedValue == null ? true : tempExpectedValue), false, null)
(tempExpectedValue == null ? true : tempExpectedValue), false,
new ConversionContext().withComparisonResult(tempEntry.getValue().getResult()))
.toFormattedString());
if (tempEntry.getValue().getActualValue() != null) {
tempComparisonResultElement.setAttribute(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<integrity name="Integrity JUnit Testing" timestamp="18.07.14 09:47" isotimestamp="2014-07-18T09:47:15" duration="47.650">
<integrity name="Integrity JUnit Testing" timestamp="18.07.14 10:15" isotimestamp="2014-07-18T10:15:06" duration="20.014">
<variables />
<suite id="0" name="integrity.basic.beans.primitiveBeanTest" timestamp="18.07.14 09:47:15.0126">
<suite id="0" name="integrity.basic.beans.primitiveBeanTest" timestamp="18.07.14 10:15:06.0783">
<setup />
<variables />
<statements>
<comment id="1" line="7">this should succeed</comment>
<test id="2" line="8" name="alterPrimitiveBean" description="takes the bean {primitiveBoolean = true, primitiveByte = 42, primitiveChar = A, primitiveDouble = 1.5, primitiveFloat = 4.5, primitiveInt = 100000000, primitiveLong = 999999999, primitiveShort = 2000}, alters it a little bit and returns it" fixture="de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#alterPrimitiveBean" timestamp="18.07.14 09:47:15.0126">
<results duration="3.957" successCount="1" failureCount="0" exceptionCount="0">
<result duration="3.957" description="takes the bean {primitiveBoolean = true, primitiveByte = 42, primitiveChar = A, primitiveDouble = 1.5, primitiveFloat = 4.5, primitiveInt = 100000000, primitiveLong = 999999999, primitiveShort = 2000}, alters it a little bit and returns it" type="success">
<test id="2" line="8" name="alterPrimitiveBean" description="takes the bean {primitiveBoolean = true, primitiveByte = 42, primitiveChar = A, primitiveDouble = 1.5, primitiveFloat = 4.5, primitiveInt = 100000000, primitiveLong = 999999999, primitiveShort = 2000}, alters it a little bit and returns it" fixture="de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#alterPrimitiveBean" timestamp="18.07.14 10:15:06.0783">
<results duration="1.508" successCount="1" failureCount="0" exceptionCount="0">
<result duration="1.508" description="takes the bean {primitiveBoolean = true, primitiveByte = 42, primitiveChar = A, primitiveDouble = 1.5, primitiveFloat = 4.5, primitiveInt = 100000000, primitiveLong = 999999999, primitiveShort = 2000}, alters it a little bit and returns it" type="success">
<parameters>
<parameter name="bean" value="[FORMATTED]{[NL][T]primitiveBoolean = true[NL|, ][T]primitiveByte = 42[NL|, ][T]primitiveChar = A[NL|, ][T]primitiveDouble = 1.5[NL|, ][T]primitiveFloat = 4.5[NL|, ][T]primitiveInt = 100000000[NL|, ][T]primitiveLong = 999999999[NL|, ][T]primitiveShort = 2000[NL]}" />
</parameters>
Expand All @@ -19,21 +19,21 @@
</results>
</test>
<comment id="3" line="28">this should fail</comment>
<test id="4" line="29" name="alterPrimitiveBean" description="takes the bean {primitiveBoolean = true, primitiveByte = 42, primitiveChar = A, primitiveDouble = 1.5, primitiveFloat = 4.5, primitiveInt = 100000000, primitiveLong = 999999999, primitiveShort = 2000}, alters it a little bit and returns it" fixture="de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#alterPrimitiveBean" timestamp="18.07.14 09:47:15.0158">
<results duration="1.278" successCount="0" failureCount="1" exceptionCount="0">
<result duration="1.278" description="takes the bean {primitiveBoolean = true, primitiveByte = 42, primitiveChar = A, primitiveDouble = 1.5, primitiveFloat = 4.5, primitiveInt = 100000000, primitiveLong = 999999999, primitiveShort = 2000}, alters it a little bit and returns it" type="failure">
<test id="4" line="29" name="alterPrimitiveBean" description="takes the bean {primitiveBoolean = true, primitiveByte = 42, primitiveChar = A, primitiveDouble = 1.5, primitiveFloat = 4.5, primitiveInt = 100000000, primitiveLong = 999999999, primitiveShort = 2000}, alters it a little bit and returns it" fixture="de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#alterPrimitiveBean" timestamp="18.07.14 10:15:06.0798">
<results duration="0.692" successCount="0" failureCount="1" exceptionCount="0">
<result duration="0.692" description="takes the bean {primitiveBoolean = true, primitiveByte = 42, primitiveChar = A, primitiveDouble = 1.5, primitiveFloat = 4.5, primitiveInt = 100000000, primitiveLong = 999999999, primitiveShort = 2000}, alters it a little bit and returns it" type="failure">
<parameters>
<parameter name="bean" value="[FORMATTED]{[NL][T]primitiveBoolean = true[NL|, ][T]primitiveByte = 42[NL|, ][T]primitiveChar = A[NL|, ][T]primitiveDouble = 1.5[NL|, ][T]primitiveFloat = 4.5[NL|, ][T]primitiveInt = 100000000[NL|, ][T]primitiveLong = 999999999[NL|, ][T]primitiveShort = 2000[NL]}" />
</parameters>
<comparisons>
<comparison expectedValue="[FORMATTED]{[NL][T]primitiveBoolean = false[NL|, ][T]primitiveByte = 43[NL|, ][T]primitiveChar = B[NL|, ][T]primitiveDouble = 2.5[NL|, ][T]primitiveFloat = 5.5[NL|, ][T]primitiveInt = 100000002[NL|, ][T]primitiveLong = 1000000000[NL|, ][T]primitiveShort = 2001[NL]}" value="[FORMATTED]{[NL][T]primitiveBoolean = false[NL|, ][T]primitiveByte = 43[NL|, ][T]primitiveChar = B[NL|, ][T]primitiveDouble = 2.5[NL|, ][T]primitiveFloat = 5.5[NL|, ][T][UL][B]primitiveInt = 100000001[/B][/UL][NL|, ][T]primitiveLong = 1000000000[NL|, ][T]primitiveShort = 2001[NL]}" type="failure" />
<comparison expectedValue="[FORMATTED]{[NL][T]primitiveBoolean = false[NL|, ][T]primitiveByte = 43[NL|, ][T]primitiveChar = B[NL|, ][T]primitiveDouble = 2.5[NL|, ][T]primitiveFloat = 5.5[NL|, ][T][UL][B]primitiveInt = 100000002[/B][/UL][NL|, ][T]primitiveLong = 1000000000[NL|, ][T]primitiveShort = 2001[NL]}" value="[FORMATTED]{[NL][T]primitiveBoolean = false[NL|, ][T]primitiveByte = 43[NL|, ][T]primitiveChar = B[NL|, ][T]primitiveDouble = 2.5[NL|, ][T]primitiveFloat = 5.5[NL|, ][T][UL][B]primitiveInt = 100000001[/B][/UL][NL|, ][T]primitiveLong = 1000000000[NL|, ][T]primitiveShort = 2001[NL]}" type="failure" />
</comparisons>
</result>
</results>
</test>
</statements>
<teardown />
<result duration="42.352" successCount="1" failureCount="1" exceptionCount="0" testExceptionCount="0" callExceptionCount="0" />
<result duration="19.481" successCount="1" failureCount="1" exceptionCount="0" testExceptionCount="0" callExceptionCount="0" />
</suite>
</integrity>

Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<integrity name="Integrity JUnit Testing" timestamp="18.07.14 09:51" isotimestamp="2014-07-18T09:51:13" duration="50.486">
<integrity name="Integrity JUnit Testing" timestamp="18.07.14 10:15" isotimestamp="2014-07-18T10:15:08" duration="13.958">
<variables />
<suite id="0" name="integrity.basic.nestedobjects.nestedobjects" timestamp="18.07.14 09:51:13.0655">
<suite id="0" name="integrity.basic.nestedobjects.nestedobjects" timestamp="18.07.14 10:15:08.0753">
<setup />
<variables>
<variable name="stringVar" value="A String in a Variable" />
<variable name="obj1" value="[FORMATTED]{[NL][T]key1 = The first value[NL|, ][T]key2 = 31337, 31338[NL|, ][T]key3 = 123.456[NL|, ][T]key4 = true[NL|, ][T]key5 = null[NL|, ][T]key6 = {[NL][T][T]subkey1 = A String in a Variable[NL|, ][T][T]subkey2 = {[NL][T][T][T]subsubkey1 = 10000[NL][T][T]}[NL][T]}[NL]}" />
<variable name="obj2" />
</variables>
<statements>
<call id="1" line="26" name="echoMap" description="Echo the map '{key1 = The first value, key2 = 31337, 31338, key3 = 123.456, key4 = true, key5 = null, key6 = {subkey1 = A String in a Variable, subkey2 = {subsubkey1 = 10000}}}'" fixture="de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoMap" timestamp="18.07.14 09:51:13.0655">
<call id="1" line="26" name="echoMap" description="Echo the map '{key1 = The first value, key2 = 31337, 31338, key3 = 123.456, key4 = true, key5 = null, key6 = {subkey1 = A String in a Variable, subkey2 = {subsubkey1 = 10000}}}'" fixture="de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoMap" timestamp="18.07.14 10:15:08.0769">
<parameters>
<parameter name="map" value="[FORMATTED]{[NL][T]key1 = The first value[NL|, ][T]key2 = 31337, 31338[NL|, ][T]key3 = 123.456[NL|, ][T]key4 = true[NL|, ][T]key5 = null[NL|, ][T]key6 = {[NL][T][T]subkey1 = A String in a Variable[NL|, ][T][T]subkey2 = {[NL][T][T][T]subsubkey1 = 10000[NL][T][T]}[NL][T]}[NL]}" />
</parameters>
<result duration="2.531" type="success">
<result duration="0.305" type="success">
<variableUpdate name="obj2" value="[FORMATTED]{[NL][T]key1 = The first value[NL|, ][T]key2 = 31337, 31338[NL|, ][T]key3 = 123.456[NL|, ][T]key4 = true[NL|, ][T]key5 = null[NL|, ][T]key6 = {[NL][T][T]subkey1 = A String in a Variable[NL|, ][T][T]subkey2 = {[NL][T][T][T]subsubkey1 = 10000[NL][T][T]}[NL][T]}[NL]}" />
</result>
</call>
<test id="2" line="40" name="echoMapTest" description="Echo the map '{key1 = The first value, key2 = 31337, 31338, key3 = 123.456, key4 = true, key5 = null, key6 = {subkey1 = A String in a Variable, subkey2 = {subsubkey1 = 10000}}}'" fixture="de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoMap" timestamp="18.07.14 09:51:13.0670">
<results duration="0.981" successCount="1" failureCount="0" exceptionCount="0">
<result duration="0.981" description="Echo the map '{key1 = The first value, key2 = 31337, 31338, key3 = 123.456, key4 = true, key5 = null, key6 = {subkey1 = A String in a Variable, subkey2 = {subsubkey1 = 10000}}}'" type="success">
<test id="2" line="40" name="echoMapTest" description="Echo the map '{key1 = The first value, key2 = 31337, 31338, key3 = 123.456, key4 = true, key5 = null, key6 = {subkey1 = A String in a Variable, subkey2 = {subsubkey1 = 10000}}}'" fixture="de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoMap" timestamp="18.07.14 10:15:08.0769">
<results duration="0.200" successCount="1" failureCount="0" exceptionCount="0">
<result duration="0.200" description="Echo the map '{key1 = The first value, key2 = 31337, 31338, key3 = 123.456, key4 = true, key5 = null, key6 = {subkey1 = A String in a Variable, subkey2 = {subsubkey1 = 10000}}}'" type="success">
<parameters>
<parameter name="map" value="[FORMATTED]{[NL][T]key1 = The first value[NL|, ][T]key2 = 31337, 31338[NL|, ][T]key3 = 123.456[NL|, ][T]key4 = true[NL|, ][T]key5 = null[NL|, ][T]key6 = {[NL][T][T]subkey1 = A String in a Variable[NL|, ][T][T]subkey2 = {[NL][T][T][T]subsubkey1 = 10000[NL][T][T]}[NL][T]}[NL]}" />
</parameters>
Expand All @@ -29,21 +29,21 @@
</result>
</results>
</test>
<test id="3" line="42" name="echoMapTest" description="Echo the map '{key1 = The first value, key2 = 31337, 31338, key3 = 123.456, key4 = true, key5 = null, key6 = {subkey1 = A String in a Variable, subkey2 = {subsubkey1 = 10000}}}'" fixture="de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoMap" timestamp="18.07.14 09:51:13.0686">
<results duration="0.664" successCount="0" failureCount="1" exceptionCount="0">
<result duration="0.664" description="Echo the map '{key1 = The first value, key2 = 31337, 31338, key3 = 123.456, key4 = true, key5 = null, key6 = {subkey1 = A String in a Variable, subkey2 = {subsubkey1 = 10000}}}'" type="failure">
<test id="3" line="42" name="echoMapTest" description="Echo the map '{key1 = The first value, key2 = 31337, 31338, key3 = 123.456, key4 = true, key5 = null, key6 = {subkey1 = A String in a Variable, subkey2 = {subsubkey1 = 10000}}}'" fixture="de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoMap" timestamp="18.07.14 10:15:08.0769">
<results duration="0.141" successCount="0" failureCount="1" exceptionCount="0">
<result duration="0.141" description="Echo the map '{key1 = The first value, key2 = 31337, 31338, key3 = 123.456, key4 = true, key5 = null, key6 = {subkey1 = A String in a Variable, subkey2 = {subsubkey1 = 10000}}}'" type="failure">
<parameters>
<parameter name="map" value="[FORMATTED]{[NL][T]key1 = The first value[NL|, ][T]key2 = 31337, 31338[NL|, ][T]key3 = 123.456[NL|, ][T]key4 = true[NL|, ][T]key5 = null[NL|, ][T]key6 = {[NL][T][T]subkey1 = A String in a Variable[NL|, ][T][T]subkey2 = {[NL][T][T][T]subsubkey1 = 10000[NL][T][T]}[NL][T]}[NL]}" />
</parameters>
<comparisons>
<comparison expectedValue="[FORMATTED]{[NL][T]key1 = The first value[NL|, ][T]key2 = 31337, 31339[NL|, ][T]key3 = 123.456[NL|, ][T]key4 = true[NL|, ][T]key5 = null[NL|, ][T]key6 = {[NL][T][T]subkey1 = A String in a Variable[NL|, ][T][T]subkey2 = {[NL][T][T][T]subsubkey1 = 10000[NL][T][T]}[NL][T]}[NL]}" value="[FORMATTED]{[NL][T]key1 = The first value[NL|, ][T][UL][B]key2 = 31337, 31338[/B][/UL][NL|, ][T]key3 = 123.456[NL|, ][T]key4 = true[NL|, ][T]key5 = null[NL|, ][T]key6 = {[NL][T][T]subkey1 = A String in a Variable[NL|, ][T][T]subkey2 = {[NL][T][T][T]subsubkey1 = 10000[NL][T][T]}[NL][T]}[NL]}" type="failure" />
<comparison expectedValue="[FORMATTED]{[NL][T]key1 = The first value[NL|, ][T][UL][B]key2 = 31337, 31339[/B][/UL][NL|, ][T]key3 = 123.456[NL|, ][T]key4 = true[NL|, ][T]key5 = null[NL|, ][T]key6 = {[NL][T][T]subkey1 = A String in a Variable[NL|, ][T][T]subkey2 = {[NL][T][T][T]subsubkey1 = 10000[NL][T][T]}[NL][T]}[NL]}" value="[FORMATTED]{[NL][T]key1 = The first value[NL|, ][T][UL][B]key2 = 31337, 31338[/B][/UL][NL|, ][T]key3 = 123.456[NL|, ][T]key4 = true[NL|, ][T]key5 = null[NL|, ][T]key6 = {[NL][T][T]subkey1 = A String in a Variable[NL|, ][T][T]subkey2 = {[NL][T][T][T]subsubkey1 = 10000[NL][T][T]}[NL][T]}[NL]}" type="failure" />
</comparisons>
</result>
</results>
</test>
</statements>
<teardown />
<result duration="45.197" successCount="1" failureCount="1" exceptionCount="0" testExceptionCount="0" callExceptionCount="0" />
<result duration="13.216" successCount="1" failureCount="1" exceptionCount="0" testExceptionCount="0" callExceptionCount="0" />
</suite>
</integrity>

Loading

0 comments on commit 8127e84

Please sign in to comment.