@Test public void testAsyncReference() throws InterruptedException, ExecutionException { BlockingFoo.reset(); BlockingBarProducer.reset(); Boss boss = weld.select(Boss.class).get(); assertFalse(boss.foo.isDone()); assertEquals("", boss.foo.orElse(BlockingFoo.EMPTY).getMessage()); boss.foo.ifDone((r, t) -> fail("BlockingFoo not complete yet")); BlockingFoo.complete("Foo"); BlockingBarProducer.complete(152); Awaitility.await().atMost(Timeouts.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS).until(() -> boss.isReadyToTest()); assertEquals("Foo", boss.foo.get().getMessage()); boss.foo.ifDone((r, t) -> assertEquals("Foo", r.getMessage())); Throwable cause = boss.unsatisfied.cause(); assertNotNull(cause); assertTrue(cause instanceof UnsatisfiedResolutionException); boss.unsatisfied.ifDone((r, t) -> { assertNotNull(t); assertTrue(t instanceof UnsatisfiedResolutionException); }); assertNull(boss.noBing.get()); assertEquals(55, boss.juicyBing.get().value); assertNull(boss.juicyBar.cause()); assertEquals(152, boss.juicyBar.get().code); assertTrue(BlockingBarProducer.PRODUCER_USED.get()); }
/** * Creates a {@link Bean}. * * @param <T> * The type of the repository. * @param repositoryType * The class representing the repository. * @param beanManager * The BeanManager instance. * @return The bean. */ private <T> Bean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers, BeanManager beanManager) { // Determine the amazondbclient bean which matches the qualifiers of the // repository. Bean<AmazonDynamoDB> amazonDynamoDBBean = amazonDynamoDBs.get(qualifiers); // Determine the dynamo db mapper configbean which matches the // qualifiers of the repository. Bean<DynamoDBMapperConfig> dynamoDBMapperConfigBean = dbMapperConfigs.get(qualifiers); if (amazonDynamoDBBean == null) { throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.", AmazonDynamoDBClient.class.getName(), qualifiers)); } Bean<DynamoDBOperations> dynamoDBOperationsBean = dynamoDBOperationss.get(qualifiers); // Construct and return the repository bean. return new DynamoDBRepositoryBean<T>(beanManager, amazonDynamoDBBean, dynamoDBMapperConfigBean,dynamoDBOperationsBean,qualifiers, repositoryType); }
private <T> CdiRepositoryBean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers, BeanManager beanManager) { Bean<DatasourceMapper> dsBean = dsMap.get(qualifiers); if (dsBean == null) { throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.", DatasourceMapper.class.getName(), qualifiers)); } return new SnowdropRepositoryBean<>(dsBean, qualifiers, repositoryType, beanManager, getCustomImplementationDetector()); }
@Override protected ProducerTemplate findOrCreateCamelTemplate() { return getReferenceByType(cdiContainer.getBeanManager(), CamelContext.class) .orElseThrow( () -> new UnsatisfiedResolutionException("No default Camel context is deployed, " + "cannot create default ProducerTemplate!")) .createProducerTemplate(); }
private static <T extends CamelContext> T selectContext(String name, Instance<T> instance) { for (T context : instance) { if (name.equals(context.getName())) { return context; } } throw new UnsatisfiedResolutionException("No Camel context with name [" + name + "] is deployed!"); }
private CamelPostProcessorHelper getPostProcessorHelper(String contextName) { CamelPostProcessorHelper helper = postProcessorHelpers.get(contextName); if (helper == null) { CamelContext context = getOrLookupCamelContext(contextName); if (context == null) { throw new UnsatisfiedResolutionException("No Camel context with name [" + contextName + "] is deployed!"); } helper = new CamelPostProcessorHelper(context); postProcessorHelpers.put(contextName, helper); } return helper; }
private <T> Bean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers, BeanManager beanManager) { Bean<SolrOperations> solrOperationBeans = this.solrOperationsMap.get(qualifiers.toString()); if (solrOperationBeans == null) { throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.", SolrOperations.class.getName(), qualifiers)); } return new SolrRepositoryBean<T>(solrOperationBeans, qualifiers, repositoryType, beanManager, getCustomImplementationDetector()); }
@Override public T get() { if (isAmbiguous()) { throw new AmbiguousResolutionException(); } if (isUnsatisfied()) { throw new UnsatisfiedResolutionException(); } return instance; }
private <T extends Repository> Bean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers, BeanManager beanManager) { logger.debug(String.format("Creating a Repository Bean for interface '%s'.", repositoryType)); Bean<EntityManager> entityManagerBean = entityManagers.get(qualifiers); if (entityManagerBean == null) { throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.", EntityManager.class.getName(), qualifiers)); } return new SimpleRepositoryBean<>(qualifiers, repositoryType, beanManager, entityManagerBean); }
@Override protected ProducerTemplate findOrCreateCamelTemplate() { return getReferenceByType(container.getBeanManager(), CamelContext.class) .orElseThrow( () -> new UnsatisfiedResolutionException("No default Camel context is deployed, " + "cannot create default ProducerTemplate!")) .createProducerTemplate(); }
private <T> Bean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers, BeanManager beanManager) { Bean<SolrOperations> solrOperationBeans = this.solrOperationsMap.get(qualifiers.toString()); if (solrOperationBeans == null) { throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.", SolrOperations.class.getName(), qualifiers)); } return new SolrRepositoryBean<T>(solrOperationBeans, qualifiers, repositoryType, beanManager); }
@Override public Object getInjectableReference(final InjectionPoint injectionPoint, final CreationalContext<?> ctx) { Asserts.assertNotNull(injectionPoint, "injectionPoint parameter"); if(injectionPoint == null) { return null; } final BeanManagerImpl parentBm = getParentBm(); final Boolean existing = USE_PARENT_BM.get(); if (existing != null && existing) { // shortcut the whole logic to keep the threadlocal set up correctly if (parentBm == null) { return null; } return parentBm.getInjectableReference(injectionPoint, ctx); } // we can do it cause there is caching but we shouldn't - easy way to overide OWB actually final Bean<Object> injectedBean = (Bean<Object>)getInjectionResolver().getInjectionPointBean(injectionPoint); try { if (parentBm != null && injectedBean != null && injectedBean == parentBm.getInjectionResolver().getInjectionPointBean(injectionPoint)) { USE_PARENT_BM.set(true); try { return parentBm.getInjectableReference(injectionPoint, ctx); } finally { USE_PARENT_BM.remove(); } } } catch (final UnsatisfiedResolutionException ure) { // skip, use this bean } return super.getInjectableReference(injectionPoint, ctx); }
private CamelContext getOrLookupCamelContext(String contextName) { // TODO: proper support for custom context qualifiers return getReferenceByType(manager, CamelContext.class, contextName.isEmpty() ? DEFAULT : ContextName.Literal.of(contextName)) .orElseThrow(() -> new UnsatisfiedResolutionException("No Camel context with name [" + contextName + "] is deployed!")); }
/** * Test bad resolver */ @Test(expected = UnsatisfiedResolutionException.class) public void testDataServiceExceptionOnUnknownResolver() { System.out.println("failResolveDataService"); getResolver("foo"); }
private CamelContext getOrLookupCamelContext(String contextName) { // TODO: proper support for custom context qualifiers return getReferenceByType(manager, CamelContext.class, contextName.isEmpty() ? Default.Literal.INSTANCE : ContextName.Literal.of(contextName)) .orElseThrow(() -> new UnsatisfiedResolutionException("No Camel context with name [" + contextName + "] is deployed!")); }