use of io.quarkus.arc.ArcContainer in project quarkus by quarkusio.
the class RepeatingQualifierClassTest method testRepeatingQualifiers.
@Test
public void testRepeatingQualifiers() {
ArcContainer container = Arc.container();
// simple resolution with just one instance of repeatable qualifier
InstanceHandle<SomePlace> home = container.instance(SomePlace.class, new Location.Literal("home"));
Assertions.assertTrue(home.isAvailable());
// resolution when we select a bean having two repeatable qualifiers but only using one
InstanceHandle<SomePlace> farAway = container.instance(SomePlace.class, new Location.Literal("farAway"));
Assertions.assertTrue(farAway.isAvailable());
// resolution where we select a bean having two repeatable qualifiers using both
InstanceHandle<SomePlace> work = container.instance(SomePlace.class, new Location.Literal("work"), new Location.Literal("office"));
Assertions.assertTrue(work.isAvailable());
InjectingBean injectingBean = container.instance(InjectingBean.class).get();
Assertions.assertNotNull(injectingBean.getFarAway());
Assertions.assertNotNull(injectingBean.getHome());
Assertions.assertNotNull(injectingBean.getWork());
Assertions.assertNotNull(injectingBean.getLocationFromInitializer());
}
use of io.quarkus.arc.ArcContainer in project quarkus by quarkusio.
the class RepeatingQualifierObserverTest method testRepeatingQualifiers.
@Test
public void testRepeatingQualifiers() {
ArcContainer container = Arc.container();
Event<String> event = container.beanManager().getEvent().select(String.class);
ObservingBean bean = container.instance(ObservingBean.class).get();
List<String> expectedList = new ArrayList<>();
assertListsAreEqual(expectedList, bean.getEvents());
event.select(new Location.Literal("home")).fire("home");
expectedList.add("home");
assertListsAreEqual(expectedList, bean.getEvents());
event.select(new Location.Literal("farAway"), new Location.Literal("dreamland")).fire("farAway");
expectedList.add("farAway");
assertListsAreEqual(expectedList, bean.getEvents());
event.select(new Location.Literal("work"), new Location.Literal("office")).fire("work");
expectedList.add("work");
assertListsAreEqual(expectedList, bean.getEvents());
}
use of io.quarkus.arc.ArcContainer in project quarkus by quarkusio.
the class RepeatingQualifierProducerTest method testRepeatingQualifiers.
@Test
public void testRepeatingQualifiers() {
ArcContainer container = Arc.container();
container.requestContext().activate();
// all beans need to be invoked so that they are created, only then can we test disposers work as well
// simple resolution with just one instance of repeatable qualifier
InstanceHandle<SomePlace> home = container.instance(SomePlace.class, new Location.Literal("home"));
Assertions.assertTrue(home.isAvailable());
home.get().ping();
// resolution when we select a bean having two repeatable qualifiers but only using one
InstanceHandle<SomePlace> farAway = container.instance(SomePlace.class, new Location.Literal("farAway"));
Assertions.assertTrue(farAway.isAvailable());
farAway.get().ping();
// resolution where we select a bean having two repeatable qualifiers using both
InstanceHandle<SomePlace> work = container.instance(SomePlace.class, new Location.Literal("work"), new Location.Literal("office"));
Assertions.assertTrue(work.isAvailable());
work.get().ping();
// same as before but backed by field producer
InstanceHandle<SomePlace> matrix = container.instance(SomePlace.class, new Location.Literal("alternativeReality"), new Location.Literal("matrix"));
Assertions.assertTrue(matrix.isAvailable());
matrix.get().ping();
// deactivate req. context which will trigger disposers
container.requestContext().terminate();
// assert all disposers were invoked
ProducerBean producerBean = container.instance(ProducerBean.class).get();
Assertions.assertTrue(producerBean.isFarAwayDisposerInvoked());
Assertions.assertTrue(producerBean.isHomeDisposerInvoked());
Assertions.assertTrue(producerBean.isMatrixDisposerInvoked());
Assertions.assertTrue(producerBean.isWorkDisposerInvoked());
}
use of io.quarkus.arc.ArcContainer in project quarkus by quarkusio.
the class TypedTest method testEmptyTyped.
@Test
public void testEmptyTyped() throws IOException {
ArcContainer container = Arc.container();
assertFalse(container.instance(MyBean.class).isAvailable());
assertNull(EVENT.get());
container.beanManager().getEvent().fire("foo");
assertEquals("foo", EVENT.get());
InstanceHandle<Stage> stage = container.instance(Stage.class);
assertTrue(stage.isAvailable());
assertEquals("produced", stage.get().id);
assertTrue(container.instance(MyOtherBean.class).isAvailable());
boolean found = false;
for (Bean<?> bean : container.beanManager().getBeans(Object.class)) {
InjectableBean<?> injectable = (InjectableBean<?>) bean;
if (injectable.getDeclaringBean() == null && injectable.getBeanClass().equals(MyOtherBean.class)) {
found = true;
break;
}
}
assertTrue(found, "MyOtherBean not found");
}
use of io.quarkus.arc.ArcContainer in project quarkus by quarkusio.
the class RemoveUnusedDecoratorTest method testRemoval.
@Test
public void testRemoval() {
ArcContainer container = Arc.container();
assertPresent(HasObserver.class);
assertNotPresent(Converter.class);
assertTrue(container.beanManager().resolveDecorators(Set.of(Converter.class)).isEmpty());
}
Aggregations