org.jboss.weld.environment.se.Weld Java Examples

The following examples show how to use org.jboss.weld.environment.se.Weld. 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: AwsSnsTestBase.java    From smallrye-reactive-messaging with Apache License 2.0 7 votes vote down vote up
static Weld baseWeld() {
    Weld weld = new Weld();
    // SmallRye config
    ConfigExtension extension = new ConfigExtension();
    weld.addExtension(extension);

    weld.addBeanClass(MediatorFactory.class);
    weld.addBeanClass(MediatorManager.class);
    weld.addBeanClass(InternalChannelRegistry.class);
    weld.addBeanClass(ConfiguredChannelFactory.class);
    weld.addBeanClass(ChannelProducer.class);
    weld.addBeanClass(ExecutionHolder.class);
    weld.addBeanClass(WorkerPoolRegistry.class);
    weld.addExtension(new ReactiveMessagingExtension());

    weld.addBeanClass(SnsConnector.class);
    weld.disableDiscovery();

    return weld;
}
 
Example #2
Source File: JmsTestBase.java    From smallrye-reactive-messaging with Apache License 2.0 7 votes vote down vote up
protected Weld initWithoutConnectionFactory() {
    weld = new Weld();

    // SmallRye config
    ConfigExtension extension = new ConfigExtension();
    weld.addExtension(extension);

    weld.addBeanClass(MediatorFactory.class);
    weld.addBeanClass(MediatorManager.class);
    weld.addBeanClass(InternalChannelRegistry.class);
    weld.addBeanClass(ConfiguredChannelFactory.class);
    weld.addBeanClass(ChannelProducer.class);
    weld.addBeanClass(ExecutionHolder.class);
    weld.addBeanClass(WorkerPoolRegistry.class);
    weld.addExtension(new ReactiveMessagingExtension());
    weld.addBeanClass(JmsConnector.class);
    weld.disableDiscovery();
    return weld;
}
 
Example #3
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testConfigByCDIIncorrectBean() {
    Weld weld = new Weld();

    weld.addBeanClass(ProducingBean.class);
    weld.addBeanClass(ClientConfigurationBean.class);

    new MapBasedConfig()
            .put("mp.messaging.outgoing.sink.address", "sink")
            .put("mp.messaging.outgoing.sink.connector", AmqpConnector.CONNECTOR_NAME)
            .put("mp.messaging.outgoing.sink.host", host)
            .put("mp.messaging.outgoing.sink.port", port)
            .put("mp.messaging.outgoing.sink.durable", true)
            .put("amqp-username", username)
            .put("amqp-password", password)
            .put("mp.messaging.outgoing.sink.client-options-name", "dummyoptionsnonexistent")
            .write();

    container = weld.initialize();
}
 
Example #4
Source File: AmqpSourceTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testConfigByCDIMissingBean() {
    Weld weld = new Weld();

    weld.addBeanClass(ConsumptionBean.class);
    weld.addBeanClass(ExecutionHolder.class);

    new MapBasedConfig()
            .put("mp.messaging.incoming.data.address", "data")
            .put("mp.messaging.incoming.data.connector", AmqpConnector.CONNECTOR_NAME)
            .put("mp.messaging.incoming.data.host", host)
            .put("mp.messaging.incoming.data.port", port)
            .put("amqp-username", username)
            .put("amqp-password", password)
            .put("mp.messaging.incoming.data.client-options-name", "myclientoptions")
            .write();

    container = weld.initialize();
}
 
Example #5
Source File: AmqpSourceTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testConfigByCDIIncorrectBean() {
    Weld weld = new Weld();

    weld.addBeanClass(ConsumptionBean.class);
    weld.addBeanClass(ClientConfigurationBean.class);
    weld.addBeanClass(ExecutionHolder.class);

    new MapBasedConfig()
            .put("mp.messaging.incoming.data.address", "data")
            .put("mp.messaging.incoming.data.connector", AmqpConnector.CONNECTOR_NAME)
            .put("mp.messaging.incoming.data.host", host)
            .put("mp.messaging.incoming.data.port", port)
            .put("amqp-username", username)
            .put("amqp-password", password)
            .put("mp.messaging.incoming.data.client-options-name", "dummyoptionsnonexistent")
            .write();

    container = weld.initialize();
}
 
Example #6
Source File: AmqpSourceTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testConfigGlobalOptionsByCDIIncorrectBean() {
    Weld weld = new Weld();

    weld.addBeanClass(ConsumptionBean.class);
    weld.addBeanClass(ClientConfigurationBean.class);
    weld.addBeanClass(ExecutionHolder.class);

    new MapBasedConfig()
            .put("mp.messaging.incoming.data.address", "data")
            .put("mp.messaging.incoming.data.connector", AmqpConnector.CONNECTOR_NAME)
            .put("mp.messaging.incoming.data.host", host)
            .put("mp.messaging.incoming.data.port", port)
            .put("amqp-username", username)
            .put("amqp-password", password)
            .put("amqp-client-options-name", "dummyoptionsnonexistent")
            .write();

    container = weld.initialize();
}
 
Example #7
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test
public void testABeanProducingMessagesSentToAMQPWithOutboundMetadataUsingNonAnonymousSender()
        throws InterruptedException {
    Weld weld = new Weld();

    CountDownLatch latch = new CountDownLatch(10);
    usage.consumeIntegers("sink-foo",
            v -> latch.countDown());

    weld.addBeanClass(ProducingBeanUsingOutboundMetadata.class);

    new MapBasedConfig()
            .put("mp.messaging.outgoing.sink.address", "sink-foo")
            .put("mp.messaging.outgoing.sink.connector", AmqpConnector.CONNECTOR_NAME)
            .put("mp.messaging.outgoing.sink.host", host)
            .put("mp.messaging.outgoing.sink.port", port)
            .put("mp.messaging.outgoing.sink.durable", true)
            .put("mp.messaging.outgoing.sink.use-anonymous-sender", false)
            .put("amqp-username", username)
            .put("amqp-password", password)
            .write();

    container = weld.initialize();

    assertThat(latch.await(1, TimeUnit.MINUTES)).isTrue();
}
 
Example #8
Source File: WebRouteObserversTest.java    From weld-vertx with Apache License 2.0 6 votes vote down vote up
@Before
public void init(TestContext context) throws InterruptedException {
    vertx = Vertx.vertx();
    Async async = context.async();
    Weld weld = WeldVerticle.createDefaultWeld().disableDiscovery().beanClasses(HelloRouteObserver.class, PaymentObserverResource.class,
            SayHelloService.class, PaymentService.class, RequestHelloService.class);
    WeldWebVerticle weldVerticle = new WeldWebVerticle(weld);
    vertx.deployVerticle(weldVerticle, deploy -> {
        if (deploy.succeeded()) {
            // Configure the router after Weld bootstrap finished
            vertx.createHttpServer().requestHandler(weldVerticle.createRouter()::accept).listen(8080, (listen) -> {
                if (listen.succeeded()) {
                    async.complete();
                } else {
                    context.fail(listen.cause());
                }
            });
        } else {
            context.fail(deploy.cause());
        }
    });
    SYNCHRONIZER.clear();
}
 
Example #9
Source File: WeldInitiator.java    From weld-junit with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            Weld weld = WeldInitiator.this.weld;
            if (weld == null) {
                // Null in case of fromTestPackage() is used
                weld = createWeld().addPackage(false, description.getTestClass());
            }
            initWeldContainer(weld);
            try {
                base.evaluate();
            } finally {
                shutdownWeldContainer();
            }
        }
    };
}
 
Example #10
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testConfigByCDIMissingBean() {
    Weld weld = new Weld();

    weld.addBeanClass(ProducingBean.class);

    new MapBasedConfig()
            .put("mp.messaging.outgoing.sink.address", "sink")
            .put("mp.messaging.outgoing.sink.connector", AmqpConnector.CONNECTOR_NAME)
            .put("mp.messaging.outgoing.sink.host", host)
            .put("mp.messaging.outgoing.sink.port", port)
            .put("mp.messaging.outgoing.sink.durable", true)
            .put("amqp-username", username)
            .put("amqp-password", password)
            .put("mp.messaging.outgoing.sink.client-options-name", "myclientoptions")
            .write();

    container = weld.initialize();
}
 
Example #11
Source File: EventbusTestBase.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
static Weld baseWeld() {
    Weld weld = new Weld();
    weld.addBeanClass(MediatorFactory.class);
    weld.addBeanClass(MediatorManager.class);
    weld.addBeanClass(InternalChannelRegistry.class);
    weld.addBeanClass(ConfiguredChannelFactory.class);
    weld.addBeanClass(ExecutionHolder.class);
    weld.addBeanClass(WorkerPoolRegistry.class);
    weld.addExtension(new ReactiveMessagingExtension());
    weld.addBeanClass(VertxEventBusConnector.class);

    weld.addExtension(new io.smallrye.config.inject.ConfigExtension());

    weld.disableDiscovery();
    return weld;
}
 
Example #12
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test(expected = DeploymentException.class)
@Ignore("Failing on CI - need to be investigated")
public void testConfigGlobalOptionsByCDIMissingBean() {
    Weld weld = new Weld();

    weld.addBeanClass(ProducingBean.class);

    new MapBasedConfig()
            .put("mp.messaging.outgoing.sink.address", "sink")
            .put("mp.messaging.outgoing.sink.connector", AmqpConnector.CONNECTOR_NAME)
            .put("mp.messaging.outgoing.sink.host", host)
            .put("mp.messaging.outgoing.sink.port", port)
            .put("mp.messaging.outgoing.sink.durable", true)
            .put("amqp-username", username)
            .put("amqp-password", password)
            .put("amqp-client-options-name", "dummyoptionsnonexistent")
            .write();

    container = weld.initialize();
}
 
Example #13
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test(expected = DeploymentException.class)
@Ignore("Failing on CI - to be investigated")
public void testConfigGlobalOptionsByCDIIncorrectBean() {
    Weld weld = new Weld();

    weld.addBeanClass(ProducingBean.class);
    weld.addBeanClass(ClientConfigurationBean.class);

    new MapBasedConfig()
            .put("mp.messaging.outgoing.sink.address", "sink")
            .put("mp.messaging.outgoing.sink.connector", AmqpConnector.CONNECTOR_NAME)
            .put("mp.messaging.outgoing.sink.host", host)
            .put("mp.messaging.outgoing.sink.port", port)
            .put("mp.messaging.outgoing.sink.durable", true)
            .put("amqp-username", username)
            .put("amqp-password", password)
            .put("amqp-client-options-name", "dummyoptionsnonexistent")
            .write();

    container = weld.initialize();
}
 
Example #14
Source File: MqttTestBase.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
static Weld baseWeld(MapBasedConfig config) {
    addConfig(config);
    Weld weld = new Weld();
    weld.disableDiscovery();
    weld.addBeanClass(MediatorFactory.class);
    weld.addBeanClass(MediatorManager.class);
    weld.addBeanClass(InternalChannelRegistry.class);
    weld.addBeanClass(ConfiguredChannelFactory.class);
    weld.addBeanClass(WorkerPoolRegistry.class);
    weld.addBeanClass(ExecutionHolder.class);
    weld.addPackages(EmitterImpl.class.getPackage());
    weld.addExtension(new ReactiveMessagingExtension());
    weld.addBeanClass(MqttConnector.class);

    // Add SmallRye Config
    weld.addExtension(new io.smallrye.config.inject.ConfigExtension());

    return weld;
}
 
Example #15
Source File: KafkaTestBase.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
public static Weld baseWeld() {
    Weld weld = new Weld();

    // SmallRye config
    ConfigExtension extension = new ConfigExtension();
    weld.addExtension(extension);

    weld.addBeanClass(MediatorFactory.class);
    weld.addBeanClass(MediatorManager.class);
    weld.addBeanClass(InternalChannelRegistry.class);
    weld.addBeanClass(ConfiguredChannelFactory.class);
    weld.addBeanClass(ChannelProducer.class);
    weld.addBeanClass(ExecutionHolder.class);
    weld.addBeanClass(WorkerPoolRegistry.class);
    weld.addExtension(new ReactiveMessagingExtension());

    weld.addBeanClass(KafkaConnector.class);
    weld.disableDiscovery();
    return weld;
}
 
Example #16
Source File: DocumentationTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test
public void testMessageKafkaPriceConsumer() throws InterruptedException {
    MapBasedConfig config = getConsumerConfiguration();
    Weld weld = baseWeld();
    addConfig(config);
    weld.addBeanClass(KafkaPriceMessageConsumer.class);
    weld.disableDiscovery();
    container = weld.initialize();

    KafkaPriceMessageConsumer consumer = container.select(KafkaPriceMessageConsumer.class).get();

    // TODO we need some readiness support in the connector
    Thread.sleep(1000);

    KafkaUsage usage = new KafkaUsage();
    AtomicInteger count = new AtomicInteger();
    usage.produceDoubles(50, null, () -> new ProducerRecord<>("prices", count.incrementAndGet() * 1.0));

    await().until(() -> consumer.list().size() >= 50);
}
 
Example #17
Source File: AsyncRouteObserversTest.java    From weld-vertx with Apache License 2.0 6 votes vote down vote up
@Before
public void init(TestContext context) throws InterruptedException {
    vertx = Vertx.vertx();
    Async async = context.async();
    Weld weld = WeldVerticle.createDefaultWeld().disableDiscovery().beanClasses(AsyncRouteObserver.class, BlockingService.class)
            .packages(AsyncReference.class);
    WeldWebVerticle weldVerticle = new WeldWebVerticle(weld);
    vertx.deployVerticle(weldVerticle, deploy -> {
        if (deploy.succeeded()) {
            // Configure the router after Weld bootstrap finished
            vertx.createHttpServer().requestHandler(weldVerticle.createRouter()::accept).listen(8080, (listen) -> {
                if (listen.succeeded()) {
                    async.complete();
                } else {
                    context.fail(listen.cause());
                }
            });
        } else {
            context.fail(deploy.cause());
        }
    });
    SYNCHRONIZER.clear();
}
 
Example #18
Source File: AbstractWeldInitiator.java    From weld-junit with Apache License 2.0 6 votes vote down vote up
protected WeldContainer initWeldContainer(Weld weld) {
    // Register mock injection services if needed
    if (!resources.isEmpty()) {
        weld.addServices(new MockResourceInjectionServices(resources));
    }
    if (ejbFactory != null) {
        weld.addServices(new MockEjbInjectionServices(ejbFactory));
    }
    if (persistenceContextFactory != null || persistenceUnitFactory != null) {
        weld.addServices(new MockJpaInjectionServices(persistenceUnitFactory, persistenceContextFactory));
    }
    // Init the container
    container = weld.initialize();
    if (extension != null) {
        extension.activateContexts();
    }
    injectInstances();
    return container;
}
 
Example #19
Source File: PubSubTestBase.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
static Weld baseWeld() {
    final Weld weld = new Weld();

    weld.addExtension(new ConfigExtension());
    weld.addBeanClass(MediatorFactory.class);
    weld.addBeanClass(MediatorManager.class);
    weld.addBeanClass(InternalChannelRegistry.class);
    weld.addBeanClass(ConfiguredChannelFactory.class);
    weld.addBeanClass(ChannelProducer.class);
    weld.addBeanClass(ExecutionHolder.class);
    weld.addBeanClass(WorkerPoolRegistry.class);
    weld.addExtension(new ReactiveMessagingExtension());

    weld.addBeanClass(PubSubManager.class);
    weld.addBeanClass(PubSubConnector.class);
    weld.disableDiscovery();

    return weld;
}
 
Example #20
Source File: DynamicMqttSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test
public void testABeanProducingMessagesSentToMQTT() {
    Weld weld = baseWeld(getConfig());
    weld.addBeanClass(DynamicTopicProducingBean.class);

    final List<MqttMessage> rawMessages = new ArrayList<>(10);
    final List<String> topics = new CopyOnWriteArrayList<>();
    usage.consumeRaw("#", 10, 60, TimeUnit.SECONDS, null,
            (topic, msg) -> {
                topics.add(topic);
                rawMessages.add(msg);
            });

    container = weld.initialize();

    await().atMost(1, TimeUnit.MINUTES).until(() -> topics.size() >= 10);
    assertThat(topics.size()).isEqualTo(10);
    assertThat(rawMessages.size()).isEqualTo(10);
    MqttMessage firstMessage = rawMessages.get(0);
    assertThat(firstMessage.getQos()).isEqualTo(1);
    assertThat(firstMessage.isRetained()).isFalse();
}
 
Example #21
Source File: MqttAcknowledgementTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 10000)
public void testAcknowledgmentWithQoS0AndPayloads() throws InterruptedException {
    Weld weld = baseWeld(getConfig(0));
    weld.addBeanClass(EmitterBean.class);

    CountDownLatch latch = new CountDownLatch(2);
    usage.consumeStrings("test-topic-mqtt", 2, 10, TimeUnit.SECONDS,
            null,
            v -> latch.countDown());

    container = weld.initialize();

    EmitterBean bean = container.getBeanManager().createInstance().select(EmitterBean.class).get();
    bean.sendAndAwait();
    bean.sendMessageAndAwait();
    assertThat(latch.await(1, TimeUnit.MINUTES)).isTrue();
}
 
Example #22
Source File: MqttAcknowledgementTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 10000)
public void testAcknowledgmentWithQoS1AndPayloads() throws InterruptedException {
    Weld weld = baseWeld(getConfig(1));
    weld.addBeanClass(EmitterBean.class);

    CountDownLatch latch = new CountDownLatch(2);
    usage.consumeStrings("test-topic-mqtt", 2, 10, TimeUnit.SECONDS,
            null,
            v -> latch.countDown());

    container = weld.initialize();

    EmitterBean bean = container.getBeanManager().createInstance().select(EmitterBean.class).get();
    bean.sendAndAwait();
    bean.sendMessageAndAwait();
    assertThat(latch.await(1, TimeUnit.MINUTES)).isTrue();
}
 
Example #23
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigGlobalOptionsByCDICorrect() throws InterruptedException {
    Weld weld = new Weld();

    CountDownLatch latch = new CountDownLatch(10);
    usage.consumeIntegers("sink",
            v -> latch.countDown());

    weld.addBeanClass(ProducingBean.class);
    weld.addBeanClass(ClientConfigurationBean.class);

    new MapBasedConfig()
            .put("mp.messaging.outgoing.sink.address", "sink")
            .put("mp.messaging.outgoing.sink.connector", AmqpConnector.CONNECTOR_NAME)
            .put("mp.messaging.outgoing.sink.host", host)
            .put("mp.messaging.outgoing.sink.port", port)
            .put("mp.messaging.outgoing.sink.durable", true)
            .put("amqp-username", username)
            .put("amqp-password", password)
            .put("amqp-client-options-name", "myclientoptions")
            .write();

    container = weld.initialize();

    assertThat(latch.await(1, TimeUnit.MINUTES)).isTrue();
}
 
Example #24
Source File: DocumentationTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test
public void testKafkaPriceMessageProducer() {
    KafkaUsage usage = new KafkaUsage();
    List<Double> list = new CopyOnWriteArrayList<>();
    usage.consumeDoubles("prices", 50, 60, TimeUnit.SECONDS, null, (s, v) -> list.add(v));

    MapBasedConfig config = getProducerConfiguration();
    Weld weld = baseWeld();
    addConfig(config);
    weld.addBeanClass(KafkaPriceMessageProducer.class);
    weld.disableDiscovery();
    container = weld.initialize();

    await().until(() -> list.size() >= 50);
}
 
Example #25
Source File: AmqpFailureHandlerTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
private MyReceiverBean deploy() {
    Weld weld = new Weld();
    weld.addBeanClass(MyReceiverBean.class);

    container = weld.initialize();
    await().until(() -> container.select(MediatorManager.class).get().isInitialized());
    return container.getBeanManager().createInstance().select(MyReceiverBean.class).get();
}
 
Example #26
Source File: DocumentationTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test
public void testKafkaPriceProducer() {
    KafkaUsage usage = new KafkaUsage();
    List<Double> list = new CopyOnWriteArrayList<>();
    usage.consumeDoubles("prices", 50, 60, TimeUnit.SECONDS, null, (s, v) -> list.add(v));

    MapBasedConfig config = getProducerConfiguration();
    Weld weld = baseWeld();
    addConfig(config);
    weld.addBeanClass(KafkaPriceProducer.class);
    weld.disableDiscovery();
    container = weld.initialize();

    await().until(() -> list.size() >= 50);
}
 
Example #27
Source File: RequestHandler.java    From jrestless-examples with Apache License 2.0 5 votes vote down vote up
public RequestHandler() {

		Weld weld = new Weld();
		weld.initialize();

		// configure the application with the resource
		ResourceConfig resourceConfig = new ResourceConfig()
				.register(GatewayFeature.class)
				.packages("com.jrestless.aws.examples");
		init(resourceConfig);
		start();
	}
 
Example #28
Source File: GreeterTest.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
@Test(expected = UnsatisfiedResolutionException.class)
public void bootWeldSeContainer() {
    Extension testExtension = ContainerLifecycleObserver.extensionBuilder()
        .add(afterBeanDiscovery((e) -> System.out.println("Bean discovery completed!")))
        .add(processAnnotatedType().notify((e) -> {
            if (e.getAnnotatedType().getJavaClass().getName().startsWith("com.hantsylab")) {
                e.veto();
            }
        })).build();
    try (WeldContainer container = new Weld().addExtension(testExtension).initialize()) {
        Greeter greeter = container.select(Greeter.class).get();
        //assertTrue(greeter == null);
    }

}
 
Example #29
Source File: AmqpLinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    Weld weld = new Weld();

    weld.addBeanClass(MyProducer.class);
    weld.addBeanClass(MyConsumer.class);

    new MapBasedConfig()
            .put("mp.messaging.outgoing.people-out.connector", AmqpConnector.CONNECTOR_NAME)
            .put("mp.messaging.outgoing.people-out.address", "people")
            .put("mp.messaging.outgoing.people-out.link-name", "people")
            .put("mp.messaging.outgoing.people-out.host", host)
            .put("mp.messaging.outgoing.people-out.port", port)
            .put("mp.messaging.outgoing.people-out.durable", true)
            .put("amqp-username", username)
            .put("amqp-password", password)

            .put("mp.messaging.incoming.people-in.connector", AmqpConnector.CONNECTOR_NAME)
            .put("mp.messaging.incoming.people-in.address", "people")
            .put("mp.messaging.incoming.people-in.link-name", "people")
            .put("mp.messaging.incoming.people-in.host", host)
            .put("mp.messaging.incoming.people-in.port", port)
            .put("mp.messaging.incoming.people-in.durable", true)

            .write();

    container = weld.initialize();
    AmqpConnector connector = container.getBeanManager().createInstance().select(AmqpConnector.class,
            ConnectorLiteral.of(AmqpConnector.CONNECTOR_NAME)).get();
    await().until(() -> connector.isReady("people-in"));

    MyProducer producer = container.getBeanManager().createInstance().select(MyProducer.class).get();
    producer.run();

    MyConsumer consumer = container.getBeanManager().createInstance().select(MyConsumer.class).get();
    await()
            .atMost(1, TimeUnit.MINUTES)
            .until(() -> consumer.list().size() == 3);
    assertThat(consumer.list()).containsExactly("Luke", "Leia", "Han");
}
 
Example #30
Source File: EventBusSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test
public void testABeanProducingMessagesSentToEventBus() {
    Weld weld = baseWeld();
    weld.addBeanClass(ProducingBean.class);
    weld.addBeanClass(VertxProducer.class);
    addConfig(getConfig());
    container = weld.initialize();
    ProducingBean bean = container.getBeanManager().createInstance().select(ProducingBean.class).get();

    await().until(() -> bean.messages().size() == 10);
    assertThat(bean.messages().size()).isEqualTo(10);
}