Search in sources :

Example 1 with TheLoneBean

use of org.jboss.weld.environment.se.test.weldManager.contextActive.TheLoneBean in project core by weld.

the class GetContextUtilMethodsTest method getActiveContextsTest.

@Test
public void getActiveContextsTest() {
    try (WeldContainer container = new Weld().initialize()) {
        // TheLoneBean is just to have some bean in the archive
        container.select(TheLoneBean.class).get().ping();
        WeldManager manager = container.select(WeldManager.class).get();
        // there are 7 scopes by default in SE, only 3 have active contexts by default
        // it is dependent, singleton and application
        Collection<Context> activeContexts = manager.getActiveContexts();
        Assert.assertEquals(3, activeContexts.size());
        Set<Class<? extends Annotation>> scopes = activeContexts.stream().map(t -> t.getScope()).collect(Collectors.toSet());
        Assert.assertTrue(scopes.contains(Dependent.class));
        Assert.assertTrue(scopes.contains(Singleton.class));
        Assert.assertTrue(scopes.contains(ApplicationScoped.class));
    }
}
Also used : Context(jakarta.enterprise.context.spi.Context) WeldAlterableContext(org.jboss.weld.context.WeldAlterableContext) Dependent(jakarta.enterprise.context.Dependent) Arquillian(org.jboss.arquillian.junit.Arquillian) ApplicationScoped(jakarta.enterprise.context.ApplicationScoped) RunWith(org.junit.runner.RunWith) WeldManager(org.jboss.weld.manager.api.WeldManager) BeanArchive(org.jboss.shrinkwrap.api.BeanArchive) TheLoneBean(org.jboss.weld.environment.se.test.weldManager.contextActive.TheLoneBean) RequestContextController(jakarta.enterprise.context.control.RequestContextController) Weld(org.jboss.weld.environment.se.Weld) ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) Utils(org.jboss.weld.test.util.Utils) Collection(java.util.Collection) Set(java.util.Set) Singleton(jakarta.inject.Singleton) Context(jakarta.enterprise.context.spi.Context) Test(org.junit.Test) Archive(org.jboss.shrinkwrap.api.Archive) ClassPath(org.jboss.arquillian.container.se.api.ClassPath) WeldContainer(org.jboss.weld.environment.se.WeldContainer) Collectors(java.util.stream.Collectors) Deployment(org.jboss.arquillian.container.test.api.Deployment) WeldAlterableContext(org.jboss.weld.context.WeldAlterableContext) Annotation(java.lang.annotation.Annotation) Assert(org.junit.Assert) RequestScoped(jakarta.enterprise.context.RequestScoped) Singleton(jakarta.inject.Singleton) WeldContainer(org.jboss.weld.environment.se.WeldContainer) Dependent(jakarta.enterprise.context.Dependent) ApplicationScoped(jakarta.enterprise.context.ApplicationScoped) Annotation(java.lang.annotation.Annotation) Weld(org.jboss.weld.environment.se.Weld) WeldManager(org.jboss.weld.manager.api.WeldManager) Test(org.junit.Test)

Aggregations

ApplicationScoped (jakarta.enterprise.context.ApplicationScoped)1 Dependent (jakarta.enterprise.context.Dependent)1 RequestScoped (jakarta.enterprise.context.RequestScoped)1 RequestContextController (jakarta.enterprise.context.control.RequestContextController)1 Context (jakarta.enterprise.context.spi.Context)1 Singleton (jakarta.inject.Singleton)1 Annotation (java.lang.annotation.Annotation)1 Collection (java.util.Collection)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ClassPath (org.jboss.arquillian.container.se.api.ClassPath)1 Deployment (org.jboss.arquillian.container.test.api.Deployment)1 Arquillian (org.jboss.arquillian.junit.Arquillian)1 Archive (org.jboss.shrinkwrap.api.Archive)1 BeanArchive (org.jboss.shrinkwrap.api.BeanArchive)1 ShrinkWrap (org.jboss.shrinkwrap.api.ShrinkWrap)1 WeldAlterableContext (org.jboss.weld.context.WeldAlterableContext)1 Weld (org.jboss.weld.environment.se.Weld)1 WeldContainer (org.jboss.weld.environment.se.WeldContainer)1 TheLoneBean (org.jboss.weld.environment.se.test.weldManager.contextActive.TheLoneBean)1