javax.enterprise.inject.UnsatisfiedResolutionException Java Examples

The following examples show how to use javax.enterprise.inject.UnsatisfiedResolutionException. 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: BeanManagerImpl.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Object getInjectableReference(InjectionPoint ij, CreationalContext<?> ctx) {
    Objects.requireNonNull(ij, "InjectionPoint is null");
    Objects.requireNonNull(ctx, "CreationalContext is null");
    if (ctx instanceof CreationalContextImpl) {
        Set<Bean<?>> beans = getBeans(ij.getType(), ij.getQualifiers().toArray(new Annotation[] {}));
        if (beans.isEmpty()) {
            throw new UnsatisfiedResolutionException();
        }
        InjectableBean<?> bean = (InjectableBean<?>) resolve(beans);
        InjectionPoint prev = InjectionPointProvider.set(ij);
        try {
            return ArcContainerImpl.beanInstanceHandle(bean, (CreationalContextImpl) ctx, false, null).get();
        } finally {
            InjectionPointProvider.set(prev);
        }
    }
    throw new IllegalArgumentException(
            "CreationalContext must be an instances of " + CreationalContextImpl.class);
}
 
Example #2
Source File: AsyncReferenceTest.java    From weld-vertx with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #3
Source File: DynamoDBRepositoryExtension.java    From spring-data-dynamodb with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #4
Source File: InstanceImpl.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private InjectableBean<T> bean() {
    Set<InjectableBean<?>> beans = beans();
    if (beans.isEmpty()) {
        throw new UnsatisfiedResolutionException(
                "No bean found for required type [" + requiredType + "] and qualifiers [" + requiredQualifiers + "]");
    } else if (beans.size() > 1) {
        throw new AmbiguousResolutionException("Beans: " + beans.toString());
    }
    return (InjectableBean<T>) beans.iterator().next();
}
 
Example #5
Source File: SolrRepositoryExtension.java    From dubbox with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example #6
Source File: WebappBeanManager.java    From tomee with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #7
Source File: FlywayExtensionConfigEmptyTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Test
@DisplayName("Injecting (default) flyway should fail if there is no datasource configured")
public void testFlywayNotAvailableWithoutDataSource() {
    assertThrows(UnsatisfiedResolutionException.class, flyway::get);
}
 
Example #8
Source File: FlywayExtensionConfigMissingNamedDataSourceTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Test
@DisplayName("Injecting flyway should fail if the named datasource is missing")
public void testFlywayNotAvailableWithoutDataSource() {
    assertThrows(UnsatisfiedResolutionException.class, flyway::get);
}
 
Example #9
Source File: LiquibaseExtensionConfigMissingNamedDataSourceTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Test
@DisplayName("Injecting liquibase should fail if the named datasource is missing")
public void testLiquibaseNotAvailableWithoutDataSource() {
    assertThrows(UnsatisfiedResolutionException.class, liquibase::get);
}
 
Example #10
Source File: LiquibaseExtensionConfigEmptyTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Test
@DisplayName("Injecting (default) liquibase should fail if there is no datasource configured")
public void testLiquibaseNotAvailableWithoutDataSource() {
    assertThrows(UnsatisfiedResolutionException.class, liquibase::get);
}
 
Example #11
Source File: PackageValidator.java    From microprofile-starter with Apache License 2.0 3 votes vote down vote up
/**
 * Retrieve the single CDI instance which has the classType in the bean definition. It throws the standard CDI exceptions
 * in case when there are no or multiple beans which are a candidate for the type.
 *
 * @param classType a {@link java.lang.Class} representing the required type
 * @param <T>       Generic Type argument
 * @return CDI instance matching the class type and qualifiers (if specified).
 * @throws javax.enterprise.inject.AmbiguousResolutionException When more then 1 bean is found in the match
 * @throws UnsatisfiedResolutionException                       When no bean is found in the match.
 */
public static <T> T retrieveInstance(Class<T> classType) {
    Instance<T> instance = CDI.current().select(classType);
    if (instance.isUnsatisfied()) {
        throw new UnsatisfiedResolutionException(String.format("No bean found for class %s", classType.getName()));
    }
    return instance.get();
}