use of com.sun.tck.lib.NotApplicableException 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.NotApplicableException in project jtharness by openjdk.
the class TestDataCollector method checkIfTestCaseShouldBeExecuted.
/**
* Checking for @ExecuteIf(Not) annotations.
* May throw <code>SomethingIsWrong</code> exception or <code>NotApplicableException</code>
*/
public static void checkIfTestCaseShouldBeExecuted(Method method, Object testInstance, Class<?> testClass, PrintWriter log) {
ExecuteIf executeIf = method.getAnnotation(ExecuteIf.class);
ExecuteIfNot executeIfNot = method.getAnnotation(ExecuteIfNot.class);
if (executeIf == null && executeIfNot == null) {
return;
}
if (executeIf != null && executeIfNot != null) {
throw new SomethingIsWrong("@ExecuteIf and @ExecuteIfNot could not be used together for one testcase");
}
String fieldOrMethodName;
String reason;
if (executeIf != null) {
fieldOrMethodName = executeIf.value();
reason = executeIf.reason();
} else {
fieldOrMethodName = executeIfNot.value();
reason = executeIfNot.reason();
}
Boolean booleanResult;
try {
booleanResult = (Boolean) TGFUtils.getRawDataFromTextReference(testInstance, testClass, log, fieldOrMethodName, executeIf != null ? "@ExecuteIf" : "@ExecuteIfNot");
} catch (ClassCastException e) {
throw new SomethingIsWrong("\"" + fieldOrMethodName + "\" should be of boolean type");
}
if (booleanResult == null) {
throw new SomethingIsWrong("\"" + fieldOrMethodName + "\" has null value or returned null");
}
if (executeIf != null && !booleanResult || executeIfNot != null && booleanResult) {
throw new NotApplicableException(reason);
}
}
use of com.sun.tck.lib.NotApplicableException 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);
});
}
}
use of com.sun.tck.lib.NotApplicableException in project jtharness by openjdk.
the class RunningTestCases method process.
/**
* {@inheritDoc}
*/
@Override
public void process(TestGroupContext.TestGroupLifePhase lifePhase, TestGroupContext testGroupContext) {
Collection<TestCaseContext> testCases = testGroupContext.getTestCaseContexts();
// todo with streams here we may go parallel if needed in future
testCases.forEach(context -> {
TestResult result;
try {
TestDataCollector.checkIfTestCaseShouldBeExecuted(context.getTestCaseMethod(), context.getTestGroupInstance(), context.getTestGroupInstance().getClass(), context.getLog());
result = runTestCaseAsNeeded(context);
} catch (SomethingIsWrong e) {
// something might be wrong with runtime test skipping for example - @ExecuteIf/Not
context.printlnToLog(e.getMessage());
result = TestResult.failure(e.getMessage());
} catch (NotApplicableException e) {
String message = e.getMessage();
result = new InapplicableTestResult("Not applicable." + (message != null ? " Reason: " + message : ""));
}
// todo improve this
if (result instanceof InapplicableTestResult) {
testGroupContext.recordNotApplicable();
}
testGroupContext.addExecutionResult(context.getTestCaseName(), result);
});
}
Aggregations