Search in sources :

Example 1 with InstanceProducer

use of org.jboss.arquillian.core.api.InstanceProducer in project keycloak by keycloak.

the class ModelTestExecutor method execute.

@Override
public void execute(LocalExecutionEvent event) throws Exception {
    Method testMethod = event.getExecutor().getMethod();
    ModelTest annotation = testMethod.getAnnotation(ModelTest.class);
    if (annotation == null) {
        // Not a model test
        super.execute(event);
    } else {
        TestResult result = new TestResult();
        try {
            // Model test - wrap the call inside the
            TestContext ctx = testContext.get();
            KeycloakTestingClient testingClient = ctx.getTestingClient();
            testingClient.server().runModelTest(testMethod.getDeclaringClass().getName(), testMethod.getName());
            result.setStatus(TestResult.Status.PASSED);
        } catch (Throwable e) {
            result.setStatus(TestResult.Status.FAILED);
            result.setThrowable(e);
        } finally {
            result.setEnd(System.currentTimeMillis());
        }
        // Need to use reflection this way...
        Field testResultField = Reflections.findDeclaredField(LocalTestExecuter.class, "testResult");
        testResultField.setAccessible(true);
        InstanceProducer<TestResult> thisTestResult = (InstanceProducer<TestResult>) testResultField.get(this);
        thisTestResult.set(result);
    }
}
Also used : ModelTest(org.keycloak.testsuite.arquillian.annotation.ModelTest) Field(java.lang.reflect.Field) InstanceProducer(org.jboss.arquillian.core.api.InstanceProducer) TestResult(org.jboss.arquillian.test.spi.TestResult) KeycloakTestingClient(org.keycloak.testsuite.client.KeycloakTestingClient) Method(java.lang.reflect.Method)

Aggregations

Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 InstanceProducer (org.jboss.arquillian.core.api.InstanceProducer)1 TestResult (org.jboss.arquillian.test.spi.TestResult)1 ModelTest (org.keycloak.testsuite.arquillian.annotation.ModelTest)1 KeycloakTestingClient (org.keycloak.testsuite.client.KeycloakTestingClient)1