Java Code Examples for org.jboss.weld.environment.se.Weld#initialize()
The following examples show how to use
org.jboss.weld.environment.se.Weld#initialize() .
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: AmqpSourceTest.java From smallrye-reactive-messaging with Apache License 2.0 | 6 votes |
@Test(expected = DeploymentException.class) public void testConfigGlobalOptionsByCDIMissingBean() { 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("amqp-client-options-name", "myclientoptions") .write(); container = weld.initialize(); }
Example 2
Source File: MissingBackPressureTest.java From smallrye-reactive-messaging with Apache License 2.0 | 6 votes |
@Test public void testWithInterval() throws InterruptedException { KafkaUsage usage = new KafkaUsage(); CountDownLatch latch = new CountDownLatch(1); AtomicInteger expected = new AtomicInteger(0); usage.consumeStrings("output", 10, 10, TimeUnit.SECONDS, latch::countDown, (k, v) -> expected.getAndIncrement()); Weld weld = baseWeld(); addConfig(myKafkaSinkConfig()); weld.addBeanClass(MyOutgoingBean.class); container = weld.initialize(); assertThat(latch.await(1, TimeUnit.MINUTES)).isTrue(); assertThat(expected).hasValueGreaterThanOrEqualTo(10); }
Example 3
Source File: AmqpSinkTest.java From smallrye-reactive-messaging with Apache License 2.0 | 6 votes |
@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 4
Source File: MqttAcknowledgementTest.java From smallrye-reactive-messaging with Apache License 2.0 | 6 votes |
@Test(timeout = 10000) public void testAcknowledgmentWithQoS2AndPayloads() 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 5
Source File: AbstractWeldInitiator.java From weld-junit with Apache License 2.0 | 6 votes |
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 6
Source File: AmqpSourceTest.java From smallrye-reactive-messaging with Apache License 2.0 | 6 votes |
@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 7
Source File: MqttAcknowledgementTest.java From smallrye-reactive-messaging with Apache License 2.0 | 6 votes |
@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 8
Source File: FileApplication.java From tutorials with MIT License | 5 votes |
public static void main(String[] args) { Weld weld = new Weld(); WeldContainer container = weld.initialize(); ImageFileProcessor imageFileProcessor = container.select(ImageFileProcessor.class).get(); System.out.println(imageFileProcessor.openFile("file1.png")); System.out.println(imageFileProcessor.writeFile("file1.png")); System.out.println(imageFileProcessor.saveFile("file1.png")); container.shutdown(); }
Example 9
Source File: MultipleTopicsConsumptionTest.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@Test public void testWithoutClientId() { Clients.clear(); Weld weld = baseWeld(getConfig(null)); weld.addBeanClass(Consumers.class); container = weld.initialize(); Consumers bean = container.getBeanManager().createInstance().select(Consumers.class).get(); await().until(() -> this.container.select(MediatorManager.class).get().isInitialized()); await() .until(() -> this.container.select(MqttConnector.class, ConnectorLiteral.of("smallrye-mqtt")).get().isReady()); assertThat(bean.prices()).isEmpty(); assertThat(bean.products()).isEmpty(); AtomicInteger counter1 = new AtomicInteger(); AtomicInteger counter2 = new AtomicInteger(); new Thread(() -> usage.produceIntegers("prices", 10, null, counter1::getAndIncrement)) .start(); new Thread(() -> usage.produceIntegers("products", 10, null, counter2::getAndIncrement)) .start(); await().atMost(2, TimeUnit.MINUTES).until(() -> bean.products().size() >= 10); await().atMost(2, TimeUnit.MINUTES).until(() -> bean.prices().size() >= 10); }
Example 10
Source File: GreeterTest.java From ee8-sandbox with Apache License 2.0 | 5 votes |
@Test public void bootstrapWeldContainer() { Weld weld = new Weld(); try (WeldContainer container = weld.initialize()) { Greeter greeter = container.select(Greeter.class).get(); assertTrue(greeter != null); } }
Example 11
Source File: DynamicMqttTopicSourceTest.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@Test public void testWithDashInExpression() { Weld weld = baseWeld(getConfig("/app/#")); weld.addBeanClass(DynamicTopicApp.class); container = weld.initialize(); awaitAndVerify(); }
Example 12
Source File: AmqpLinkTest.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@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 13
Source File: MetadataPropagationTest.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
private <T> void deploy(MapBasedConfig config, Class<T> clazz) { if (config != null) { config.write(); } else { MapBasedConfig.clear(); } Weld weld = baseWeld(); weld.addBeanClass(clazz); container = weld.initialize(); }
Example 14
Source File: Installer.java From CodeDefenders with GNU Lesser General Public License v3.0 | 5 votes |
/** * Sets up the {@link InitialContext} for a given configuration. * <p> * Also adds the database {@link DataSource} to the initial context. * * @param configurations the configuration used to set the initial context. * @throws NamingException when setting the initial context fails. */ private static void setupInitialContext(Properties configurations) throws NamingException { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); InitialContext ic = new InitialContext(); ic.createSubcontext("java:"); ic.createSubcontext("java:comp"); ic.createSubcontext("java:comp/env"); ic.createSubcontext("java:comp/env/codedefenders"); // Alessio: Maybe there a better way to do it... for (String propName : configurations.stringPropertyNames()) { logger.info("Setting java:comp/env/codedefenders/" + propName + " = " + configurations.get(propName)); ic.bind("java:comp/env/codedefenders/" + propName, configurations.get(propName)); } ic.createSubcontext("java:comp/env/jdbc"); MysqlDataSource dataSource = new MysqlDataSource(); dataSource.setURL(configurations.getProperty("db.url")); dataSource.setUser(configurations.getProperty("db.username")); dataSource.setPassword(configurations.getProperty("db.password")); ic.bind("java:comp/env/jdbc/codedefenders", dataSource); // Maybe there's a way to provide the beans definition directly here... Weld weld = new Weld(); WeldContainer container = weld.initialize(); // Manually load the dependencies and set the backend in the context, this is only because I cannot inject BeanManager BackendExecutorService backend = container.instance().select(BackendExecutorService.class).get(); ic.bind("java:comp/env/codedefenders/backend", backend); // Weld will be automatically closed at system.exit }
Example 15
Source File: MultipleTopicsConsumptionTest.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@Test public void testWithClientId() { Clients.clear(); Weld weld = baseWeld(getConfig("my-id")); weld.addBeanClass(Consumers.class); container = weld.initialize(); Consumers bean = container.getBeanManager().createInstance().select(Consumers.class).get(); await().until(() -> this.container.select(MediatorManager.class).get().isInitialized()); await() .until(() -> this.container.select(MqttConnector.class, ConnectorLiteral.of("smallrye-mqtt")).get().isReady()); assertThat(bean.prices()).isEmpty(); assertThat(bean.products()).isEmpty(); AtomicInteger counter1 = new AtomicInteger(); AtomicInteger counter2 = new AtomicInteger(); new Thread(() -> usage.produceIntegers("prices", 10, null, counter1::getAndIncrement)) .start(); new Thread(() -> usage.produceIntegers("products", 10, null, counter2::getAndIncrement)) .start(); await().atMost(2, TimeUnit.MINUTES).until(() -> bean.products().size() >= 10); await().atMost(2, TimeUnit.MINUTES).until(() -> bean.prices().size() >= 10); }
Example 16
Source File: DefaultConfigTest.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
private <T> void deploy(MapBasedConfig config, Class<T> clazz) { if (config != null) { config.write(); } else { MapBasedConfig.clear(); } Weld weld = baseWeld(); weld.addBeanClass(clazz); container = weld.initialize(); }
Example 17
Source File: DocumentationTest.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@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 18
Source File: WeldContainerControl.java From deltaspike with Apache License 2.0 | 4 votes |
@Override public synchronized void boot() { weld = new Weld(); weldContainer = weld.initialize(); }
Example 19
Source File: InterceptorIntegrationTest.java From tutorials with MIT License | 4 votes |
@Before public void init() { weld = new Weld(); container = weld.initialize(); }
Example 20
Source File: MailerIT.java From jeeshop with Apache License 2.0 | 4 votes |
@BeforeClass public static void init() { weld = new Weld(); container = weld.initialize(); }