Java Code Examples for javax.enterprise.inject.Instance#select()
The following examples show how to use
javax.enterprise.inject.Instance#select() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AmqpClientHelper.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
static AmqpClient createClientFromClientOptionsBean(Vertx vertx, Instance<AmqpClientOptions> instance, String optionsBeanName) { Instance<AmqpClientOptions> options = instance.select(NamedLiteral.of(optionsBeanName)); if (options.isUnsatisfied()) { throw ex.illegalStateFindingBean(AmqpClientOptions.class.getName(), optionsBeanName); } log.createClientFromBean(optionsBeanName); return AmqpClient.create(vertx, options.get()); }
Example 2
Source File: BuiltInBeansAreResolvableTest.java From quarkus with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "serial", "unchecked", "rawtypes" }) @Test public void testEventBean() { // use dynamic resolution to test it Instance<Object> instance = Arc.container().beanManager().createInstance(); // event with no qualifier and raw type Instance<Event> rawNoQualifier = instance.select(Event.class); assertTrue(rawNoQualifier.isResolvable()); DummyBean.resetCounters(); rawNoQualifier.get().fire(new Payload()); assertEquals(1, DummyBean.noQualifiers); assertEquals(0, DummyBean.qualifierTimesTriggered); assertEquals(1, DummyBean.timesTriggered); // event with type and no qualifier Instance<Event<Payload>> typedEventNoQualifier = instance.select(new TypeLiteral<Event<Payload>>() { }); assertTrue(typedEventNoQualifier.isResolvable()); DummyBean.resetCounters(); typedEventNoQualifier.get().fire(new Payload()); assertEquals(1, DummyBean.noQualifiers); assertEquals(0, DummyBean.qualifierTimesTriggered); assertEquals(1, DummyBean.timesTriggered); // event with type and qualifier Instance<Event<Payload>> typedEventWithQualifier = instance.select(new TypeLiteral<Event<Payload>>() { }, new DummyQualifier.Literal()); assertTrue(typedEventWithQualifier.isResolvable()); DummyBean.resetCounters(); typedEventWithQualifier.get().fire(new Payload()); assertEquals(1, DummyBean.noQualifiers); assertEquals(1, DummyBean.qualifierTimesTriggered); assertEquals(1, DummyBean.timesTriggered); }
Example 3
Source File: AlternativePriorityAnnotationTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test public void testAnnotationWorks() { Instance<Object> instance = CDI.current().select(Object.class); assertTrue(instance.select(Foo.class).isResolvable()); assertTrue(instance.select(AlternativeClassBean.class).isResolvable()); assertTrue(instance.select(AlternativeProducerFieldBean.class).isResolvable()); assertTrue(instance.select(AlternativeProducerMethodBean.class).isResolvable()); assertTrue(instance.select(TheUltimateImpl.class).isResolvable()); Instance<MyInterface> interfaceInstance = instance.select(MyInterface.class); assertTrue(interfaceInstance.isResolvable()); MyInterface actualImpl = interfaceInstance.get(); assertEquals(TheUltimateImpl.class.getSimpleName(), actualImpl.ping()); }