Skip to content

Commit

Permalink
Merge branch 'v0.12.x_bugfix' into v0.12.x
Browse files Browse the repository at this point in the history
  • Loading branch information
S1artie committed Nov 23, 2013
2 parents 43b36fa + e98c021 commit 16d1361
Show file tree
Hide file tree
Showing 16 changed files with 269 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ packagedef mypackage with
variable var

suitedef asuite with
test echo echo: {
abc: 123
"123": "abc"
} = {
abc: 123
"123": "abc"
}
test echo echo: 01:00:00-0100

test echo echo: 2013-06-24T10:00:00Z
suiteend
packageend
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package de.gebit.integrity.parameter.conversion;

/**
* This instance is used for variable resolving in case of
* {@link UnresolvableVariableHandling#RESOLVE_TO_UNRESOLVABLE_OBJECT}.
*
* @author Rene Schneider - initial API and implementation
*
*/
public final class UnresolvableVariable {

/**
* Singleton instance.
*/
private static final UnresolvableVariable INSTANCE = new UnresolvableVariable();

private UnresolvableVariable() {
// private constructor
}

public static UnresolvableVariable getInstance() {
return INSTANCE;
}

@Override
public String toString() {
return "???";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public enum UnresolvableVariableHandling {
*/
RESOLVE_TO_NULL_VALUE,

/**
* Resolve to the string 'null'.
*/
RESOLVE_TO_NULL_STRING,

/**
* Resolve to a string with the name of the variable.
*/
Expand All @@ -38,7 +33,7 @@ public enum UnresolvableVariableHandling {
/**
* Resolve to the string '???'.
*/
RESOLVE_TO_QUESTIONMARK_STRING,
RESOLVE_TO_UNRESOLVABLE_OBJECT,

/**
* Keep the variable reference as-is.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import de.gebit.integrity.operations.UnexecutableException;
import de.gebit.integrity.operations.custom.CustomOperationWrapper;
import de.gebit.integrity.operations.standard.StandardOperationProcessor;
import de.gebit.integrity.parameter.conversion.UnresolvableVariable;
import de.gebit.integrity.parameter.conversion.UnresolvableVariableHandling;
import de.gebit.integrity.parameter.variables.VariableManager;
import de.gebit.integrity.utils.IntegrityDSLUtil;
Expand Down Expand Up @@ -184,10 +185,8 @@ public Object resolveSingleParameterValue(ValueOrEnumValueOrOperation aValue,
return null;
case RESOLVE_TO_NAME_STRING:
return tempVariable.getName().getName();
case RESOLVE_TO_NULL_STRING:
return "null";
case RESOLVE_TO_QUESTIONMARK_STRING:
return "???";
case RESOLVE_TO_UNRESOLVABLE_OBJECT:
return UnresolvableVariable.getInstance();
case EXCEPTION:
default:
throw new UnresolvableVariableException("Unresolvable variable " + tempVariable.getName().getName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ private static Calendar parseIsoDateAndTimeString(String aDateString, String aTi
if (!tempTimeValue.contains(".")) {
// inject milliseconds, if none are present but seconds are given
if (tempHasTimezone) {
tempTimeValue = tempTimeValue.substring(0, aTimeString.length() - 4) + ".000"
+ tempTimeValue.substring(aTimeString.length() - 4);
tempTimeValue = tempTimeValue.substring(0, tempTimeValue.length() - 5) + ".000"
+ tempTimeValue.substring(tempTimeValue.length() - 5);
} else {
tempTimeValue += ".000";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ protected SuiteSummaryResult callSuiteSingle(Suite aSuiteCall) {

List<SuiteDefinition> tempSetupSuitesExecuted = executeSetupSuites(aSuiteCall.getDefinition(), tempSetupResults);

// Define variables for all the parameters provided to the suite call
for (SuiteParameter tempParam : aSuiteCall.getParameters()) {
if (tempParam.getValue() instanceof Variable) {
Variable tempVariable = (Variable) tempParam.getValue();
Expand All @@ -707,6 +708,11 @@ protected SuiteSummaryResult callSuiteSingle(Suite aSuiteCall) {
Map<SuiteStatementWithResult, List<? extends Result>> tempResults = executeSuite(aSuiteCall.getDefinition());
tempSuiteDuration = System.nanoTime() - tempSuiteDuration;

// Now unset all the parameter variables' values again (fixes issue #44)
for (SuiteParameter tempParam : aSuiteCall.getParameters()) {
variableManager.unset(tempParam.getName());
}

executeTearDownSuites(tempSetupSuitesExecuted, tempTearDownResults);

SuiteSummaryResult tempResult = (!shouldExecuteFixtures()) ? null : new SuiteResult(tempResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import de.gebit.integrity.dsl.Variable;
import de.gebit.integrity.exceptions.ThisShouldNeverHappenException;
import de.gebit.integrity.operations.UnexecutableException;
import de.gebit.integrity.parameter.conversion.UnresolvableVariable;
import de.gebit.integrity.parameter.conversion.UnresolvableVariableHandling;
import de.gebit.integrity.parameter.conversion.ValueConverter;
import de.gebit.integrity.parameter.resolving.ParameterResolver;
Expand Down Expand Up @@ -48,6 +49,9 @@ public abstract class AbstractTestRunnerCallback extends TestRunnerCallback {
@Inject
protected ParameterResolver parameterResolver;

/**
* The variable manager to use.
*/
@Inject
protected VariableManager variableManager;

Expand Down Expand Up @@ -155,4 +159,20 @@ protected boolean containsNestedObject(Object aValue) {

return false;
}

/**
* Convert a value to a string intended to be included in the textual output. This most importantly converts
* {@link UnresolvableVariable} instances to a "null" string.
*
* @param aValue
* the value to stringify
* @return the string
*/
protected String valueToString(Object aValue) {
if (aValue == null || aValue == UnresolvableVariable.getInstance()) {
return "null";
} else {
return aValue.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import de.gebit.integrity.exceptions.MethodNotFoundException;
import de.gebit.integrity.fixtures.FixtureMethod;
import de.gebit.integrity.operations.UnexecutableException;
import de.gebit.integrity.parameter.conversion.UnresolvableVariable;
import de.gebit.integrity.parameter.conversion.UnresolvableVariableHandling;
import de.gebit.integrity.parameter.conversion.ValueConverter;
import de.gebit.integrity.parameter.resolving.ParameterResolver;
Expand Down Expand Up @@ -224,8 +225,17 @@ protected String replaceConditionalTextBlocks(String anInput, Map<String, Object
String tempBlockText = tempMatcher.group(4);
String tempSuffix = tempMatcher.group(5);

if ((tempInverter.length() == 0 && someParameters.containsKey(tempParameterName) || (tempInverter.length() > 0 && !someParameters
.containsKey(tempParameterName)))) {
// Fix for issue #41: Conditional fixture description parts are not correctly chosen in some situations
boolean tempParameterConsideredPresent = false;
if (someParameters.containsKey(tempParameterName)) {
Object tempParameterValue = someParameters.get(tempParameterName);
tempParameterConsideredPresent = tempParameterValue != null
&& tempParameterValue != UnresolvableVariable.getInstance();
}
boolean tempInversion = (tempInverter.length() > 0);

if ((!tempInversion && tempParameterConsideredPresent)
|| (tempInversion && !tempParameterConsideredPresent)) {
tempString = tempPrefix + tempBlockText + tempSuffix;
} else {
tempString = tempPrefix + tempSuffix;
Expand Down Expand Up @@ -259,10 +269,10 @@ protected String replaceParameters(String anInput, Map<String, Object> someParam
Object tempValueBeforeConversion = someParameters.get(tempMatcher.group(2));
String tempValue = null;
if (tempValueBeforeConversion == null
&& anUnresolvableVariableHandlingPolicy == UnresolvableVariableHandling.RESOLVE_TO_QUESTIONMARK_STRING) {
&& anUnresolvableVariableHandlingPolicy == UnresolvableVariableHandling.RESOLVE_TO_UNRESOLVABLE_OBJECT) {
// If the unresolvable variable handling policy requires question marks as a replacement, we'll assume
// that's required for unresolvable parameters as well; this is typically required for tabletests.
tempValue = "???";
tempValue = UnresolvableVariable.getInstance().toString();
} else {
tempValue = valueConverter.convertValueToString(tempValueBeforeConversion, false,
anUnresolvableVariableHandlingPolicy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ public void onTestStart(Test aTest) {
println("Now running test "
+ testCount
+ ": "
+ testFormatter.testToHumanReadableString(aTest,
UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING) + "...");
+ testFormatter
.testToHumanReadableString(aTest, UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE)
+ "...");
} catch (ClassNotFoundException exc) {
exc.printStackTrace();
} catch (UnexecutableException exc) {
Expand Down Expand Up @@ -204,15 +205,15 @@ protected void displayTestSubResult(TestSubResult aSubResult) {
boolean tempExpectedIsNestedObject = containsNestedObject(tempExpectedValue);

print("'"
+ valueConverter.convertValueToString((tempExpectedValue == null ? true
: tempExpectedValue), false,
UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING)
+ valueConverter
.convertValueToString((tempExpectedValue == null ? true : tempExpectedValue),
false, UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE)
+ "' expected"
+ (tempEntry.getKey().equals(ParameterUtil.DEFAULT_PARAMETER_NAME) ? "" : " for '"
+ tempEntry.getKey() + "'")
+ ", but got '"
+ convertResultValueToStringGuarded(tempEntry.getValue().getResult(), aSubResult,
tempExpectedIsNestedObject, UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING)
tempExpectedIsNestedObject, UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE)
+ "'!");
tempHasBegun = true;
}
Expand Down Expand Up @@ -255,7 +256,7 @@ public void onVariableDefinition(VariableEntity aDefinition, SuiteDefinition aSu
+ IntegrityDSLUtil.getQualifiedVariableEntityName(aDefinition, false)
+ (anInitialValue == null ? "" : " with initial value: "
+ valueConverter.convertValueToString(anInitialValue, false,
UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING)));
UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE)));
}

@Override
Expand All @@ -265,7 +266,7 @@ public void onConstantDefinition(ConstantEntity aDefinition, SuiteDefinition aSu
+ IntegrityDSLUtil.getQualifiedVariableEntityName(aDefinition, false)
+ (aValue == null ? "" : " with value: "
+ valueConverter.convertValueToString(aValue, false,
UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING))
UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE))
+ (aParameterizedFlag ? " (parameterized)" : ""));
}

Expand All @@ -276,8 +277,9 @@ public void onCallStart(Call aCall) {
println("Now executing call "
+ callCount
+ ": "
+ testFormatter.callToHumanReadableString(aCall,
UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING) + "...");
+ testFormatter
.callToHumanReadableString(aCall, UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE)
+ "...");
} catch (ClassNotFoundException exc) {
exc.printStackTrace();
} catch (UnexecutableException exc) {
Expand Down Expand Up @@ -335,7 +337,7 @@ public void onTableTestRowStart(TableTest aTableTest, TableTestRow aRow) {
+ tableTestRowCount
+ " ("
+ testFormatter.tableTestRowToHumanReadableString(aTableTest, aRow,
UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING) + ")...");
UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE) + ")...");
} catch (ClassNotFoundException exc) {
exc.printStackTrace();
} catch (UnexecutableException exc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,9 @@ private void onVariableDefinitionInternal(VariableOrConstantEntity aDefinition,
*/
protected UnresolvableVariableHandling determineUnresolvableVariableHandlingPolicy() {
if (isDryRun()) {
return UnresolvableVariableHandling.RESOLVE_TO_QUESTIONMARK_STRING;
return UnresolvableVariableHandling.RESOLVE_TO_UNRESOLVABLE_OBJECT;
} else {
return UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING;
return UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,8 @@ public void onTestStart(Test aTest) {
addLineNumber(tempTestElement, aTest);
tempTestElement.setAttribute(TEST_NAME_ELEMENT, aTest.getDefinition().getName());
try {
tempTestElement
.setAttribute(FIXTURE_DESCRIPTION_ATTRIBUTE, testFormatter.testToHumanReadableString(aTest,
UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING));
tempTestElement.setAttribute(FIXTURE_DESCRIPTION_ATTRIBUTE,
testFormatter.testToHumanReadableString(aTest, UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE));
} catch (ClassNotFoundException exc) {
tempTestElement.setAttribute(FIXTURE_DESCRIPTION_ATTRIBUTE, exc.getMessage());
exc.printStackTrace();
Expand Down Expand Up @@ -827,7 +826,7 @@ public void onTableTestStart(TableTest aTest) {
tempTestElement.setAttribute(TEST_NAME_ELEMENT, aTest.getDefinition().getName());
try {
tempTestElement.setAttribute(FIXTURE_DESCRIPTION_ATTRIBUTE, testFormatter.tableTestToHumanReadableString(
aTest, UnresolvableVariableHandling.RESOLVE_TO_QUESTIONMARK_STRING));
aTest, UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE));
} catch (ClassNotFoundException exc) {
tempTestElement.setAttribute(FIXTURE_DESCRIPTION_ATTRIBUTE, exc.getMessage());
exc.printStackTrace();
Expand Down Expand Up @@ -1100,15 +1099,15 @@ protected void onAnyKindOfSubTestFinish(MethodReference aMethod, SuiteStatementW
tempParameterElement.setAttribute(
PARAMETER_VALUE_ATTRIBUTE,
valueConverter.convertValueToFormattedString(tempEntry.getValue(), false,
UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING).toFormattedString());
UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE).toFormattedString());
tempParameterCollectionElement.addContent(tempParameterElement);
}
tempTestResultElement.addContent(tempParameterCollectionElement);

try {
tempTestResultElement.setAttribute(FIXTURE_DESCRIPTION_ATTRIBUTE, testFormatter
.fixtureMethodToHumanReadableString(aMethod, aStatement, aParameterMap,
UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING));
UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE));
} catch (ClassNotFoundException exc) {
tempTestResultElement.setAttribute(FIXTURE_DESCRIPTION_ATTRIBUTE, exc.getMessage());
exc.printStackTrace();
Expand Down Expand Up @@ -1149,12 +1148,12 @@ protected void onAnyKindOfSubTestFinish(MethodReference aMethod, SuiteStatementW
RESULT_EXPECTED_VALUE_ATTRIBUTE,
valueConverter.convertValueToFormattedString(
(tempExpectedValue == null ? true : tempExpectedValue), false,
UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING).toFormattedString());
UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE).toFormattedString());
if (tempEntry.getValue().getResult() != null) {
tempComparisonResultElement.setAttribute(
RESULT_REAL_VALUE_ATTRIBUTE,
convertResultValueToFormattedStringGuarded(tempEntry.getValue().getResult(), aSubResult,
tempExpectedIsNestedObject, UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING)
tempExpectedIsNestedObject, UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE)
.toFormattedString());
}

Expand Down Expand Up @@ -1187,9 +1186,8 @@ public void onCallStart(Call aCall) {
addLineNumber(tempCallElement, aCall);
tempCallElement.setAttribute(CALL_NAME_ELEMENT, aCall.getDefinition().getName());
try {
tempCallElement
.setAttribute(FIXTURE_DESCRIPTION_ATTRIBUTE, testFormatter.callToHumanReadableString(aCall,
UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING));
tempCallElement.setAttribute(FIXTURE_DESCRIPTION_ATTRIBUTE,
testFormatter.callToHumanReadableString(aCall, UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE));
} catch (ClassNotFoundException exc) {
tempCallElement.setAttribute(FIXTURE_DESCRIPTION_ATTRIBUTE, exc.getMessage());
exc.printStackTrace();
Expand Down Expand Up @@ -1228,7 +1226,7 @@ public void onCallStart(Call aCall) {
tempParameterElement.setAttribute(
PARAMETER_VALUE_ATTRIBUTE,
valueConverter.convertValueToFormattedString(tempParameter.getValue(), false,
UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING).toFormattedString());
UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE).toFormattedString());

tempParameterCollectionElement.addContent(tempParameterElement);
}
Expand Down Expand Up @@ -1287,7 +1285,7 @@ public void onCallFinish(Call aCall, CallResult aResult) {
tempVariableUpdateElement.setAttribute(
VARIABLE_VALUE_ATTRIBUTE,
convertResultValueToFormattedStringGuarded(tempUpdatedVariable.getValue(), aResult, false,
UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING).toFormattedString());
UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE).toFormattedString());
tempCallResultElement.addContent(tempVariableUpdateElement);
}
} else if (aResult instanceof de.gebit.integrity.runner.results.call.ExceptionResult) {
Expand Down Expand Up @@ -1665,7 +1663,7 @@ private void onVariableDefinitionInternal(VariableOrConstantEntity aDefinition,
tempVariableElement.setAttribute(
VARIABLE_VALUE_ATTRIBUTE,
valueConverter.convertValueToFormattedString(anInitialValue, false,
UnresolvableVariableHandling.RESOLVE_TO_NULL_STRING).toFormattedString());
UnresolvableVariableHandling.RESOLVE_TO_NULL_VALUE).toFormattedString());
}

if (!isDryRun()) {
Expand Down
Loading

0 comments on commit 16d1361

Please sign in to comment.