/** * Invoke method after enrichment. Inexplicably, the {@code @Before} * and {@code @After} methods are not called when running this * executor. Calling them manually for now. * * @param testMethodExecutor Method executor. * @return Test result. */ public TestResult invoke(TestMethodExecutor testMethodExecutor) { RequestContextController controller = enricher.getRequestContextController(); try { controller.activate(); Object object = testMethodExecutor.getInstance(); Method method = testMethodExecutor.getMethod(); LOGGER.info("Invoking '" + method + "' on " + object); enricher.enrich(object); invokeAnnotated(object, Before.class); testMethodExecutor.invoke(enricher.resolve(method)); invokeAnnotated(object, After.class); } catch (Throwable t) { return TestResult.failed(t); } finally { controller.deactivate(); } return TestResult.passed(); }
/** * @param testMethodExecutor * The executor responsible for executing the test method */ public Test(TestMethodExecutor testMethodExecutor) { // TODO: how to validate testMethodExecutor super(testMethodExecutor.getInstance(), testMethodExecutor.getMethod()); //Validate.notNull(testMethodExecutor, "TestMethodExecutor must be specified"); this.testMethodExecutor = testMethodExecutor; }
@Override public Object answer(org.mockito.invocation.InvocationOnMock invocation) throws Throwable { for (Object argument : invocation.getArguments()) { if (argument instanceof LifecycleMethodExecutor) { ((LifecycleMethodExecutor) argument).invoke(); } else if (argument instanceof TestMethodExecutor) { ((TestMethodExecutor) argument).invoke(); } else if (argument instanceof TestLifecycleEvent) { ((TestLifecycleEvent) argument).getExecutor().invoke(); } } return null; } }
public void execute(@Observes LocalExecutionEvent event) throws Exception { TestResult result = new TestResult(); try { event.getExecutor().invoke( enrichArguments( event.getExecutor().getMethod(), serviceLoader.get().all(TestEnricher.class))); result.setStatus(Status.PASSED); } catch (Throwable e) { result.setStatus(Status.FAILED); result.setThrowable(e); } finally { result.setEnd(System.currentTimeMillis()); } testResult.set(result); }
public TestResult test(TestMethodExecutor testMethodExecutor) throws Exception { Validate.notNull(testMethodExecutor, "TestMethodExecutor must be specified"); ExecutionDecision executionDecision = resolveExecutionDecision(manager, testMethodExecutor.getMethod()); if (executionDecision.getDecision() == Decision.DONT_EXECUTE) { return TestResult.skipped(new SkippedTestExecutionException(executionDecision.getReason())); } final List<TestResult> results = new ArrayList<TestResult>(); manager.fire(new Test(testMethodExecutor), new NonManagedObserver<Test>() { @Inject private Instance<TestResult> testResult; @Override public void fired(Test event) { results.add(testResult.get()); } }); return TestResult.flatten(results); }
/** * @param testMethodExecutor * The executor responsible for executing the test method */ public Test(TestMethodExecutor testMethodExecutor) { // TODO: how to validate testMethodExecutor super(testMethodExecutor.getInstance(), testMethodExecutor.getMethod()); //Validate.notNull(testMethodExecutor, "TestMethodExecutor must be specified"); this.testMethodExecutor = testMethodExecutor; }
@Override public Object answer(org.mockito.invocation.InvocationOnMock invocation) throws Throwable { for (Object argument : invocation.getArguments()) { if (argument instanceof LifecycleMethodExecutor) { ((LifecycleMethodExecutor) argument).invoke(); } else if (argument instanceof TestMethodExecutor) { ((TestMethodExecutor) argument).invoke(); } } return null; } }
public void execute(@Observes LocalExecutionEvent event) throws Exception { TestResult result = new TestResult(); try { event.getExecutor().invoke( enrichArguments( event.getExecutor().getMethod(), serviceLoader.get().all(TestEnricher.class))); result.setStatus(Status.PASSED); } catch (Throwable e) { result.setStatus(Status.FAILED); result.setThrowable(e); } finally { result.setEnd(System.currentTimeMillis()); } testResult.set(result); }
private String toFqn(ExecutionEvent event) { final TestMethodExecutor executor = event.getExecutor(); final Object test = executor.getInstance(); final Method method = executor.getMethod(); return test.getClass().getName() + "#" + method.getName(); }
@Test public void shouldReturnFailedOnException() throws Throwable { bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader); Exception exception = new Exception(); Mockito.when(testExecutor.getInstance()).thenReturn(this); Mockito.when(testExecutor.getMethod()).thenReturn( getTestMethod("shouldReturnFailedOnException")); Mockito.doThrow(exception).when(testExecutor).invoke(); fire(new LocalExecutionEvent(testExecutor)); TestResult result = getManager().resolve(TestResult.class); Assert.assertNotNull( "Should have set result", result); Assert.assertEquals( "Should have failed test", TestResult.Status.FAILED, result.getStatus()); Assert.assertEquals( "Should have set failed cause", exception, result.getThrowable()); }
@Override public Object answer(org.mockito.invocation.InvocationOnMock invocation) throws Throwable { for (Object argument : invocation.getArguments()) { if (argument instanceof LifecycleMethodExecutor) { ((LifecycleMethodExecutor) argument).invoke(); } else if (argument instanceof TestMethodExecutor) { ((TestMethodExecutor) argument).invoke(); } } return null; } }
public TestResult invoke(final TestMethodExecutor testMethodExecutor) { if (testMethodExecutor == null) { throw new IllegalArgumentException("TestMethodExecutor must be specified"); } URI targetBaseURI = uriHandler.locateTestServlet(testMethodExecutor.getMethod()); Class<?> testClass = testMethodExecutor.getInstance().getClass(); final String url = targetBaseURI.toASCIIString() + ARQUILLIAN_SERVLET_MAPPING + "?outputMode=serializedObject&className=" + testClass.getName() + "&methodName=" + testMethodExecutor.getMethod().getName(); final String eventUrl = targetBaseURI.toASCIIString() + ARQUILLIAN_SERVLET_MAPPING + "?outputMode=serializedObject&className=" + testClass.getName() + "&methodName=" + testMethodExecutor.getMethod().getName() + "&cmd=event"; Timer eventTimer = null; try { eventTimer = createCommandServicePullTimer(eventUrl); return executeWithRetry(url, TestResult.class); } catch (Exception e) { throw new IllegalStateException("Error launching test " + testClass.getName() + " " + testMethodExecutor.getMethod(), e); } finally { if (eventTimer != null) { eventTimer.cancel(); } } }
@Test public void shouldReturnFailedOnException() throws Throwable { bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader); Exception exception = new Exception(); Mockito.when(testExecutor.getInstance()).thenReturn(this); Mockito.when(testExecutor.getMethod()).thenReturn( getTestMethod("shouldReturnFailedOnException")); Mockito.doThrow(exception).when(testExecutor).invoke(); fire(new LocalExecutionEvent(testExecutor)); TestResult result = getManager().resolve(TestResult.class); Assert.assertNotNull( "Should have set result", result); Assert.assertEquals( "Should have failed test", TestResult.Status.FAILED, result.getStatus()); Assert.assertEquals( "Should have set failed cause", exception, result.getThrowable()); }
@Override public Object answer(org.mockito.invocation.InvocationOnMock invocation) throws Throwable { wasCalled(cycle); for (Object argument : invocation.getArguments()) { if (argument instanceof LifecycleMethodExecutor) { ((LifecycleMethodExecutor) argument).invoke(); } else if (argument instanceof TestMethodExecutor) { ((TestMethodExecutor) argument).invoke(); } } return null; } }
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();
@Override public Object answer(org.mockito.invocation.InvocationOnMock invocation) throws Throwable { for (Object argument : invocation.getArguments()) { if (argument instanceof LifecycleMethodExecutor) { ((LifecycleMethodExecutor) argument).invoke(); } else if (argument instanceof TestMethodExecutor) { ((TestMethodExecutor) argument).invoke(); } else if (argument instanceof TestLifecycleEvent) { ((TestLifecycleEvent) argument).getExecutor().invoke(); } } return null; } }
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();
@Override public Object answer(org.mockito.invocation.InvocationOnMock invocation) throws Throwable { for (Object argument : invocation.getArguments()) { if (argument instanceof LifecycleMethodExecutor) { ((LifecycleMethodExecutor) argument).invoke(); } else if (argument instanceof TestMethodExecutor) { ((TestMethodExecutor) argument).invoke(); } else if (argument instanceof TestLifecycleEvent) { ((TestLifecycleEvent) argument).getExecutor().invoke(); } } return null; } }
private org.jboss.arquillian.test.spi.event.suite.Test test(String testMethodName, Object obj) throws Exception { TestMethodExecutor executor = mock(TestMethodExecutor.class); when(executor.getInstance()).thenReturn(obj); when(executor.getMethod()).thenReturn(method(testMethodName)); return new org.jboss.arquillian.test.spi.event.suite.Test( executor ); }
@Override public Object answer(org.mockito.invocation.InvocationOnMock invocation) throws Throwable { for (Object argument : invocation.getArguments()) { if (argument instanceof LifecycleMethodExecutor) { ((LifecycleMethodExecutor) argument).invoke(); } else if (argument instanceof TestMethodExecutor) { ((TestMethodExecutor) argument).invoke(); } else if (argument instanceof TestLifecycleEvent) { ((TestLifecycleEvent) argument).getExecutor().invoke(); } } return null; } }