use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class ThreadScopedActiveInterceptorTest method threadScopeActivatedWithInterceptorAtTypeLeve.
@Test
public void threadScopeActivatedWithInterceptorAtTypeLeve() {
try (WeldContainer container = new Weld().initialize()) {
Bar bar = container.select(Bar.class).get();
Assert.assertEquals(2, bar.doubleIncrement());
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class DevelopmentModeDisabledSmokeTest method testDevelopmentMode.
@SuppressWarnings("unchecked")
@Test
public void testDevelopmentMode() {
try (WeldContainer container = new Weld().initialize()) {
assertTrue(container.select(ProbeExtension.class).isUnsatisfied());
BeanManager beanManager = container.getBeanManager();
Bean<Omega> bean = (Bean<Omega>) beanManager.resolve(beanManager.getBeans(Omega.class));
assertFalse(bean.getStereotypes().contains(MonitoredComponent.class));
container.select(Omega.class).get().ping();
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class DevelopmentModeEnabledSmokeTest method testDevelopmentMode.
@SuppressWarnings("unchecked")
@Test
public void testDevelopmentMode() {
try (WeldContainer container = new Weld().initialize()) {
assertNotNull(container.select(ProbeExtension.class).get());
BeanManager beanManager = container.getBeanManager();
Bean<Omega> bean = (Bean<Omega>) beanManager.resolve(beanManager.getBeans(Omega.class));
assertTrue(bean.getStereotypes().contains(MonitoredComponent.class));
container.select(Omega.class).get().ping();
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class WeldInstanceTest method testHandlers.
@Test
public void testHandlers() {
ActionSequence.reset();
try (WeldContainer container = new Weld().initialize()) {
WeldInstance<Processor> instance = container.select(Processor.class);
assertTrue(instance.isAmbiguous());
for (Handler<Processor> handler : instance.handlers()) {
handler.get().ping();
if (handler.getBean().getScope().equals(Dependent.class)) {
handler.destroy();
}
}
assertEquals(3, ActionSequence.getSequenceSize());
ActionSequence.assertSequenceDataContainsAll("firstPing", "secondPing", "firstDestroy");
ActionSequence.reset();
assertTrue(instance.isAmbiguous());
for (Iterator<Handler<Processor>> iterator = instance.handlers().iterator(); iterator.hasNext(); ) {
try (Handler<Processor> handler = iterator.next()) {
handler.get().ping();
}
}
assertEquals(4, ActionSequence.getSequenceSize());
ActionSequence.assertSequenceDataContainsAll("firstPing", "secondPing", "firstDestroy", "secondDestroy");
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class WeldInstanceTest method testGetHandler.
@Test
public void testGetHandler() {
ActionSequence.reset();
try (WeldContainer container = new Weld().initialize()) {
Bean<?> alphaBean = container.getBeanManager().resolve(container.getBeanManager().getBeans(Alpha.class));
WeldInstance<Alpha> instance = container.select(Alpha.class);
Handler<Alpha> alpha1 = instance.getHandler();
assertEquals(alphaBean, alpha1.getBean());
assertEquals(Dependent.class, alpha1.getBean().getScope());
// Contextual reference is obtained lazily
assertNull(ActionSequence.getSequenceData());
String alpha2Id;
// Test try-with-resource
try (Handler<Alpha> alpha2 = instance.getHandler()) {
assertNull(ActionSequence.getSequenceData());
alpha2Id = alpha2.get().getId();
assertFalse(alpha1.get().getId().equals(alpha2Id));
}
List<String> sequence = ActionSequence.getSequenceData();
assertEquals(3, sequence.size());
assertEquals("c" + alpha2Id, sequence.get(0));
assertEquals("c" + alpha1.get().getId(), sequence.get(1));
assertEquals("d" + alpha2Id, sequence.get(2));
alpha1.destroy();
// Alpha1 destroyed
sequence = ActionSequence.getSequenceData();
assertEquals(4, sequence.size());
assertEquals("d" + alpha1.get().getId(), sequence.get(3));
// Subsequent invocations are no-op
alpha1.destroy();
// Test normal scoped bean is also destroyed
WeldInstance<Bravo> bravoInstance = container.select(Bravo.class);
String bravoId = bravoInstance.get().getId();
try (Handler<Bravo> bravo = bravoInstance.getHandler()) {
assertEquals(bravoId, bravo.get().getId());
ActionSequence.reset();
}
sequence = ActionSequence.getSequenceData();
assertEquals(1, sequence.size());
assertEquals("d" + bravoId, sequence.get(0));
}
}
Aggregations