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;
}
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());
}
}
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();
}
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);
}
}
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");
}
}
Aggregations