Search in sources :

Example 1 with TestResult

use of org.jboss.arquillian.test.spi.TestResult 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)

Example 2 with TestResult

use of org.jboss.arquillian.test.spi.TestResult in project wildfly-swarm by wildfly-swarm.

the class DaemonMethodExecutor method invoke.

/**
 * {@inheritDoc}
 *
 * @see org.jboss.arquillian.container.test.spi.ContainerMethodExecutor#invoke(org.jboss.arquillian.test.spi.TestMethodExecutor)
 */
@Override
public TestResult invoke(final TestMethodExecutor testMethodExecutor) {
    assert testMethodExecutor != null : "Test method executor is required";
    // Build the String request according to the wire protocol
    final StringBuilder builder = new StringBuilder();
    builder.append(WireProtocol.COMMAND_TEST_PREFIX);
    builder.append(testMethodExecutor.getInstance().getClass().getName());
    builder.append(SPACE);
    builder.append(testMethodExecutor.getMethod().getName());
    builder.append(WireProtocol.COMMAND_EOF_DELIMITER);
    final String testCommand = builder.toString();
    final PrintWriter writer = this.context.getWriter();
    // Request
    writer.write(testCommand);
    writer.flush();
    try {
        // Read response
        final ObjectInputStream response = new ObjectInputStream(new NoCloseInputStream(context.getSocketInstream()));
        final TestResult testResult = (TestResult) response.readObject();
        response.close();
        return testResult;
    } catch (final IOException ioe) {
        throw new RuntimeException("Could not get test results", ioe);
    } catch (final ClassNotFoundException cnfe) {
        throw new RuntimeException("test result not on the client classpath", cnfe);
    }
}
Also used : TestResult(org.jboss.arquillian.test.spi.TestResult) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

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