use of com.sun.tck.lib.tgf.SomethingIsWrong in project jtharness by openjdk.
the class AfterTestCaseActions method process.
/**
* {@inheritDoc}
*/
@Override
public void process(TestCaseContext.TestCaseLifePhase lifePhase, final TestCaseContext context) {
Annotation tcAnnotation = getTheOnlyAnnotationInterestedIn(context);
Annotation tgAnnotation = getTheOnlyTestGroupAnnotationInterestedIn(context);
if (tcAnnotation != null && tgAnnotation != null) {
throw new IllegalArgumentException("Annotation @After is attached " + "to both testgroup class and a testcase \"" + context.getTestCaseName() + "\". This is not allowed");
}
final After after = tcAnnotation != null ? (After) tcAnnotation : (After) tgAnnotation;
String methodName = after.value();
try {
searchAndInvoke(methodName, context.getTestGroupInstance().getClass(), context.getTestGroupInstance(), context.getLog());
} catch (SomethingIsWrong e) {
final String message = e.getMessage();
context.printlnToLog(message);
final String failedTryingToInvoke = MessageFormat.format("Failed trying to invoke @After method \"{0}\"", methodName);
context.setTestCaseInvocationArgValues(null);
context.setOverridingResult(TestResult.failure(failedTryingToInvoke));
}
}
use of com.sun.tck.lib.tgf.SomethingIsWrong in project jtharness by openjdk.
the class DefaultExecutionResult method process.
/**
* {@inheritDoc}
*/
@Override
public void process(TestCaseContext.TestCaseLifePhase lifePhase, TestCaseContext context) {
TestResult result;
Throwable t = AUTD2Utils.unwrapCoreExceptionFromITEs(context);
if (t == null) {
Object testCaseReturnedResult = context.getTestCaseResult().getResult();
if (testCaseReturnedResult != null) {
// setting tight policy for what a testcase method can return by default
// to catch mistakes since a non-void return value is not processed
// anyhow by this processor and would be basically lost
// even if the returned result reflects a failure.
String nonVoidResult = format("Testcase \"{0}\" returned unrecognized value {1}" + ", but it is expected to return void", context.getTestCaseName(), testCaseReturnedResult);
result = TestResult.failure(nonVoidResult);
} else {
result = OK_RESULT;
}
} else {
if (t instanceof ClassCastException || t instanceof IllegalArgumentException) {
// todo share this with exp exceptions processor
result = TestResult.failure(unmatchedArgsExceptionThrown(t.getClass().getSimpleName(), context, t, context.getTestCaseMethod(), context.getTestCaseInvocationArgValues()));
} else if (t instanceof SomethingIsWrong) {
// todo share this with exp exceptions processor
context.printlnToLog(t.getMessage());
result = TestResult.failure(t.getMessage());
} else if (t instanceof NotApplicableException) {
// todo share this with exp exceptions processor
String message = t.getMessage();
context.recordNotApplicable();
result = new InapplicableTestResult("Not applicable." + (message != null ? " Reason: " + message : ""), message);
} else if (t instanceof TestFailedException) {
testFailed(context.getTestCaseNameWithIndex(), t, context);
result = TestResult.failure(t.getMessage());
} else {
String unexpectedThrown = format("Testcase \"{0}\" has thrown an unexpected exception {1}", context.getTestCaseNameWithIndex(), t);
context.getParentContext().printlnToLog(unexpectedThrown);
context.getParentContext().printStackTraceToLog(t);
result = TestResult.failure(unexpectedThrown);
}
}
context.addExecutionResult(context.getTestCaseName(), result);
context.clearTestCaseResult();
}
use of com.sun.tck.lib.tgf.SomethingIsWrong in project jtharness by openjdk.
the class ExceptionsExpected method getExpectedExceptionTypes.
/**
* Returns an array of expected exception types.
*/
protected Class<? extends Throwable>[] getExpectedExceptionTypes(TestCaseContext context) {
Class<? extends Throwable>[] expExTypes = null;
Set<Annotation> annotations = getAnnotationsInterestedIn(context);
for (Annotation annotation : annotations) {
if (ExpectedExceptions.class.equals(annotation.annotationType())) {
ExpectedExceptions exceptions = (ExpectedExceptions) annotation;
expExTypes = exceptions.value();
if (expExTypes.length == 0) {
throw new SomethingIsWrong("@ExpectedExceptions attached to " + context.getTestCaseName() + " contains empty array of classes.");
}
}
}
return expExTypes;
}
use of com.sun.tck.lib.tgf.SomethingIsWrong in project jtharness by openjdk.
the class AfterTestGroupActions method process.
/**
* {@inheritDoc}
*/
@Override
public void process(TestGroupContext.TestGroupLifePhase lifePhase, TestGroupContext context) throws Throwable {
AfterTestGroup before = (AfterTestGroup) getTheOnlyTestGroupAnnotationInterestedIn(context);
String methodName = before.value();
try {
searchAndInvoke(methodName, context.getTestGroupInstance().getClass(), context.getTestGroupInstance(), context.getLog());
} catch (SomethingIsWrong e) {
final String message = e.getMessage();
context.printlnToLog(message);
final String failedTryingToInvoke = MessageFormat.format("Failed trying to invoke @AfterTestGroup method \"{0}\"", methodName);
throw new RuntimeException(failedTryingToInvoke);
}
}
use of com.sun.tck.lib.tgf.SomethingIsWrong in project jtharness by openjdk.
the class TGFTestCaseMethodSetting method processSettingMethodPhase.
private void processSettingMethodPhase(TestCaseContext.TestCaseLifePhase lifePhase, final TestCaseContext context) {
try {
if (dataIterator == null) {
final Object testGroupInstance = context.getTestGroupInstance();
Values data = collectReferencedData(context, testGroupInstance);
// todo cache somewhere somehow the generated exclude list
Map<String, Values.ExcludedIndices> excludeList = TGFUtils.createExcludeList(context.getParentContext().getExecutionArgs());
String testCaseName = context.getTestCaseName();
if (excludeList.containsKey(testCaseName)) {
data.markNotApplicable(excludeList.get(testCaseName));
}
if (data.isNotApplicable()) {
throw new NotApplicableException(data.getReasonNotApplicaple());
}
dataIterator = data.iterator();
rowIndex = -1;
notApplicableRowIndices = data.getNotApplicableRowIndices();
}
} catch (SomethingIsWrong somethingIsWrong) {
dataCreationFailure = true;
context.setThrownException(somethingIsWrong);
return;
}
if (dataIterator.hasNext() && !wasProcessorCalledForThisPhase(lifePhase)) {
rowIndex++;
rawArgs = dataIterator.next();
freshRawArgs = true;
final Object[] args = new Object[rawArgs.length];
for (int i = 0; i < rawArgs.length; i++) {
if (rawArgs[i] instanceof AbstractValue) {
args[i] = ((AbstractValue) rawArgs[i]).doCreate();
} else {
args[i] = rawArgs[i];
}
}
currentValue = args;
}
if (currentValue != null) {
context.setCallableTestCase(() -> {
context.setTestCaseInvocationArgValues(currentValue);
context.setRowIndex(rowIndex);
if (notApplicableRowIndices.isExcluded(rowIndex)) {
throw new NotApplicableException();
}
Object[] adaptedArgs = adaptArgsForVararg(context.getTestCaseMethod(), currentValue);
return context.getTestCaseMethod().invoke(context.getTestGroupInstance(), adaptedArgs);
});
}
}
Aggregations