Skip to content

Commit

Permalink
fixes #232: Rename "post-invocation tests" to "finalization tests"
Browse files Browse the repository at this point in the history
  • Loading branch information
S1artie committed Feb 27, 2019
1 parent a1ebfd3 commit 54deda2
Show file tree
Hide file tree
Showing 21 changed files with 356 additions and 386 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import java.util.Date;

import de.gebit.integrity.exceptions.AbortExecutionException;
import de.gebit.integrity.fixtures.FinalizationTestFixture;
import de.gebit.integrity.fixtures.FixtureMethod;
import de.gebit.integrity.fixtures.FixtureParameter;

public class AdditionFixture {
public class AdditionFixture implements FinalizationTestFixture {

public static final String STRING_CONST = "Hello World!";

Expand All @@ -33,6 +34,11 @@ public Integer addition(@FixtureParameter(name = "summand1") Integer aSummand1,
return new Integer(aSummand1 + aSummand2);
}

@Override
public String performFinalizationTest() {
return "blah";
}

/**
* Creates a random number in a given interval.
*
Expand Down
49 changes: 5 additions & 44 deletions de.gebit.integrity.dsl.experimentation/src/folder/simple.integrity
Original file line number Diff line number Diff line change
Expand Up @@ -68,50 +68,11 @@ packagedef mypackage with
*/
suitedef asuite gets testParameter anotherParameter returns aResult with

// Sets date/time on all forks and the master process (= the one that starts all forks) to a specific, frozen date and time 00:00:00
timeset 12.10.2001

// Sets date/time on a specific fork to a specific time, but lets it progress afterwards with 3x normal speed
timeset 10.10.2001 15:30:01 progressing 3x on fork1

// Sets date/time on the master process to a specific ISO-formatted time
timeset 2003-10-16T20:00:00+0200 on master

// Resets date/time on all forks and the master to live system date/time
timeset live

timeset + 12minutes on master


suite bsuite on fork1

timeset + 1h 100ms

timeset - 100ms

timeset 12.10.2001 on fork1

timeset + 20y on fork1

timeset 10.02.2001 on fork1
timeset 10.03.2001 on master

timeset + 1months

constant testConst 1100

variable blah
call echoCall echo: 1000 -> blah

timeset + testConst
timeset - blah
timeset + (testConst - blah)

timeset 10.10.2001 progressing blah

suite csuite on fork1

suite bsuite on fork1
tabletest echo
| echo | = |
| "abc" | "abc" |
| "def" | "def" |
| "ghi" | "ghi"|

suiteend

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@
package de.gebit.integrity.fixtures;

/**
* A post-invocation-test fixture defines a method that is to be invoked AFTER the actual fixture methods had been
* called during a tabletest invocation. This post-invocation test method is expected to return a success or failure
* result, and if it returns a failure, this is logged as a failure for the entire tabletest.
* A finalization test fixture defines a method that is to be invoked AFTER the actual fixture methods had been called
* during a tabletest invocation. This post-invocation test method is expected to return a success or failure result,
* and if it returns a failure, this is logged as a failure for the entire tabletest.
* <p>
* The post-invocation method is useful with tabletests, as it is only called exactly once, after all the method calls
* The finalization test method is useful with tabletests, as it is only called exactly once, after all the method calls
* for the lines of the tabletest were invoked. It is also called on the same fixture class instance that the tabletest
* method calls will be called on, effectively providing a good point of entry to perform some sort of finalization test
* for fixtures that hold internal state. Think of a fixture that loads a number of datasets at first invocation,
* testing them one by one afterwards in a tabletest. A useful post-invocation test would be to check if there are still
* testing them one by one afterwards in a tabletest. A useful finalization test would be to check if there are still
* datasets left unchecked.
* <p>
* For call or test invocations, post invocation test methods are simply ignored. They are only used in conjunction with
* For call or test invocations, finalization test methods are simply ignored. They are only used in conjunction with
* tabletests. For normal test invocations, it is assumed that the test method invocation itself should already lead to
* a final result as to whether the test is considered successful or not.
*
*
* @author Rene Schneider - initial API and implementation
*
*/
public interface PostInvocationTestFixture {
public interface FinalizationTestFixture {

/**
* The post-invocation method will be invoked after fixture methods had been called. It should do any post-checks
* The finalization test method will be invoked after fixture methods had been called. It should do any post-checks
* necessary before the fixture instance is being destroyed, and if it concludes that the entire tabletest should be
* considered a failure, it should return a failure message explaining what is wrong.
* <p>
* The message returned will end up in the test result in a prominent spot, so it should be reasonably concise.
* Longer explanations and possibly data that is useful to diagnose the problem (such as surplus line raw data)
* should be provided as an extended result via an {@link ExtendedResultFixture} method (which will be called after
* the post-invocation test has run).
* the finalization test has run).
*
* @return null if the test is considered successful, an error message if not
*/
String performPostInvocationTest();
String performFinalizationTest();

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public class FixtureWrapper<C extends Object> {
/**
* Fixture instance factories are cached in this map.
*/
private static Map<Class<?>, FixtureInstanceFactory<?>> factoryCache = new HashMap<Class<?>, FixtureInstanceFactory<?>>();
private static Map<Class<?>, FixtureInstanceFactory<?>> factoryCache
= new HashMap<Class<?>, FixtureInstanceFactory<?>>();

/**
* Creates a new instance. This also instantiates the given fixture class!
Expand Down Expand Up @@ -220,12 +221,12 @@ public boolean isResultAwareFixture() {
}

/**
* Checks whether the wrapped fixture is a {@link #isPostInvocationTestFixture()}.
* Checks whether the wrapped fixture is a {@link #isFinalizationTestFixture()}.
*
* @return true if it is
*/
public boolean isPostInvocationTestFixture() {
return (PostInvocationTestFixture.class.isAssignableFrom(fixtureClass));
public boolean isFinalizationTestFixture() {
return (FinalizationTestFixture.class.isAssignableFrom(fixtureClass));
}

/**
Expand Down Expand Up @@ -309,8 +310,8 @@ public Object execute(Map<String, Object> someParameters) throws Throwable {
int tempMethodParamCount = tempMethod.getParameterTypes().length;
Object[] tempParams = new Object[tempMethodParamCount];
for (int i = 0; i < tempMethodParamCount; i++) {
FixtureParameter tempAnnotation = findAnnotation(FixtureParameter.class,
tempMethod.getParameterAnnotations()[i]);
FixtureParameter tempAnnotation
= findAnnotation(FixtureParameter.class, tempMethod.getParameterAnnotations()[i]);

if (tempAnnotation != null && tempAnnotation.name() != null) {
tempParams[i] = someParameters.remove(tempAnnotation.name());
Expand All @@ -323,8 +324,8 @@ public Object execute(Map<String, Object> someParameters) throws Throwable {
try {
return tempMethod.invoke(getFixtureInstance(), tempParams);
} catch (IllegalAccessException exc) {
ModelSourceInformationElement tempModelSourceInfo = modelSourceExplorer
.determineSourceInformation(methodReference);
ModelSourceInformationElement tempModelSourceInfo
= modelSourceExplorer.determineSourceInformation(methodReference);
throw new IllegalArgumentException("Caught exception when trying to invoke fixture method '"
+ tempModelSourceInfo.getSnippet() + "' defined at " + tempModelSourceInfo, exc);
} catch (InvocationTargetException exc) {
Expand Down Expand Up @@ -354,8 +355,8 @@ public void convertParameterValuesToFixtureDefinedTypes(Method aFixtureMethod, M

int tempMethodParamCount = aFixtureMethod.getParameterTypes().length;
for (int i = 0; i < tempMethodParamCount; i++) {
FixtureParameter tempAnnotation = findAnnotation(FixtureParameter.class,
aFixtureMethod.getParameterAnnotations()[i]);
FixtureParameter tempAnnotation
= findAnnotation(FixtureParameter.class, aFixtureMethod.getParameterAnnotations()[i]);
if (tempAnnotation != null && tempAnnotation.name() != null) {
String tempName = tempAnnotation.name();
Object tempValue = aParameterMap.get(tempName);
Expand All @@ -373,8 +374,8 @@ public void convertParameterValuesToFixtureDefinedTypes(Method aFixtureMethod, M
tempConvertedValueArrayType = tempExpectedType.getComponentType();
}

Object tempConvertedValueArray = Array.newInstance(tempConvertedValueArrayType,
((Object[]) tempValue).length);
Object tempConvertedValueArray
= Array.newInstance(tempConvertedValueArrayType, ((Object[]) tempValue).length);
for (int k = 0; k < ((Object[]) tempValue).length; k++) {
Object tempSingleValue = ((Object[]) tempValue)[k];
Object tempSingleConvertedValue = valueConverter
Expand All @@ -386,9 +387,8 @@ public void convertParameterValuesToFixtureDefinedTypes(Method aFixtureMethod, M
} else {
// if the expected type is an array, we don't want to convert to that array, but to the
// component type, of course...
Class<?> tempConversionTargetType = tempExpectedType.isArray()
? tempExpectedType.getComponentType()
: tempExpectedType;
Class<?> tempConversionTargetType
= tempExpectedType.isArray() ? tempExpectedType.getComponentType() : tempExpectedType;

// ...except for byte arrays (issue #66), those must be treated specially!
boolean tempSpecialByteArrayMode = false;
Expand Down Expand Up @@ -463,8 +463,8 @@ protected void performNullCheck(FixtureParameter anAnnotation, Object aValue) {
*/
public List<ExtendedResult> retrieveExtendedResults(FixtureInvocationResult anInvocationResult) {
if (fixtureInstance instanceof ExtendedResultFixture) {
List<ExtendedResult> tempList = ((ExtendedResultFixture) fixtureInstance)
.provideExtendedResults(anInvocationResult);
List<ExtendedResult> tempList
= ((ExtendedResultFixture) fixtureInstance).provideExtendedResults(anInvocationResult);
return (tempList != null && tempList.size() > 0) ? tempList : null;
} else {
return null;
Expand Down Expand Up @@ -555,16 +555,16 @@ protected void announceTestResultsInternal(ValueOrEnumValueOrOperationCollection
}

/**
* Executes the post-invocation test for {@link PostInvocationTestFixture}s.
* Executes the finalization test for {@link FinalizationTestFixture}s.
*
* @return null if successful, an error message otherwise
*/
public String runPostInvocationTest() {
if (isPostInvocationTestFixture()) {
return ((PostInvocationTestFixture) fixtureInstance).performPostInvocationTest();
public String runFinalizationTest() {
if (isFinalizationTestFixture()) {
return ((FinalizationTestFixture) fixtureInstance).performFinalizationTest();
} else {
throw new ThisShouldNeverHappenException(
"Running the post invocation test shouldn't be done if the fixture does not have one!");
"Running the finalization test shouldn't be done if the fixture does not have one!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2187,14 +2187,14 @@ private void updateDetailPanel(SetListEntry anEntry, ILabelProvider aProvider) {
resultExceptionCountLabel.setVisible(true);

Object tempPostInvocationResult = tempResultEntry
.getAttribute(SetListEntryAttributeKeys.POST_INVOCATION_RESULT);
.getAttribute(SetListEntryAttributeKeys.FINALIZATION_TEST_RESULT);
if (tempPostInvocationResult != null) {
if (tempPostInvocationResult.equals(true)) {
// We currently do not display successful post-invocation test results at all
} else if (tempPostInvocationResult instanceof String) {
showSection(postInvocationTestSection);
String tempPostInvocationTrace = (String) tempResultEntry
.getAttribute(SetListEntryAttributeKeys.POST_INVOCATION_EXCEPTION);
.getAttribute(SetListEntryAttributeKeys.FINALIZATION_TEST_EXCEPTION);
if (tempPostInvocationTrace != null) {
postInvocationTestResultBorder.setForeground(resultExceptionColor);
postInvocationTestResultText.setText(tempPostInvocationTrace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ protected SetListEntryResultStates determineEntryResultState(SetListEntry anEntr
}
}
String tempPostInvocationResult = (String) anEntry
.getAttribute(SetListEntryAttributeKeys.POST_INVOCATION_RESULT);
.getAttribute(SetListEntryAttributeKeys.FINALIZATION_TEST_RESULT);
if (tempPostInvocationResult != null) {
if (anEntry.getAttribute(SetListEntryAttributeKeys.POST_INVOCATION_EXCEPTION) != null) {
if (anEntry.getAttribute(SetListEntryAttributeKeys.FINALIZATION_TEST_EXCEPTION) != null) {
tempHasException = true;
} else {
tempHasFailure = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*******************************************************************************/
package de.gebit.integrity.remoting.entities.setlist;

import de.gebit.integrity.fixtures.PostInvocationTestFixture;

/**
* Keys for Set List Entry Attributes.
*
Expand Down Expand Up @@ -120,12 +118,12 @@ public enum SetListEntryAttributeKeys {
/**
* Post invocation result data. See {@link PostInvocationTestFixture} for details.
*/
POST_INVOCATION_RESULT,
FINALIZATION_TEST_RESULT,

/**
* Post invocation exception data. See {@link PostInvocationTestFixture} for details.
*/
POST_INVOCATION_EXCEPTION,
FINALIZATION_TEST_EXCEPTION,

/**
* Whether a test/call was successful.
Expand Down
Loading

0 comments on commit 54deda2

Please sign in to comment.