org.jboss.arquillian.core.spi.EventContext Java Examples

The following examples show how to use org.jboss.arquillian.core.spi.EventContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestObserver.java    From tomee with Apache License 2.0 6 votes vote down vote up
public void release(@Observes final EventContext<BeforeUnDeploy> event) {
    if (!SystemInstance.isInitialized()) {
        event.proceed();
        return;
    }

    try {
        event.proceed();
    } finally {
        final BeanContext bc = beanContext();
        if (bc != null) { // can be null if deployment exception
            final CreationalContext<?> cc = bc.get(CreationalContext.class);
            if (cc != null) {
                cc.release();
            }
        }
    }
}
 
Example #2
Source File: NamespaceExtensionContainer.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
private void runWithinNamespaces(EventContext<Test> context, String[] namespaces) {
    final List<FailedNamespaceException> exceptions = new ArrayList<>();
    final String original = NamespaceManager.get();
    try {
        for (String namespace : namespaces) {
            try {
                NamespaceManager.set(namespace);
                context.proceed();
            } catch (Exception e) {
                exceptions.add(new FailedNamespaceException(e, namespace));
            }
        }
    } finally {
        NamespaceManager.set(original);
    }
    if (exceptions.size() > 1) {
        throw new MultipleExceptions(exceptions);
    } else if (exceptions.size() == 1) {
        throw exceptions.get(0);
    }
}
 
Example #3
Source File: NamespaceExtensionContainer.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
public void execute(@Observes EventContext<Test> context) {
    Test event = context.getEvent();

    Method testMethod = event.getTestMethod();
    WithinNamespace ns = testMethod.getAnnotation(WithinNamespace.class);
    if (ns == null) {
        ns = event.getTestClass().getAnnotation(WithinNamespace.class);
        if (ns == null) {
            Class<?> testClass = event.getTestClass().getJavaClass();
            ns = testClass.getPackage().getAnnotation(WithinNamespace.class);
        }
    }

    if (ns != null) {
        runWithinNamespaces(context, ns.value());
    } else {
        context.proceed();
    }
}
 
Example #4
Source File: TestObserver.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void switchLoader(final EventContext<?> event) {
    if (!SystemInstance.isInitialized()) {
        event.proceed();
        return;
    }
    final BeanContext context = beanContext();
    ThreadContext oldCtx = null;
    ClassLoader oldCl = null;
    if (context != null) {
        oldCtx = ThreadContext.enter(new ThreadContext(context, null));
    } else {
        oldCl = Thread.currentThread().getContextClassLoader();
        final ClassLoaders classLoaders = classLoader.get();
        if (classLoaders != null) {
            final ClassLoader loader = classLoaders.classloaders.size() == 1 /*assume it is the one we want*/ ?
                    classLoaders.classloaders.values().iterator().next() : oldCl /* we don't know the deployment so just passthrough */;
            setTCCL(loader);
        }
    }
    try {
        event.proceed();
    } finally {
        if (context != null) {
            ThreadContext.exit(oldCtx);
        } else {
            setTCCL(oldCl);
        }
    }
}
 
Example #5
Source File: IgnoreObserver.java    From arquillian-governor with Apache License 2.0 5 votes vote down vote up
private void execute(EventContext<? extends ExecutionEvent> context, String phase) {
    if (shouldPerformExecution(context.getEvent())) {
        context.proceed();
    } else {
        log.info("Ignore test [" + phase + "]: " + toFqn(context.getEvent()));
        testResultProducer.set(TestResult.skipped());
    }
}
 
Example #6
Source File: SuiteDeployer.java    From arquillian-suite-extension with Apache License 2.0 5 votes vote down vote up
/**
 * Method ignoring DeployManagedDeployments events if already deployed.
 *
 * @param eventContext Event to check
 */
public void blockDeployManagedDeploymentsWhenNeeded(@Observes EventContext<DeployManagedDeployments> eventContext) {
    if (!extensionEnabled()) {
        eventContext.proceed();
    }
    else if (deployDeployments) {
        deployDeployments = false;
        debug("NOT Blocking DeployManagedDeployments event {0}", eventContext.getEvent().toString());
        eventContext.proceed();
    } else {
        // Do nothing with event.
        debug("Blocking DeployManagedDeployments event {0}", eventContext.getEvent().toString());
    }
}
 
Example #7
Source File: SuiteDeployer.java    From arquillian-suite-extension with Apache License 2.0 5 votes vote down vote up
/**
 * Method ignoring GenerateDeployment events if deployment is already done.
 *
 * @param eventContext Event to check
 */
public void blockGenerateDeploymentWhenNeeded(@Observes EventContext<GenerateDeployment> eventContext) {
    if (!extensionEnabled()) {
        eventContext.proceed();
    }
    else if (suiteDeploymentGenerated) {
        // Do nothing with event.
        debug("Blocking GenerateDeployment event {0}", eventContext.getEvent().toString());
    } else {
        suiteDeploymentGenerated = true;
        debug("NOT Blocking GenerateDeployment event {0}", eventContext.getEvent().toString());
        eventContext.proceed();
    }
}
 
Example #8
Source File: SuiteDeployer.java    From arquillian-suite-extension with Apache License 2.0 5 votes vote down vote up
/**
 * Method ignoring UnDeployManagedDeployments events at runtime.
 *
 * Only at undeploy container we will undeploy all.
 *
 * @param eventContext Event to check
 */
public void blockUnDeployManagedDeploymentsWhenNeeded(@Observes EventContext<UnDeployManagedDeployments> eventContext) {
    if (!extensionEnabled()) {
        eventContext.proceed();
    }
    else if (undeployDeployments) {
        undeployDeployments = false;
        debug("NOT Blocking UnDeployManagedDeployments event {0}", eventContext.getEvent().toString());
        eventContext.proceed();
    } else {
        // Do nothing with event.
        debug("Blocking UnDeployManagedDeployments event {0}", eventContext.getEvent().toString());
    }
}
 
Example #9
Source File: CreationalContextDestroyer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void destroy(@Observes EventContext<After> event) throws IOException {
    try {
        event.proceed();
    } finally {
        InjectionEnricher.CreationContextHolder cc = creationalContext.get();
        if (cc != null) {
            cc.close();
        }
    }
}
 
Example #10
Source File: ArquillianSuiteExtension.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
public void resotreProtocolMetaData(@Observes EventContext<Before> eventContext) {
    testScopedProtocolMetaData.set(cachedProtocolMetaData);
    eventContext.proceed();
}
 
Example #11
Source File: TestObserver.java    From tomee with Apache License 2.0 4 votes vote down vote up
public void observesTest(@Observes final EventContext<TestEvent> event) {
    switchLoader(event);
}
 
Example #12
Source File: UserLogin.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
public void login(@Observes EventContext<Before> event) throws Exception {
    Before before = event.getEvent();

    UserIsLoggedIn userIsLoggedIn = null;
    if (before.getTestMethod().isAnnotationPresent(UserIsLoggedIn.class)) {
        userIsLoggedIn = before.getTestMethod().getAnnotation(UserIsLoggedIn.class);
    } else if (before.getTestClass().isAnnotationPresent(UserIsLoggedIn.class)) {
        userIsLoggedIn = before.getTestClass().getAnnotation(UserIsLoggedIn.class);
    }

    if (userIsLoggedIn != null) {
        final LoginContext context = new UserLoginContext(userIsLoggedIn);

        log.info(String.format("Found @UserIsLoggedIn: %s [%s]", context.getEmail(), userIsLoggedIn.location()));

        final URI baseUri = getBaseURI(before.getTestMethod());
        final WebDriver driver = createWebDriver();
        try {
            driver.manage().deleteAllCookies();

            driver.navigate().to(baseUri + USER_LOGIN_SERVLET_PATH + "?location=" + URLEncoder.encode(userIsLoggedIn.location(), "UTF-8"));

            // did we navigate to this requested page, or did we get redirected/forwarded to login already
            List<WebElement> loginUrlElts = driver.findElements(By.id("login-url"));
            if (loginUrlElts.size() > 0) {
                String loginURL = loginUrlElts.get(0).getText();

                // check
                if (isInternalLink(loginURL)) {
                    loginURL = baseUri + loginURL;
                }

                // go-to login page
                driver.navigate().to(loginURL);
            }

            // find custom login handler, if exists
            LoginHandler loginHandler = TestBase.instance(getClass(), LoginHandler.class);
            if (loginHandler == null) {
                loginHandler = new DefaultLoginHandler();
            }
            loginHandler.login(driver, context);
            log.info("Logged-in: " + context.getEmail());
            // copy cookies
            Set<Cookie> cookies = driver.manage().getCookies();
            for (Cookie cookie : cookies) {
                ModulesApi.addCookie(cookie.getName(), cookie.getValue());
            }
        } finally {
            driver.close();
        }
    }

    event.proceed();
}
 
Example #13
Source File: ArquillianSuiteExtension.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
public void blockUnDeployManagedDeployments(@Observes EventContext<UnDeployManagedDeployments> ignored) {
    // We need to block UnDeployManagedDeployments event
}
 
Example #14
Source File: ArquillianSuiteExtension.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
public void overrideBefore(@Observes EventContext<BeforeClass> event) {
    // Setup the Suite level scenario as if it came from the TestClass
    event.proceed();
    classDeploymentScenario.set(suiteDeploymentScenario);
}
 
Example #15
Source File: ArquillianSuiteExtension.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
public void blockDeployManagedDeployments(@Observes EventContext<DeployManagedDeployments> ignored) {
    // We need to block DeployManagedDeployments event
}
 
Example #16
Source File: IgnoreObserver.java    From arquillian-governor with Apache License 2.0 4 votes vote down vote up
public void remoteTest(@Observes(precedence = 1000) EventContext<RemoteExecutionEvent> context) {
    execute(context, "remote");
}
 
Example #17
Source File: IgnoreObserver.java    From arquillian-governor with Apache License 2.0 4 votes vote down vote up
public void localTest(@Observes(precedence = 1000) EventContext<LocalExecutionEvent> context) {
    execute(context, "local");
}