List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext getBean
@Override public Object getBean(String name) throws BeansException
From source file:org.smartfrog.services.anubis.PartitionTest.java
@Override protected void setUp() throws Exception { TestNodeCfg.nextMagic();//from w ww .j a va2 s.com 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; memberContexts = createMembers(); log.info("Awaiting initial partition stability"); boolean success = false; try { success = initialLatch.await(60, TimeUnit.SECONDS); assertTrue("Initial partition did not acheive stability", success); log.info("Initial partition stable"); partition = new ArrayList<TestNode>(); for (AnnotationConfigApplicationContext context : memberContexts) { TestNode member = (TestNode) controller.getNode(context.getBean(Identity.class)); assertNotNull("Can't find node: " + context.getBean(Identity.class), member); partition.add(member); } } finally { if (!success) { tearDown(); } } }
From source file:com.mine.cassandra.sink.CassandraSinkPropertiesTests.java
@Test public void ttlCanBeCustomized() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(context, "ttl:" + 1000); context.register(Conf.class); context.refresh();// ww w . j av a 2 s . c om CassandraSinkProperties properties = context.getBean(CassandraSinkProperties.class); assertThat(properties.getTtl(), equalTo(1000)); context.close(); }
From source file:nl.surfnet.coin.api.GroupProviderConfigurationTest.java
/** * Test to see if the cache works./*from w w w .jav a2 s.c o m*/ * */ @Test public void testCache() throws JsonParseException, JsonMappingException, IOException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(this.getClass()); GroupProviderConfiguration configuration = (GroupProviderConfiguration) ctx .getBean("groupProviderConfiguration"); GroupProviderService groupProviderService = (GroupProviderService) ctx.getBean("groupProviderService"); when(groupProviderService.getAllGroupProviders()).thenReturn(getGroupProviders()); configuration.getAllGroupProviders(); when(groupProviderService.getAllGroupProviders()).thenThrow(new RuntimeException("Cache did not kick in")); /* * This is served from the cache */ configuration.getAllGroupProviders(); }
From source file:com.mine.cassandra.sink.CassandraSinkPropertiesTests.java
@Test public void ingestQueryCanBeCustomized() { String query = "insert into book (isbn, title, author) values (?, ?, ?)"; AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(context, "ingest-query:" + query); context.register(Conf.class); context.refresh();// ww w .j ava 2s . co m CassandraSinkProperties properties = context.getBean(CassandraSinkProperties.class); assertThat(properties.getIngestQuery(), equalTo(query)); context.close(); }
From source file:com.mine.cassandra.sink.CassandraSinkPropertiesTests.java
@Test public void statementExpressionCanBeCustomized() { String queryDsl = "Select(FOO.BAR).From(FOO)"; Expression expression = new SpelExpressionParser().parseExpression(queryDsl); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(context, "statement-expression:" + queryDsl); context.register(Conf.class); context.refresh();/*from ww w . j ava 2 s. c o m*/ CassandraSinkProperties properties = context.getBean(CassandraSinkProperties.class); assertThat(properties.getStatementExpression().getExpressionString(), equalTo(expression.getExpressionString())); context.close(); }
From source file:com.mine.cassandra.sink.CassandraSinkPropertiesTests.java
@Test public void queryTypeCanBeCustomized() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(context, "query-type:" + CassandraMessageHandler.Type.UPDATE); context.register(Conf.class); context.refresh();//from w w w . ja v a2 s .co m CassandraSinkProperties properties = context.getBean(CassandraSinkProperties.class); assertThat(properties.getQueryType(), equalTo(CassandraMessageHandler.Type.UPDATE)); context.close(); }
From source file:com.mine.cassandra.sink.CassandraSinkPropertiesTests.java
@Test public void consistencyLevelCanBeCustomized() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(context, "consistency-level:" + ConsistencyLevel.LOCAL_QUOROM); context.register(Conf.class); context.refresh();// ww w . j a va 2 s .c om CassandraSinkProperties properties = context.getBean(CassandraSinkProperties.class); assertThat(properties.getConsistencyLevel(), equalTo(ConsistencyLevel.LOCAL_QUOROM)); context.close(); }
From source file:com.mine.cassandra.sink.CassandraSinkPropertiesTests.java
@Test public void retryPolicyCanBeCustomized() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(context, "retry-policy:" + RetryPolicy.DOWNGRADING_CONSISTENCY); context.register(Conf.class); context.refresh();/*from w ww. j a v a 2 s . co m*/ CassandraSinkProperties properties = context.getBean(CassandraSinkProperties.class); assertThat(properties.getRetryPolicy(), equalTo(RetryPolicy.DOWNGRADING_CONSISTENCY)); context.close(); }
From source file:at.ac.univie.isc.asio.nest.D2rqNestAssemblerTest.java
@Test public void should_create_singleton_assembler_if_no_optional_listeners_present() throws Exception { final StaticApplicationContext parent = new StaticApplicationContext(); final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.getBeanFactory().registerSingleton("factory", new SpringContextFactory(parent)); context.register(D2rqNestAssembler.class); context.refresh();// w ww . j a va2 s . c o m final D2rqNestAssembler actual = context.getBean(D2rqNestAssembler.class); assertThat(actual, notNullValue()); }
From source file:org.springframework.data.rest.webmvc.config.RepositoryRestMvConfigurationIntegrationTests.java
/** * @see DATAREST-424// w w w .j a v a 2 s . co m */ @Test public void halHttpMethodConverterIsRegisteredAfterTheGeneralOneIfHalIsDisabledAsDefaultMediaType() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( NonHalConfiguration.class); CollectingComponent component = context.getBean(CollectingComponent.class); context.close(); List<HttpMessageConverter<?>> converters = component.converters; assertThat(converters.get(0).getSupportedMediaTypes(), hasItem(RestMediaTypes.SCHEMA_JSON)); assertThat(converters.get(1).getSupportedMediaTypes(), hasItem(MediaTypes.HAL_JSON)); }