@Override public <T> T getInstance(Class<T> type) { return containerInstance.select(type) .get(); }
@Override public <U> WeldInstance<U> select(Class<U> subtype, Annotation... qualifiers) { checkContainer(); return container.select(subtype, qualifiers); }
@Override public <U> WeldInstance<U> select(Class<U> subtype, Annotation... qualifiers) { checkContainer(); return container.select(subtype, qualifiers); }
@Override public WeldInstance<Object> select(Annotation... qualifiers) { checkContainer(); return container.select(qualifiers); }
@Override public <U> WeldInstance<U> select(TypeLiteral<U> subtype, Annotation... qualifiers) { checkContainer(); return container.select(subtype, qualifiers); }
@Override public <U> WeldInstance<U> select(TypeLiteral<U> subtype, Annotation... qualifiers) { checkContainer(); return container.select(subtype, qualifiers); }
@Override public WeldInstance<Object> select(Annotation... qualifiers) { checkContainer(); return container.select(qualifiers); }
private<T> T getBeanReference(Class<T> clazz) { return container.select(clazz).get(); }
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { // we did our checks in supportsParameter() method, now we can do simple resolution if (getContainerFromStore(extensionContext) != null) { List<Annotation> qualifiers = resolveQualifiers(parameterContext, getContainerFromStore(extensionContext).getBeanManager()); return getContainerFromStore(extensionContext) .select(parameterContext.getParameter().getType(), qualifiers.toArray(new Annotation[qualifiers.size()])).get(); } return null; }
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { // we did our checks in supportsParameter() method, now we can do simple resolution if (getContainerFromStore(extensionContext) != null) { List<Annotation> qualifiers = resolveQualifiers(parameterContext, getContainerFromStore(extensionContext).getBeanManager()); return getContainerFromStore(extensionContext) .select(parameterContext.getParameter().getType(), qualifiers.toArray(new Annotation[qualifiers.size()])).get(); } return null; }
@Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { // if weld container isn't up yet or if its not Method, we don't resolve it if (getContainerFromStore(extensionContext) == null || (!(parameterContext.getDeclaringExecutable() instanceof Method))) { return false; } List<Annotation> qualifiers = resolveQualifiers(parameterContext, getContainerFromStore(extensionContext).getBeanManager()); // if we require explicit parameter injection (via global settings or annotation) and there are no qualifiers we don't resolve it if ((getExplicitInjectionInfoFromStore(extensionContext) || (methodRequiresExplicitParamInjection(parameterContext))) && qualifiers.isEmpty()) { return false; } else { return getContainerFromStore(extensionContext).select(parameterContext.getParameter().getType(), qualifiers.toArray(new Annotation[qualifiers.size()])) .isResolvable(); } }
@Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { // if weld container isn't up yet or if its not Method, we don't resolve it if (getContainerFromStore(extensionContext) == null || (!(parameterContext.getDeclaringExecutable() instanceof Method))) { return false; } List<Annotation> qualifiers = resolveQualifiers(parameterContext, getContainerFromStore(extensionContext).getBeanManager()); // if we require explicit parameter injection (via global settings or annotation) and there are no qualifiers we don't resolve it if ((getExplicitInjectionInfoFromStore(extensionContext) || (methodRequiresExplicitParamInjection(parameterContext))) && qualifiers.isEmpty()) { return false; } else { return getContainerFromStore(extensionContext).select(parameterContext.getParameter().getType(), qualifiers.toArray(new Annotation[qualifiers.size()])) .isResolvable(); } }
@Before public void setUp() throws Exception { // disable git and ssh daemons as they are not needed for the tests System.setProperty("org.uberfire.nio.git.daemon.enabled", "false"); System.setProperty("org.uberfire.nio.git.ssh.enabled", "false"); System.setProperty("org.uberfire.sys.repo.monitor.disabled", "true"); //Bootstrap WELD container weldContainer = new Weld().initialize(); dataModelService = weldContainer.select(DataModelerService.class).get(); moduleService = weldContainer.select(KieModuleService.class).get(); //Ensure URLs use the default:// scheme fs.forceAsDefault(); }
@Test public void testWorkerNonBlocking(TestContext context) throws InterruptedException, ExecutionException { BlockingFoo.reset(); Async async = context.async(); BlockingFoo foo = weld.select(BlockingFoo.class).get(); AsyncWorker.from(vertx).perform(foo::getMessageNonBlocking).thenAccept(m -> { context.assertEquals(BlockingFoo.class.getName(), m); async.complete(); }); } }
@Test public void testConsumers() throws InterruptedException { try (WeldContainer weld = new Weld().disableDiscovery().addExtension(new VertxExtension()).addPackage(false, RegisterConsumersAfterBootstrapTest.class) .initialize()) { Vertx vertx = Vertx.vertx(); try { weld.select(VertxExtension.class).get().registerConsumers(vertx, weld.event()); vertx.eventBus().send(HelloObserver.HELLO_ADDRESS, "hello"); assertEquals("hello", SYNCHRONIZER.poll(Timeouts.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)); } finally { vertx.close(); } } }
@Test public void testAsyncReferenceConstructorInject(TestContext context) throws InterruptedException { BlockingFoo.reset(); Baz baz = weld.select(Baz.class).get(); assertEquals("", baz.getFoo().getMessage()); BlockingFoo.complete("Foo"); Awaitility.await().atMost(Timeouts.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS).until(() -> "Foo".equals(baz.getFoo().getMessage())); }
@Test public void testWorkerInject(TestContext context) throws InterruptedException, ExecutionException { BlockingFoo.reset(); Async async = context.async(); Hello hello = weld.select(Hello.class).get(); hello.hello().thenAccept((m) -> { context.assertEquals("Hello ping!", m); async.complete(); }); context.assertEquals(1, async.count()); BlockingFoo.complete("ping"); }
@Test public void testWorker(TestContext context) throws InterruptedException, ExecutionException { BlockingFoo.reset(); Async async = context.async(); BlockingFoo foo = weld.select(BlockingFoo.class).get(); AsyncWorker.from(vertx).performBlocking(foo::getMessage).thenAccept(m -> { context.assertEquals("ping", m); async.complete(); }); context.assertEquals(1, async.count()); BlockingFoo.complete("ping"); }
@Test public void testAsyncReferenceWorkerCombo(TestContext context) throws InterruptedException, ExecutionException { BlockingAlpha.reset(); Async async = context.async(); HelloCombo hello = weld.select(HelloCombo.class).get(); hello.hello().thenAccept((m) -> { context.assertEquals("Hello ping!", m); async.complete(); }); BlockingAlpha.completeInit(); context.assertEquals(1, async.count()); BlockingAlpha.completeOperation("ping"); }