List of usage examples for org.springframework.context ConfigurableApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:com.gaodashang.demo.SampleWebSocketsApplicationTests.java
@Test public void echoEndpoint() throws Exception { ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) .properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket") .run("--spring.main.web_environment=false"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close();// w ww .ja va 2 s .c om assertEquals(0, count); assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get()); }
From source file:com.gaodashang.demo.echo.CustomContainerWebSocketsApplicationTests.java
@Test public void reverseEndpoint() throws Exception { ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) .properties("websocket.uri:ws://localhost:" + PORT + "/ws/reverse") .run("--spring.main.web_environment=false"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close();/* w ww. j a v a 2 s. co m*/ assertEquals(0, count); assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); }
From source file:com.gaodashang.demo.echo.CustomContainerWebSocketsApplicationTests.java
@Test public void echoEndpoint() throws Exception { ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) .properties("websocket.uri:ws://localhost:" + PORT + "/ws/echo/websocket") .run("--spring.main.web_environment=false"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close();/*from w w w. j ava 2s.c om*/ assertEquals(0, count); assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get()); }
From source file:com.provenance.cloudprovenance.policyengine.cond.XPathProvenanceFunction.java
public void loadSpringBean() { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "beans.xml" }); xpathUtility = (XPathProvenanceConditionUtility) ctx.getBean("xPathProvenanceConditionUtility"); ctx.close();/* w ww .j av a 2 s . c o m*/ }
From source file:com.hellblazer.slp.anubis.EndToEndTest.java
@Override protected void setUp() throws Exception { super.setUp(); log.info("Setting up initial partition"); initialLatch = new CountDownLatch(configs.length); controllerContext = new AnnotationConfigApplicationContext(getControllerConfig()); controller = controllerContext.getBean(TestController.class); controller.cardinality = configs.length; controller.latch = initialLatch;/*from ww w. ja v a2 s. c om*/ memberContexts = createMembers(); log.info("Awaiting initial partition stability"); boolean success = false; connectionSets = new ArrayList<ConnectionSet>(); for (ConfigurableApplicationContext context : memberContexts) { connectionSets.add(context.getBean(ConnectionSet.class)); } try { success = initialLatch.await(120, TimeUnit.SECONDS); assertTrue("Initial partition did not stabilize", success); log.info("Initial partition stable"); partition = new ArrayList<TestNode>(); for (ConfigurableApplicationContext context : memberContexts) { partition.add((TestNode) controller.getNode(context.getBean(Identity.class))); } } finally { if (!success) { tearDown(); } } }
From source file:multibinder.RabbitAndKafkaBinderApplicationTests.java
@Test public void messagingWorks() throws Exception { // passing connection arguments arguments to the embedded Kafka instance ConfigurableApplicationContext context = SpringApplication.run(MultibinderApplication.class, "--spring.cloud.stream.kafka.binder.brokers=" + kafkaEmbedded.getBrokersAsString(), "--spring.cloud.stream.kafka.binder.zkNodes=" + kafkaEmbedded.getZookeeperConnectionString(), "--spring.cloud.stream.bindings.output.producer.requiredGroups=" + this.randomGroup); DirectChannel dataProducer = new DirectChannel(); BinderFactory<?> binderFactory = context.getBean(BinderFactory.class); QueueChannel dataConsumer = new QueueChannel(); ((RabbitMessageChannelBinder) binderFactory.getBinder("rabbit")).bindConsumer("dataOut", this.randomGroup, dataConsumer, new ExtendedConsumerProperties<>(new RabbitConsumerProperties())); ((KafkaMessageChannelBinder) binderFactory.getBinder("kafka")).bindProducer("dataIn", dataProducer, new ExtendedProducerProperties<>(new KafkaProducerProperties())); String testPayload = "testFoo" + this.randomGroup; dataProducer.send(MessageBuilder.withPayload(testPayload).build()); Message<?> receive = dataConsumer.receive(10000); Assert.assertThat(receive, Matchers.notNullValue()); Assert.assertThat(receive.getPayload(), CoreMatchers.equalTo(testPayload)); context.close();/*from w w w.j av a 2s. c o m*/ }