Search in sources :

Example 1 with SeContainer

use of jakarta.enterprise.inject.se.SeContainer in project resteasy by resteasy.

the class SeCdiNettyTest method init.

@SuppressWarnings("unchecked")
@Before
public void init() {
    while (port < 8000) this.port = (int) ((new Random().nextDouble() * 8000) + 1000);
    SeContainerInitializer initializer = SeContainerInitializer.newInstance();
    SeContainer container = initializer.disableDiscovery().addBeanClasses(EchoResource.class).addBeanClasses(DefaultExceptionMapper.class).addExtensions(ResteasyCdiExtension.class).initialize();
    ResteasyCdiExtension cdiExtension = container.select(ResteasyCdiExtension.class).get();
    CdiNettyJaxrsServer netty = new CdiNettyJaxrsServer(container);
    ResteasyDeployment rd = new ResteasyDeploymentImpl();
    rd.setActualResourceClasses(cdiExtension.getResources());
    rd.setInjectorFactory(new CdiInjectorFactory(container.getBeanManager()));
    rd.getActualProviderClasses().addAll(cdiExtension.getProviders());
    netty.setDeployment(rd);
    netty.setPort(port);
    netty.setRootResourcePath("/api");
    netty.start();
    this.server = netty;
}
Also used : ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) Random(java.util.Random) ResteasyDeploymentImpl(org.jboss.resteasy.core.ResteasyDeploymentImpl) SeContainer(jakarta.enterprise.inject.se.SeContainer) CdiInjectorFactory(org.jboss.resteasy.cdi.CdiInjectorFactory) SeContainerInitializer(jakarta.enterprise.inject.se.SeContainerInitializer) ResteasyCdiExtension(org.jboss.resteasy.cdi.ResteasyCdiExtension) Before(org.junit.Before)

Example 2 with SeContainer

use of jakarta.enterprise.inject.se.SeContainer in project cdi-tck by eclipse-ee4j.

the class BootstrapSEContainerTest method testAddExtensionAsExtensionInstance.

@Test
@SpecAssertions({ @SpecAssertion(section = SE_BOOTSTRAP, id = "de"), @SpecAssertion(section = SE_CONTAINER_INITIALIZER, id = "b") })
public void testAddExtensionAsExtensionInstance() {
    SeContainerInitializer seContainerInitializer = SeContainerInitializer.newInstance();
    TestExtension testExtension = new TestExtension();
    try (SeContainer seContainer = seContainerInitializer.disableDiscovery().addBeanClasses(Foo.class).addExtensions(testExtension).initialize()) {
        TestExtension containerExtension = seContainer.select(TestExtension.class).get();
        assertTrue(containerExtension.getBeforeBeanDiscoveryNotified().get());
        assertTrue(containerExtension.getAfterTypeDiscoveryNotified().get());
        assertTrue(containerExtension.getAfterBeanDiscoveryNotified().get());
        assertTrue(containerExtension.getAfterDeploymentValidationNotified().get());
        assertTrue(containerExtension.getProcessAnnotatedTypeNotified().get());
        assertTrue(containerExtension.getProcessInjectionTargetNotified().get());
        assertTrue(containerExtension.getProcessBeanAttributesNotified().get());
        assertTrue(containerExtension.getProcessBeanNotified().get());
    }
}
Also used : SeContainer(jakarta.enterprise.inject.se.SeContainer) SeContainerInitializer(jakarta.enterprise.inject.se.SeContainerInitializer) SpecAssertions(org.jboss.test.audit.annotations.SpecAssertions) Test(org.testng.annotations.Test)

Example 3 with SeContainer

use of jakarta.enterprise.inject.se.SeContainer in project cdi-tck by eclipse-ee4j.

the class BootstrapSEContainerTest method testContainerCloseMethodOnNotInitializedContainer.

@Test(expectedExceptions = IllegalStateException.class)
@SpecAssertions(@SpecAssertion(section = SE_CONTAINER, id = "ca"))
public void testContainerCloseMethodOnNotInitializedContainer() {
    SeContainer seContainer = initializeAndShutdownContainer();
    seContainer.close();
}
Also used : SeContainer(jakarta.enterprise.inject.se.SeContainer) SpecAssertions(org.jboss.test.audit.annotations.SpecAssertions) Test(org.testng.annotations.Test)

Example 4 with SeContainer

use of jakarta.enterprise.inject.se.SeContainer in project cdi-tck by eclipse-ee4j.

the class BootstrapSEContainerTest method testAddDecorator.

@Test
@SpecAssertions({ @SpecAssertion(section = SE_BOOTSTRAP, id = "dg"), @SpecAssertion(section = SE_CONTAINER_INITIALIZER, id = "b") })
public void testAddDecorator() {
    SeContainerInitializer seContainerInitializer = SeContainerInitializer.newInstance();
    try (SeContainer seContainer = seContainerInitializer.disableDiscovery().addBeanClasses(Corge.class, CorgeImpl.class, CorgeDecorator.class).enableDecorators(CorgeDecorator.class).initialize()) {
        Corge corge = seContainer.select(Corge.class).get();
        int result = corge.ping();
        assertTrue(CorgeDecorator.notified);
        assertEquals(result, 2);
    }
}
Also used : SeContainer(jakarta.enterprise.inject.se.SeContainer) SeContainerInitializer(jakarta.enterprise.inject.se.SeContainerInitializer) SpecAssertions(org.jboss.test.audit.annotations.SpecAssertions) Test(org.testng.annotations.Test)

Example 5 with SeContainer

use of jakarta.enterprise.inject.se.SeContainer in project cdi-tck by eclipse-ee4j.

the class BootstrapSEContainerTest method testAlternativesInSE.

@Test
@SpecAssertions({ @SpecAssertion(section = SE_CONTAINER_INITIALIZER, id = "a"), @SpecAssertion(section = SE_BOOTSTRAP, id = "db"), @SpecAssertion(section = SE_BOOTSTRAP, id = "dh"), @SpecAssertion(section = SE_BOOTSTRAP, id = "di"), @SpecAssertion(section = SE_BOOTSTRAP, id = "dm"), @SpecAssertion(section = SE_CONTAINER_INITIALIZER, id = "b") })
public void testAlternativesInSE() {
    SeContainerInitializer seContainerInitializer = SeContainerInitializer.newInstance();
    try (SeContainer seContainer = seContainerInitializer.disableDiscovery().addBeanClasses(Square.class, Circle.class, Foo.class, FooProducer.class).selectAlternatives(Circle.class).selectAlternativeStereotypes(AlternativeStereotype.class).initialize()) {
        Shape shape = seContainer.select(Shape.class).get();
        assertEquals(shape.name(), Circle.NAME);
        Set<Bean<?>> foos = seContainer.getBeanManager().getBeans(Foo.class);
        Optional<Bean<?>> alternativeFoo = foos.stream().filter(bean -> bean.isAlternative()).findAny();
        assertTrue(alternativeFoo.isPresent());
        assertEquals(alternativeFoo.get().getName(), "createFoo");
    }
}
Also used : Any(jakarta.enterprise.inject.Any) SE_CONTAINER(org.jboss.cdi.tck.cdi.Sections.SE_CONTAINER) EmptyAsset(org.jboss.shrinkwrap.api.asset.EmptyAsset) InjectLiteral(jakarta.enterprise.inject.literal.InjectLiteral) SeContainer(jakarta.enterprise.inject.se.SeContainer) Assert.assertEquals(org.testng.Assert.assertEquals) Pear(org.jboss.cdi.tck.tests.se.container.testPackage.nestedPackage.Pear) Test(org.testng.annotations.Test) Worm(org.jboss.cdi.tck.tests.se.container.testPackage.Worm) Instance(jakarta.enterprise.inject.Instance) Bean(jakarta.enterprise.inject.spi.Bean) SE_CONTAINER_INITIALIZER(org.jboss.cdi.tck.cdi.Sections.SE_CONTAINER_INITIALIZER) SpecVersion(org.jboss.test.audit.annotations.SpecVersion) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion) Assert.assertFalse(org.testng.Assert.assertFalse) BeanManager(jakarta.enterprise.inject.spi.BeanManager) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) Arquillian(org.jboss.arquillian.testng.Arquillian) SpecAssertions(org.jboss.test.audit.annotations.SpecAssertions) Set(java.util.Set) Assert.assertNotNull(org.testng.Assert.assertNotNull) Archive(org.jboss.shrinkwrap.api.Archive) ClassPath(org.jboss.arquillian.container.se.api.ClassPath) SeContainerInitializer(jakarta.enterprise.inject.se.SeContainerInitializer) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) SE(org.jboss.cdi.tck.TestGroups.SE) SE_BOOTSTRAP(org.jboss.cdi.tck.cdi.Sections.SE_BOOTSTRAP) Assert.assertTrue(org.testng.Assert.assertTrue) Optional(java.util.Optional) Apple(org.jboss.cdi.tck.tests.se.container.testPackage.Apple) SeContainer(jakarta.enterprise.inject.se.SeContainer) SeContainerInitializer(jakarta.enterprise.inject.se.SeContainerInitializer) Bean(jakarta.enterprise.inject.spi.Bean) SpecAssertions(org.jboss.test.audit.annotations.SpecAssertions) Test(org.testng.annotations.Test)

Aggregations

SeContainer (jakarta.enterprise.inject.se.SeContainer)103 Test (org.testng.annotations.Test)66 SeContainerInitializer (jakarta.enterprise.inject.se.SeContainerInitializer)61 SpecAssertions (org.jboss.test.audit.annotations.SpecAssertions)38 SpecAssertion (org.jboss.test.audit.annotations.SpecAssertion)30 Test (org.junit.jupiter.api.Test)14 BeanManager (jakarta.enterprise.inject.spi.BeanManager)11 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)10 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)10 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)10 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)9 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)9 Test (org.junit.Test)9 MetadataSources (org.hibernate.boot.MetadataSources)7 ContextNotActiveException (jakarta.enterprise.context.ContextNotActiveException)6 Apple (org.jboss.cdi.tck.tests.se.container.testPackage.Apple)6 Pear (org.jboss.cdi.tck.tests.se.container.testPackage.nestedPackage.Pear)6 Config (org.eclipse.microprofile.config.Config)5 ServerCdiExtension (io.helidon.microprofile.server.ServerCdiExtension)3 Bean (jakarta.enterprise.inject.spi.Bean)3