@Override public void fire(T event) { manager.fire(event); } }
@Override public void fire(T event) { manager.fire(event); } }
public void afterSuite() throws Exception { manager.fire(new AfterSuite()); }
public void beforeSuite() throws Exception { manager.fire(new BeforeSuite()); }
public void beforeClass(Class<?> testClass, LifecycleMethodExecutor executor) throws Exception { Validate.notNull(testClass, "TestClass must be specified"); if (testClass.isAnnotationPresent(Observer.class)) { Observer annotation = testClass.getAnnotation(Observer.class); Class<?>[] classes = annotation.value(); for (Class<?> observerClass : classes) { manager.addExtension(observerClass); } } manager.fire(new BeforeClass(testClass, executor)); }
public void afterClass(Class<?> testClass, LifecycleMethodExecutor executor) throws Exception { Validate.notNull(testClass, "TestClass must be specified"); manager.fire(new AfterClass(testClass, executor)); if (testClass.isAnnotationPresent(Observer.class)) { Observer annotation = testClass.getAnnotation(Observer.class); Class<?>[] classes = annotation.value(); for (Class<?> observerClass : classes) { manager.removeExtension(observerClass); } } }
/** * Client-to-Container event propagation */ private void executePutOperation(HttpServletRequest request, HttpServletResponse response) throws IOException, ClassNotFoundException { if (request.getContentLength() > 0) { ObjectInputStream input = new ObjectInputStream(new BufferedInputStream(request.getInputStream())); CommandPayload payload = (CommandPayload) input.readObject(); Command operation = payload.getCommand(); Manager manager = (Manager) request.getAttribute(ARQUILLIAN_MANAGER_ATTRIBUTE); // execute remote Event try { manager.fire(new ActivateManager(manager)); manager.inject(operation); operation.perform(); manager.fire(new PassivateManager(manager)); } catch (Throwable e) { payload.setThrowable(e); } response.setStatus(HttpServletResponse.SC_OK); ObjectOutputStream output = new ObjectOutputStream(response.getOutputStream()); output.writeObject(payload); output.flush(); output.close(); } else { response.setStatus(HttpServletResponse.SC_NO_CONTENT); } }
@Override public <T extends TestLifecycleEvent> void fireCustomLifecycle(T event) throws Exception { Validate.notNull(event, "Event must be specified"); ExecutionDecision executionDecision = resolveExecutionDecision(manager, event.getTestMethod()); if (executionDecision.getDecision() == Decision.DONT_EXECUTE) { return; } manager.fire(event); }
public void before(Object testInstance, Method testMethod, LifecycleMethodExecutor executor) throws Exception { Validate.notNull(testInstance, "TestInstance must be specified"); Validate.notNull(testMethod, "TestMethod must be specified"); ExecutionDecision executionDecision = resolveExecutionDecision(manager, testMethod); if (executionDecision.getDecision() == Decision.DONT_EXECUTE) { return; } manager.fire(new Before(testInstance, testMethod, executor)); }
public void after(Object testInstance, Method testMethod, LifecycleMethodExecutor executor) throws Exception { Validate.notNull(testInstance, "TestInstance must be specified"); Validate.notNull(testMethod, "TestMethod must be specified"); ExecutionDecision executionDecision = resolveExecutionDecision(manager, testMethod); if (executionDecision.getDecision() == Decision.DONT_EXECUTE) { return; } manager.fire(new After(testInstance, testMethod, executor)); }
@Test public void shouldBeAbleToUseProtectedFieldsAndMethods() throws Exception { Class<?> observerClass = SecurityActions.loadClass( this.getClass().getPackage().getName() + ".test.PrivateObserver"); Manager manager = ManagerBuilder.from().extension(observerClass).create(); manager.fire("Test"); Field wasCalled = observerClass.getField("wasCalled"); wasCalled.setAccessible(true); Assert.assertTrue((Boolean) wasCalled.get(null)); } }
@Test public void shouldBeAbleToUseProtectedFieldsAndMethods() throws Exception { Class<?> observerClass = SecurityActions.loadClass( this.getClass().getPackage().getName() + ".test.PrivateObserver"); Manager manager = ManagerBuilder.from().extension(observerClass).create(); manager.fire("Test"); Field wasCalled = observerClass.getField("wasCalled"); wasCalled.setAccessible(true); Assert.assertTrue((Boolean) wasCalled.get(null)); } }
@Override public void doFilter(ResourceRequest request, ResourceResponse response, FilterChain chain) throws IOException, PortletException { getManager(request); if (manager != null) { manager.bind(RequestScoped.class, ResourceRequest.class, request); manager.bind(RequestScoped.class, ResourceResponse.class, response); doCommonBinding(request, response, chain); manager.fire(new ExecutePortalWarpResourceRequest()); } else { chain.doFilter(request, response); } }
@Override public void doFilter(ActionRequest request, ActionResponse response, FilterChain chain) throws IOException, PortletException { getManager(request); if (manager != null) { manager.bind(RequestScoped.class, ActionRequest.class, request); manager.bind(RequestScoped.class, ActionResponse.class, response); doCommonBinding(request, response, chain); manager.fire(new ExecutePortalWarpActionRequest()); } else { chain.doFilter(request, response); } }
@Override public void doFilter(EventRequest request, EventResponse response, FilterChain chain) throws IOException, PortletException { getManager(request); if (manager != null) { manager.bind(RequestScoped.class, EventRequest.class, request); manager.bind(RequestScoped.class, EventResponse.class, response); doCommonBinding(request, response, chain); manager.fire(new ExecutePortalWarpEventRequest()); } else { chain.doFilter(request, response); } }
@Override public void doFilter(RenderRequest request, RenderResponse response, FilterChain chain) throws IOException, PortletException { getManager(request); if (manager != null) { manager.bind(RequestScoped.class, RenderRequest.class, request); manager.bind(RequestScoped.class, RenderResponse.class, response); doCommonBinding(request, response, chain); manager.fire(new ExecutePortalWarpRenderRequest()); } else { chain.doFilter(request, response); } }
@Test public void shouldExecuteProducersOnSameEventBeforeConsumers() throws Exception { Manager manager = ManagerBuilder.from() .extensions(ConsumerOne.class, ProducerOne.class, ProducerTwo.class).create(); manager.fire("test"); Assert.assertEquals("ProducerOne", callOrder.get(0)); Assert.assertEquals("ProducerTwo", callOrder.get(1)); Assert.assertEquals("ConsumerOne", callOrder.get(2)); }
@Test public void shouldExecuteProducersOnSameEventBeforeConsumers() throws Exception { Manager manager = ManagerBuilder.from() .extensions(ConsumerOne.class, ProducerOne.class, ProducerTwo.class).create(); manager.fire("test"); Assert.assertEquals("ProducerOne", callOrder.get(0)); Assert.assertEquals("ProducerTwo", callOrder.get(1)); Assert.assertEquals("ConsumerOne", callOrder.get(2)); }
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); }