javax.enterprise.inject.spi.DeploymentException Java Examples

The following examples show how to use javax.enterprise.inject.spi.DeploymentException. 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: ConfigRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public void validateConfigProperties(Map<String, Set<String>> properties) {
    Config config = ConfigProvider.getConfig();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    if (cl == null) {
        cl = ConfigRecorder.class.getClassLoader();
    }
    for (Entry<String, Set<String>> entry : properties.entrySet()) {
        Set<String> propertyTypes = entry.getValue();
        for (String propertyType : propertyTypes) {
            Class<?> propertyClass = load(propertyType, cl);
            // For parameterized types and arrays, we only check if the property config exists without trying to convert it
            if (propertyClass.isArray() || propertyClass.getTypeParameters().length > 0) {
                propertyClass = String.class;
            }
            try {
                if (!config.getOptionalValue(entry.getKey(), propertyClass).isPresent()) {
                    throw new DeploymentException(
                            "No config value of type " + entry.getValue() + " exists for: " + entry.getKey());
                }
            } catch (IllegalArgumentException e) {
                throw new DeploymentException(e);
            }
        }
    }
}
 
Example #2
Source File: NamedFactoryTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithNonMatchingConnectionFactory() {
    initWithoutConnectionFactory().addBeanClasses(FooConnectionFactoryBean.class);
    Map<String, Object> map = new HashMap<>();
    map.put("mp.messaging.connector." + JmsConnector.CONNECTOR_NAME + ".connection-factory-name", "bar");
    map.put("mp.messaging.outgoing.queue-one.connector", JmsConnector.CONNECTOR_NAME);
    map.put("mp.messaging.incoming.jms.connector", JmsConnector.CONNECTOR_NAME);
    map.put("mp.messaging.incoming.jms.destination", "queue-one");
    MapBasedConfig config = new MapBasedConfig(map);
    addConfig(config);
    try {
        deploy(PayloadConsumerBean.class, ProducerBean.class);
    } catch (DeploymentException de) {
        assertThat(de).hasCauseInstanceOf(IllegalStateException.class)
                .hasMessageContaining("javax.jms.ConnectionFactory bean named");
    }
}
 
Example #3
Source File: NamedFactoryTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithoutConnectionFactoryAndNameSet() {
    initWithoutConnectionFactory();
    Map<String, Object> map = new HashMap<>();
    map.put("mp.messaging.connector." + JmsConnector.CONNECTOR_NAME + ".connection-factory-name", "foo");
    map.put("mp.messaging.outgoing.queue-one.connector", JmsConnector.CONNECTOR_NAME);
    map.put("mp.messaging.incoming.jms.connector", JmsConnector.CONNECTOR_NAME);
    map.put("mp.messaging.incoming.jms.destination", "queue-one");
    MapBasedConfig config = new MapBasedConfig(map);
    addConfig(config);
    try {
        deploy(PayloadConsumerBean.class, ProducerBean.class);
    } catch (DeploymentException de) {
        assertThat(de).hasCauseInstanceOf(IllegalStateException.class)
                .hasMessageContaining("javax.jms.ConnectionFactory bean named");
    }
}
 
Example #4
Source File: NamedFactoryTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithoutConnectionFactoryAndNoNameSet() {
    initWithoutConnectionFactory();
    Map<String, Object> map = new HashMap<>();
    map.put("mp.messaging.outgoing.queue-one.connector", JmsConnector.CONNECTOR_NAME);
    map.put("mp.messaging.incoming.jms.connector", JmsConnector.CONNECTOR_NAME);
    map.put("mp.messaging.incoming.jms.destination", "queue-one");
    MapBasedConfig config = new MapBasedConfig(map);
    addConfig(config);
    try {
        deploy(PayloadConsumerBean.class, ProducerBean.class);
    } catch (DeploymentException de) {
        assertThat(de).hasCauseInstanceOf(IllegalStateException.class)
                .hasMessageContaining("javax.jms.ConnectionFactory bean");
    }
}
 
Example #5
Source File: InvalidBindingTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test
public void testMissingMerge() {
    addBeanClass(MySource1Bean.class);
    addBeanClass(MySink1Bean.class);
    addBeanClass(MySource2Bean.class);

    try {
        initialize();
        fail("Invalid weaving not detected");
    } catch (DeploymentException e) {
        assertThat(e.getCause())
                .hasCauseInstanceOf(WeavingException.class)
                .hasMessageContaining("`source`")
                .hasMessageContaining("#sink")
                .hasMessageContaining("(2)");
    }
}
 
Example #6
Source File: InvalidBindingTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test
public void testMissingBroadcast() {
    addBeanClass(MySink2Bean.class);
    addBeanClass(MySink1Bean.class);
    addBeanClass(MyUnicastSourceBean.class);

    try {
        initialize();
        fail("Invalid weaving not detected");
    } catch (DeploymentException e) {
        e.getCause().printStackTrace();
        assertThat(e.getCause())
                .isInstanceOf(DeploymentException.class)
                .hasCauseInstanceOf(WeavingException.class)
                .hasMessageContaining("source")
                .hasMessageContaining("Synchronous");
    }
}
 
Example #7
Source File: CacheProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@BuildStep
@Record(RUNTIME_INIT)
void recordCachesBuild(CombinedIndexBuildItem combinedIndex, BeanContainerBuildItem beanContainer, CacheConfig config,
        CaffeineCacheBuildRecorder caffeineRecorder,
        List<AdditionalCacheNameBuildItem> additionalCacheNames,
        Optional<ManagedExecutorInitializedBuildItem> managedExecutorInitialized) {
    Set<String> cacheNames = getCacheNames(combinedIndex.getIndex());
    for (AdditionalCacheNameBuildItem additionalCacheName : additionalCacheNames) {
        cacheNames.add(additionalCacheName.getName());
    }
    switch (config.type) {
        case CacheDeploymentConstants.CAFFEINE_CACHE_TYPE:
            Set<CaffeineCacheInfo> cacheInfos = CaffeineCacheInfoBuilder.build(cacheNames, config);
            caffeineRecorder.buildCaches(managedExecutorInitialized.isPresent(), beanContainer.getValue(), cacheInfos);
            break;
        default:
            throw new DeploymentException("Unknown cache type: " + config.type);
    }
}
 
Example #8
Source File: IncomingsTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testInvalidIncomings() {
    addBeanClass(ProducerOnA.class);
    addBeanClass(InvalidBeanWithIncomings.class);

    initialize();
}
 
Example #9
Source File: JmsConnectorTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testWithInvalidOutgoingDestinationType() {
    Map<String, Object> map = new HashMap<>();
    map.put("mp.messaging.outgoing.queue-one.connector", JmsConnector.CONNECTOR_NAME);
    map.put("mp.messaging.outgoing.queue-one.destination-type", "invalid");
    map.put("mp.messaging.incoming.jms.connector", JmsConnector.CONNECTOR_NAME);
    map.put("mp.messaging.incoming.jms.destination-type", "queue");
    MapBasedConfig config = new MapBasedConfig(map);
    addConfig(config);
    deploy(PayloadConsumerBean.class, ProducerBean.class);
}
 
Example #10
Source File: MissingConnectorTest.java    From microprofile-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Deployment(managed = false, name = "missing-stream")
@ShouldThrowException(value = DeploymentException.class, testable = true)
public static Archive<JavaArchive> missingStreamDeployment() {
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class)
        .addClasses(MyProcessorWithBadStreamName.class, DummyConnector.class, ArchiveExtender.class)
        .addAsManifestResource(MissingConnectorTest.class.getResource("connector-config.properties"), "microprofile-config.properties")
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

    ServiceLoader.load(ArchiveExtender.class).iterator().forEachRemaining(ext -> ext.extend(archive));
    return archive;
}
 
Example #11
Source File: JmsConnectorTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testWithInvalidIncomingDestinationType() {
    Map<String, Object> map = new HashMap<>();
    map.put("mp.messaging.outgoing.queue-one.connector", JmsConnector.CONNECTOR_NAME);
    map.put("mp.messaging.incoming.jms.connector", JmsConnector.CONNECTOR_NAME);
    map.put("mp.messaging.incoming.jms.destination-type", "invalid");
    MapBasedConfig config = new MapBasedConfig(map);
    addConfig(config);
    deploy(PayloadConsumerBean.class, ProducerBean.class);
}
 
Example #12
Source File: InvalidConfigurationTest.java    From microprofile-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Deployment(managed = false, name = "empty-incoming")
@ShouldThrowException(value = DeploymentException.class, testable = true)
public static Archive<JavaArchive> emptyIncoming() {
  JavaArchive archive = ShrinkWrap.create(JavaArchive.class)
    .addClasses(BeanWithEmptyIncoming.class, ArchiveExtender.class)
    .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

  ServiceLoader.load(ArchiveExtender.class).iterator().forEachRemaining(ext -> ext.extend(archive));
  return archive;
}
 
Example #13
Source File: MissingConnectorTest.java    From microprofile-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Deployment(managed = false, name = "missing-connector")
@ShouldThrowException(value = DeploymentException.class, testable = true)
public static Archive<JavaArchive> missingConnectorDeployment() {
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class)
        .addClasses(MyProcessor.class, ArchiveExtender.class)
        .addAsManifestResource(MissingConnectorTest.class.getResource("connector-config.properties"), "microprofile-config.properties")
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

    ServiceLoader.load(ArchiveExtender.class).iterator().forEachRemaining(ext -> ext.extend(archive));
    return archive;
}
 
Example #14
Source File: BeanInfo.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private Map<MethodInfo, InterceptionInfo> initInterceptedMethods(List<Throwable> errors,
        Consumer<BytecodeTransformer> bytecodeTransformerConsumer, boolean transformUnproxyableClasses) {
    if (!isInterceptor() && isClassBean()) {
        Map<MethodInfo, InterceptionInfo> interceptedMethods = new HashMap<>();
        Map<MethodKey, Set<AnnotationInstance>> candidates = new HashMap<>();

        List<AnnotationInstance> classLevelBindings = new ArrayList<>();
        addClassLevelBindings(target.get().asClass(), classLevelBindings);
        if (!stereotypes.isEmpty()) {
            for (StereotypeInfo stereotype : stereotypes) {
                addClassLevelBindings(stereotype.getTarget(), classLevelBindings);
            }
        }

        Set<MethodInfo> finalMethods = Methods.addInterceptedMethodCandidates(beanDeployment, target.get().asClass(),
                candidates, classLevelBindings, bytecodeTransformerConsumer, transformUnproxyableClasses);
        if (!finalMethods.isEmpty()) {
            errors.add(new DeploymentException(String.format(
                    "Intercepted methods of the bean %s may not be declared final:\n\t- %s", getBeanClass(),
                    finalMethods.stream().map(Object::toString).sorted().collect(Collectors.joining("\n\t- ")))));
            return Collections.emptyMap();
        }

        for (Entry<MethodKey, Set<AnnotationInstance>> entry : candidates.entrySet()) {
            List<InterceptorInfo> interceptors = beanDeployment.getInterceptorResolver()
                    .resolve(InterceptionType.AROUND_INVOKE, entry.getValue());
            if (!interceptors.isEmpty()) {
                interceptedMethods.put(entry.getKey().method, new InterceptionInfo(interceptors, entry.getValue()));
            }
        }
        return interceptedMethods;
    } else {
        return Collections.emptyMap();
    }
}
 
Example #15
Source File: JmsConnectorTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testInvalidSessionMode() {
    Map<String, Object> map = new HashMap<>();
    map.put("mp.messaging.outgoing.queue-one.connector", JmsConnector.CONNECTOR_NAME);
    map.put("mp.messaging.incoming.jms.connector", JmsConnector.CONNECTOR_NAME);
    map.put("mp.messaging.incoming.jms.destination", "queue-one");
    map.put("mp.messaging.incoming.jms.session-mode", "invalid");
    MapBasedConfig config = new MapBasedConfig(map);
    addConfig(config);
    deploy(PayloadConsumerBean.class, ProducerBean.class);
}
 
Example #16
Source File: InvalidConfigurationTest.java    From microprofile-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Deployment(managed = false, name = "empty-outgoing")
@ShouldThrowException(value = DeploymentException.class, testable = true)
public static Archive<JavaArchive> emptyOutgoing() {
  JavaArchive archive = ShrinkWrap.create(JavaArchive.class)
    .addClasses(BeanWithEmptyOutgoing.class, ArchiveExtender.class)
    .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

  ServiceLoader.load(ArchiveExtender.class).iterator().forEachRemaining(ext -> ext.extend(archive));
  return archive;
}
 
Example #17
Source File: InvalidConfigurationTest.java    From microprofile-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Deployment(managed = false, name = "invalid-publisher-method")
@ShouldThrowException(value = DeploymentException.class, testable = true)
public static Archive<JavaArchive> invalidPublisherMethod() {
  JavaArchive archive = ShrinkWrap.create(JavaArchive.class)
    .addClasses(BeanWithBadOutgoingSignature.class, ArchiveExtender.class)
    .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

  ServiceLoader.load(ArchiveExtender.class).iterator().forEachRemaining(ext -> ext.extend(archive));
  return archive;
}
 
Example #18
Source File: BeanDeployment.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private void validateBeans(List<Throwable> errors, List<BeanDeploymentValidator> validators,
        Consumer<BytecodeTransformer> bytecodeTransformerConsumer) {

    Map<String, List<BeanInfo>> namedBeans = new HashMap<>();

    for (BeanInfo bean : beans) {
        if (bean.getName() != null) {
            List<BeanInfo> named = namedBeans.get(bean.getName());
            if (named == null) {
                named = new ArrayList<>();
                namedBeans.put(bean.getName(), named);
            }
            named.add(bean);
        }
        bean.validate(errors, validators, bytecodeTransformerConsumer);
    }

    if (!namedBeans.isEmpty()) {
        for (Entry<String, List<BeanInfo>> entry : namedBeans.entrySet()) {
            if (entry.getValue()
                    .size() > 1) {
                if (Beans.resolveAmbiguity(entry.getValue()) == null) {
                    errors.add(new DeploymentException("Unresolvable ambiguous bean name detected: " + entry.getKey()
                            + "\nBeans:\n" + entry.getValue()
                                    .stream()
                                    .map(Object::toString)
                                    .collect(Collectors.joining("\n"))));
                }
            }
        }
    }
}
 
Example #19
Source File: IncomingsTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testIncomingsWithMissingSourceInStrictMode() {
    System.setProperty(MediatorManager.STRICT_MODE_PROPERTY, "true");
    addBeanClass(ProducerOnB.class);
    addBeanClass(MyBeanUsingMultipleIncomings.class);
    initialize();
}
 
Example #20
Source File: IncomingsTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testEmptyIncomings() {
    addBeanClass(ProducerOnA.class);
    addBeanClass(EmptyIncomings.class);

    initialize();
}
 
Example #21
Source File: IncomingsTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testIncomingsWithInvalidIncoming() {
    addBeanClass(ProducerOnA.class);
    addBeanClass(InvalidBeanWithIncomings.class);

    initialize();
}
 
Example #22
Source File: FinalInterceptedMethodTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailure() {
    Throwable t = container.getFailure();
    assertNotNull(t);
    assertTrue(t instanceof DeploymentException);
    assertTrue(t.getMessage().contains("foo"));
    assertTrue(t.getMessage().contains("bar"));
}
 
Example #23
Source File: InvalidConfigurationTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testIncompleteGraphWithStrictMode() {
    tearDown();
    System.setProperty(STRICT_MODE_PROPERTY, "true");
    setUp();
    addBeanClass(IncompleteGraphBean.class);
    initialize();
}
 
Example #24
Source File: SubscriberShapeTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test
public void testThatWeCanConsumeMessagesFromAMethodReturningSomething() {
    // This case is not supported as it forces blocking acknowledgment.
    // See the MediatorConfiguration class for details.

    initializer.addBeanClasses(BeanConsumingMessagesAndReturningSomething.class);
    try {
        initialize();
        fail("Expected failure - method validation should have failed");
    } catch (DeploymentException e) {
        // Check we have the right cause
        assertThat(e).hasMessageContaining("Invalid method").hasMessageContaining("acknowledgment");
    }
}
 
Example #25
Source File: ChannelInjectionTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonExistentChannel() {
    addBeanClass(SourceBean.class);
    try {
        installInitializeAndGet(BeanInjectedNonExistentChannel.class);
        fail();
    } catch (DeploymentException expected) {
    }
}
 
Example #26
Source File: ChannelInjectionTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonExistentLEgacyChannel() {
    addBeanClass(SourceBean.class);
    try {
        installInitializeAndGet(BeanInjectedNonExistentLegacyChannel.class);
        fail();
    } catch (DeploymentException expected) {
    }
}
 
Example #27
Source File: AwsCommonsProcessor.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
private void checkClasspath(String className, String dependencyName) {
    try {
        Class.forName(className, true, Thread.currentThread().getContextClassLoader());
    } catch (ClassNotFoundException e) {
        throw new DeploymentException(
                "Missing 'software.amazon.awssdk:" + dependencyName + "' dependency on the classpath");
    }
}
 
Example #28
Source File: GrpcServiceBuildItem.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void setBlockingStubClass(ClassType blockingStubClass) {
    if (this.blockingStubClass != null
            && !this.blockingStubClass.name().equals(blockingStubClass.name())) {
        throw new DeploymentException("Invalid gRPC Service - multiple stubs founds for " + name);
    }
    this.blockingStubClass = blockingStubClass;
}
 
Example #29
Source File: InvalidBlockingPublisherShapeTest.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testProduceCompletionStageOfPayload() {
    addBeanClass(BeanReturningCompletionStageOfPayload.class);
    initialize();
}
 
Example #30
Source File: InvalidBlockingPublisherShapeTest.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testProduceUniOfMessage() {
    addBeanClass(BeanReturningUniOfMessage.class);
    initialize();
}