/** * 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; }
/** * @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; }
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(); }
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(); } } }
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();
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();
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 ); }
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 ); }
String testMethod = testMethodExecutor.getMethod().getName(); String testCanonicalName = testClass + "." + testMethod;
@SuppressWarnings("unchecked") @Before public void setup() throws Exception { bind(ApplicationScoped.class, Container.class, container); bind(ApplicationScoped.class, DeploymentDescription.class, deploymentDescription); bind(ApplicationScoped.class, ProtocolMetaData.class, protocolMetaData); bind(ApplicationScoped.class, ProtocolRegistry.class, protocolRegistry); Mockito.when(deploymentDescription.getProtocol()).thenReturn(new ProtocolDescription("TEST")); Mockito.when(protocolRegistry.getProtocol(Mockito.any(ProtocolDescription.class))).thenReturn(protocolDefinition); Mockito.when(protocolDefinition.getProtocol()).thenReturn(protocol); Mockito.when(protocol.getExecutor( Mockito.any(ProtocolConfiguration.class), Mockito.any(ProtocolMetaData.class), Mockito.any(CommandCallback.class))).thenAnswer(new Answer<ContainerMethodExecutor>() { @Override public ContainerMethodExecutor answer(InvocationOnMock invocation) throws Throwable { return new TestContainerMethodExecutor((CommandCallback) invocation.getArguments()[2]); } }); Mockito.when(testExecutor.getInstance()).thenReturn(this); Mockito.when(testExecutor.getMethod()).thenReturn( getTestMethod("shouldReactivePreviousContextsOnRemoteEvents")); }
@SuppressWarnings("unchecked") @Before public void setup() throws Exception { bind(ApplicationScoped.class, Container.class, container); bind(ApplicationScoped.class, DeploymentDescription.class, deploymentDescription); bind(ApplicationScoped.class, ProtocolMetaData.class, protocolMetaData); bind(ApplicationScoped.class, ProtocolRegistry.class, protocolRegistry); Mockito.when(deploymentDescription.getProtocol()).thenReturn(new ProtocolDescription("TEST")); Mockito.when(protocolRegistry.getProtocol(Mockito.any(ProtocolDescription.class))).thenReturn(protocolDefinition); Mockito.when(protocolDefinition.getProtocol()).thenReturn(protocol); Mockito.when(protocol.getExecutor( Mockito.any(ProtocolConfiguration.class), Mockito.any(ProtocolMetaData.class), Mockito.any(CommandCallback.class))).thenAnswer(new Answer<ContainerMethodExecutor>() { @Override public ContainerMethodExecutor answer(InvocationOnMock invocation) throws Throwable { return new TestContainerMethodExecutor((CommandCallback) invocation.getArguments()[2]); } }); Mockito.when(testExecutor.getInstance()).thenReturn(this); Mockito.when(testExecutor.getMethod()).thenReturn( getTestMethod("shouldReactivePreviousContextsOnRemoteEvents")); }
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); }
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 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); }
@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()); }
@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()); }
@Test public void shouldReturnPassed() throws Throwable { bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader); Mockito.when(testExecutor.getInstance()).thenReturn(this); Mockito.when(testExecutor.getMethod()).thenReturn( getTestMethod("shouldReturnPassed")); fire(new LocalExecutionEvent(testExecutor)); TestResult result = getManager().resolve(TestResult.class); Assert.assertNotNull( "Should have set result", result); Assert.assertEquals( "Should have passed test", TestResult.Status.PASSED, result.getStatus()); Assert.assertNull( "Should not have set cause", result.getThrowable()); }
@Test public void shouldReturnPassed() throws Throwable { bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader); Mockito.when(testExecutor.getInstance()).thenReturn(this); Mockito.when(testExecutor.getMethod()).thenReturn( getTestMethod("shouldReturnPassed")); fire(new LocalExecutionEvent(testExecutor)); TestResult result = getManager().resolve(TestResult.class); Assert.assertNotNull( "Should have set result", result); Assert.assertEquals( "Should have passed test", TestResult.Status.PASSED, result.getStatus()); Assert.assertNull( "Should not have set cause", result.getThrowable()); }
Mockito.when(testExecutor.getMethod()).thenReturn(testMethod);