Skip to content

Commit

Permalink
Merge branch 'v0.15.x_bugfix' into v0.15.x
Browse files Browse the repository at this point in the history
  • Loading branch information
S1artie committed Jun 20, 2016
2 parents 485cffb + 645be13 commit b18bb61
Show file tree
Hide file tree
Showing 9 changed files with 1,101 additions and 877 deletions.
1,436 changes: 729 additions & 707 deletions de.gebit.integrity.dsl/src/de/gebit/integrity/utils/IntegrityDSLUtil.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,14 @@ protected SuiteSummaryResult callSuiteSingle(Suite aSuiteCall) {
}

long tempSuiteDuration = System.nanoTime();
Map<SuiteStatementWithResult, List<? extends Result>> tempResults = executeSuite(aSuiteCall.getDefinition());
Map<SuiteStatementWithResult, List<? extends Result>> tempResults;
// It is possible that a setup suite caused an abortion. If that's the case, use an empty suite result.
// Fixes issue #112.
if (!checkForAbortion()) {
tempResults = executeSuite(aSuiteCall.getDefinition());
} else {
tempResults = new HashMap<>();
}
tempSuiteDuration = System.nanoTime() - tempSuiteDuration;

// Fetch all output values into their respective local target variables
Expand Down Expand Up @@ -866,12 +873,12 @@ protected SuiteSummaryResult callSuiteSingle(Suite aSuiteCall) {
tempResult = new SuiteSummaryResult(tempForkResultSummary.getSuccessCount(),
tempForkResultSummary.getFailureCount(), tempForkResultSummary.getTestExceptionCount(),
tempForkResultSummary.getCallExceptionCount(), tempSuiteDuration);
} else {
if (tempFork != null && tempFork.hasAborted()) {
// If this happens, an abortion has happened on the fork due to an AbortExecutionException.
// TODO make this nicer, it's kind of ugly to create a fake object with null values
abortExecutionCause = new AbortExecutionCauseWrapper(null, null);
}
}

if (tempFork != null && tempFork.hasAborted()) {
// If this happens, an abortion has happened on the fork due to an AbortExecutionException.
// TODO make this nicer, it's kind of ugly to create a fake object with null values
abortExecutionCause = new AbortExecutionCauseWrapper(null, null);
}

// and afterwards we'll switch back to real test mode
Expand Down Expand Up @@ -930,15 +937,21 @@ protected List<SuiteDefinition> executeSetupSuites(SuiteDefinition aSuite,
: new SuiteResult(tempSuiteResults, null, null, System.nanoTime() - tempStart);
aSetupResultMap.put(tempSetupSuite, tempSetupResult);

tempSetupsAlreadyRun.add(tempSetupSuite);
tempSetupSuitesExecuted.add(tempSetupSuite);
if (!checkForAbortion()) {
tempSetupsAlreadyRun.add(tempSetupSuite);
tempSetupSuitesExecuted.add(tempSetupSuite);
}

if (currentCallback != null) {
currentCallback.onCallbackProcessingStart();
currentCallback.onSetupFinish(tempSetupSuite, tempSetupResult);
currentCallback.onCallbackProcessingEnd();
}
}

if (checkForAbortion()) {
break;
}
}

return tempSetupSuitesExecuted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
import de.gebit.integrity.dsl.ValueOrEnumValueOrOperation;
import de.gebit.integrity.dsl.ValueOrEnumValueOrOperationCollection;
import de.gebit.integrity.dsl.Variable;
import de.gebit.integrity.dsl.VariableOrConstantEntity;
import de.gebit.integrity.fixtures.FixtureWrapper;
import de.gebit.integrity.operations.UnexecutableException;
import de.gebit.integrity.parameter.conversion.UnresolvableVariableHandling;
import de.gebit.integrity.parameter.conversion.ValueConverter;
import de.gebit.integrity.parameter.resolving.ParameterResolver;
import de.gebit.integrity.utils.DateUtil;
import de.gebit.integrity.utils.IntegrityDSLUtil;
import de.gebit.integrity.utils.ParameterUtil.UnresolvableVariableException;

/**
Expand All @@ -59,17 +61,31 @@ public class DefaultResultComparator implements ResultComparator {
protected ParameterResolver parameterResolver;

@Override
public ComparisonResult compareResult(Object aFixtureResult,
ValueOrEnumValueOrOperationCollection anExpectedResult, FixtureWrapper<?> aFixtureInstance,
MethodReference aFixtureMethod, String aPropertyName) throws ClassNotFoundException, UnexecutableException,
InstantiationException {
public ComparisonResult compareResult(Object aFixtureResult, ValueOrEnumValueOrOperationCollection anExpectedResult,
FixtureWrapper<?> aFixtureInstance, MethodReference aFixtureMethod, String aPropertyName)
throws ClassNotFoundException, UnexecutableException, InstantiationException {
if (anExpectedResult != null) {
if (aFixtureResult == null) {
if (anExpectedResult.getMoreValues().size() > 0) {
// if there's more than one value expected, this can never equal a single null value
return SimpleComparisonResult.NOT_EQUAL;
} else {
return SimpleComparisonResult.valueOf(anExpectedResult.getValue() instanceof NullValue);
boolean tempIsNull = false;
// This is only true if the expected result is also null. That could be directly...
if (anExpectedResult.getValue() instanceof NullValue) {
tempIsNull = true;
} else {
// ...or indirectly by the value being a variable/constant that resolves to a null value
VariableOrConstantEntity tempEntity = IntegrityDSLUtil
.extractVariableOrConstantEntity(anExpectedResult.getValue());
if (tempEntity != null) {
Object tempResult = parameterResolver.resolveParameterValue(anExpectedResult,
UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE);
tempIsNull = (tempResult == null || (tempResult instanceof NullValue));
}
}

return SimpleComparisonResult.valueOf(tempIsNull);
}
} else {
if (aFixtureInstance.isCustomComparatorFixture()) {
Expand All @@ -82,8 +98,8 @@ public ComparisonResult compareResult(Object aFixtureResult,
tempConversionTargetType = aFixtureInstance.determineCustomConversionTargetType(aFixtureResult,
tempMethodName, aPropertyName);
} else {
tempConversionTargetType = aFixtureResult.getClass().isArray() ? aFixtureResult.getClass()
.getComponentType() : aFixtureResult.getClass();
tempConversionTargetType = aFixtureResult.getClass().isArray()
? aFixtureResult.getClass().getComponentType() : aFixtureResult.getClass();
}

if (anExpectedResult.getMoreValues().size() > 0) {
Expand All @@ -94,8 +110,8 @@ public ComparisonResult compareResult(Object aFixtureResult,
tempConvertedResult = Array.newInstance(tempArrayType,
anExpectedResult.getMoreValues().size() + 1);
for (int i = 0; i < Array.getLength(tempConvertedResult); i++) {
ValueOrEnumValueOrOperation tempSingleExpectedResult = (i == 0 ? anExpectedResult
.getValue() : anExpectedResult.getMoreValues().get(i - 1));
ValueOrEnumValueOrOperation tempSingleExpectedResult = (i == 0 ? anExpectedResult.getValue()
: anExpectedResult.getMoreValues().get(i - 1));
Array.set(tempConvertedResult, i, valueConverter.convertValue(tempConversionTargetType,
tempSingleExpectedResult, null));
}
Expand All @@ -110,15 +126,15 @@ public ComparisonResult compareResult(Object aFixtureResult,
// Standard comparation compares each value for itself in case of arrays
if (anExpectedResult.getMoreValues().size() > 0) {
// multiple result values were given -> fixture result must be an array of same size
if (!(aFixtureResult.getClass().isArray() && Array.getLength(aFixtureResult) == anExpectedResult
.getMoreValues().size() + 1)) {
if (!(aFixtureResult.getClass().isArray()
&& Array.getLength(aFixtureResult) == anExpectedResult.getMoreValues().size() + 1)) {
return SimpleComparisonResult.NOT_EQUAL;
}
// now compare all values
for (int i = 0; i < Array.getLength(aFixtureResult); i++) {
Object tempSingleFixtureResult = Array.get(aFixtureResult, i);
ValueOrEnumValueOrOperation tempSingleExpectedResult = (i == 0 ? anExpectedResult
.getValue() : anExpectedResult.getMoreValues().get(i - 1));
ValueOrEnumValueOrOperation tempSingleExpectedResult = (i == 0 ? anExpectedResult.getValue()
: anExpectedResult.getMoreValues().get(i - 1));
if (tempSingleFixtureResult == null) {
// The fixture returned a null, we need to expect a null
if (!(tempSingleExpectedResult instanceof NullValue)) {
Expand All @@ -142,13 +158,13 @@ public ComparisonResult compareResult(Object aFixtureResult,
if (tempSingleFixtureResult instanceof byte[]) {
byte[] tempConvertedExpectedResult = (byte[]) valueConverter.convertValue(byte[].class,
tempSingleExpectedResult, null);
return SimpleComparisonResult.valueOf(Arrays.equals((byte[]) tempSingleFixtureResult,
tempConvertedExpectedResult));
return SimpleComparisonResult.valueOf(
Arrays.equals((byte[]) tempSingleFixtureResult, tempConvertedExpectedResult));
} else if (tempSingleFixtureResult instanceof Byte[]) {
Byte[] tempConvertedExpectedResult = (Byte[]) valueConverter.convertValue(Byte[].class,
tempSingleExpectedResult, null);
return SimpleComparisonResult.valueOf(Arrays.equals((Byte[]) tempSingleFixtureResult,
tempConvertedExpectedResult));
return SimpleComparisonResult.valueOf(
Arrays.equals((Byte[]) tempSingleFixtureResult, tempConvertedExpectedResult));
}

// The fixture might still have returned an array.
Expand Down Expand Up @@ -188,8 +204,8 @@ public ComparisonResult compareResult(Object aFixtureResult,
}
} else {
if (aFixtureInstance.isCustomComparatorFixture()) {
return aFixtureInstance.performCustomComparation(null, aFixtureResult, aFixtureMethod.getMethod()
.getSimpleName(), aPropertyName);
return aFixtureInstance.performCustomComparation(null, aFixtureResult,
aFixtureMethod.getMethod().getSimpleName(), aPropertyName);
} else {
if (aFixtureResult instanceof Boolean) {
return SimpleComparisonResult.valueOf((Boolean) aFixtureResult);
Expand Down Expand Up @@ -283,11 +299,9 @@ protected ComparisonResult convertAndPerformEqualityCheck(Object aSingleFixtureR
protected ComparisonResult performEqualityCheck(Object aConvertedResult, Object aConvertedExpectedResult,
ValueOrEnumValueOrOperation aRawExpectedResult) {
if (aConvertedResult == null) {
return SimpleComparisonResult
.valueOf(aConvertedExpectedResult == null
|| (aConvertedExpectedResult.getClass().isArray()
&& Array.getLength(aConvertedExpectedResult) == 1 && Array.get(
aConvertedExpectedResult, 0) == null));
return SimpleComparisonResult.valueOf(aConvertedExpectedResult == null
|| (aConvertedExpectedResult.getClass().isArray() && Array.getLength(aConvertedExpectedResult) == 1
&& Array.get(aConvertedExpectedResult, 0) == null));
} else {
if (aConvertedResult instanceof Date && aConvertedExpectedResult instanceof Date) {
return performEqualityCheckForDates((Date) aConvertedResult, (Date) aConvertedExpectedResult,
Expand Down Expand Up @@ -375,20 +389,19 @@ protected MapComparisonResult performEqualityCheckForMaps(Map<?, ?> aResult, Map
// since even though both outer values are maps, their inner values have not been necessarily converted
// to the same types
try {
tempConvertedReferenceValue = (tempActualValue != null) ? valueConverter.convertValue(
tempActualValue.getClass(), tempReferenceValue, null) : tempReferenceValue;
tempConvertedReferenceValue = (tempActualValue != null)
? valueConverter.convertValue(tempActualValue.getClass(), tempReferenceValue, null)
: tempReferenceValue;
} catch (UnresolvableVariableException exc) {
exc.printStackTrace();
} catch (UnexecutableException exc) {
exc.printStackTrace();
}
}

ComparisonResult tempInnerResult = performEqualityCheck(
tempActualValue,
tempConvertedReferenceValue,
(tempReferenceValue instanceof ValueOrEnumValueOrOperation) ? (ValueOrEnumValueOrOperation) tempReferenceValue
: null);
ComparisonResult tempInnerResult = performEqualityCheck(tempActualValue, tempConvertedReferenceValue,
(tempReferenceValue instanceof ValueOrEnumValueOrOperation)
? (ValueOrEnumValueOrOperation) tempReferenceValue : null);

if (!tempInnerResult.isSuccessful()) {
tempSuccess = false;
Expand Down Expand Up @@ -423,12 +436,12 @@ protected ComparisonResult performEqualityCheckForDates(Date aResult, Date anExp
Object aRawExpectedResult) {
if (aRawExpectedResult instanceof DateValue) {
// compare only the date part
return SimpleComparisonResult.valueOf(DateUtil.stripTimeFromDate((Date) anExpectedResult).equals(
DateUtil.stripTimeFromDate((Date) aResult)));
return SimpleComparisonResult.valueOf(DateUtil.stripTimeFromDate((Date) anExpectedResult)
.equals(DateUtil.stripTimeFromDate((Date) aResult)));
} else if (aRawExpectedResult instanceof TimeValue) {
// compare only the time part
return SimpleComparisonResult.valueOf(DateUtil.stripDateFromTime((Date) anExpectedResult).equals(
DateUtil.stripDateFromTime((Date) aResult)));
return SimpleComparisonResult.valueOf(DateUtil.stripDateFromTime((Date) anExpectedResult)
.equals(DateUtil.stripDateFromTime((Date) aResult)));
} else {
// compare both parts
return SimpleComparisonResult.valueOf(anExpectedResult.equals(aResult));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,36 @@ packagedef integrity.basic.exceptions.abortExceptions with
call integrity.fixtures.basic.noop.throwAbortException message: "This is an abort exception in a call"
call integrity.fixtures.basic.noop.noOp // this should not be executed anymore
suiteend


suitedef abortDependentSuite with
suite abortDependentSuiteDependingSuite
suiteend

suitedef abortDependentSuiteDependingSuite requires abortDependentSuiteRequiredSuite1 abortDependentSuiteRequiredSuite1 with
call integrity.fixtures.basic.noop.noOp // this should not be executed anymore
suiteend

suitedef abortDependentSuiteRequiredSuite1 concludedby abortDependentSuiteConcludedBySuite2 with
call integrity.fixtures.basic.noop.noOp
call integrity.fixtures.basic.noop.throwAbortException message: "This is an abort exception in a call"
call integrity.fixtures.basic.noop.noOp // this should not be executed anymore
suiteend

suitedef abortDependentSuiteRequiredSuite2 concludedby abortDependentSuiteConcludedBySuite2 with
call integrity.fixtures.basic.noop.noOp // this should not be executed at all, since suite1 aborted everything
suiteend

suitedef abortDependentSuiteConcludedBySuite1 with
call integrity.fixtures.basic.noop.noOp // this should not be executed at all, since conclusion suites are currently not executed when aborts happened
suiteend

suitedef abortDependentSuiteConcludedBySuite2 with
call integrity.fixtures.basic.noop.noOp // this should not be executed at all, since conclusion suites are currently not executed when aborts happened
suiteend





packageend
Loading

0 comments on commit b18bb61

Please sign in to comment.