List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext getBean
@Override public Object getBean(String name) throws BeansException
From source file:net.ggtools.maven.DDLGeneratorIntegrationTest.java
@Test public void createContext() throws Exception { AnnotationConfigApplicationContext context = mojo.createApplicationContext(); DDLGenerator generator = context.getBean(DDLGenerator.class); }
From source file:com.github.jmnarloch.spring.jaxrs.client.jersey.EnableJerseyClientTest.java
/** * Tests the registration of the proxy factory in application context. */// w w w .ja v a2 s .co m @Test public void shouldRegisterClientProxyFactory() { // given final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class); // when JaxRsClientProxyFactory factory = context.getBean(JaxRsClientProxyFactory.class); // then assertNotNull(factory); assertTrue(JerseyClientProxyFactory.class.equals(factory.getClass())); }
From source file:com.github.jmnarloch.spring.jaxrs.client.cxf.EnableCxfClientTest.java
/** * Tests the registration of the proxy factory in application context. *//*from www. j av a 2s. com*/ @Test public void shouldRegisterClientProxyFactory() { // given final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class); // when JaxRsClientProxyFactory factory = context.getBean(JaxRsClientProxyFactory.class); // then assertNotNull(factory); assertTrue(CxfClientProxyFactory.class.equals(factory.getClass())); }
From source file:com.github.jmnarloch.spring.jaxrs.client.resteasy.EnableRestEasyClientTest.java
/** * Tests the registration of the proxy factory in application context. *//*from ww w. j a va2 s .c om*/ @Test public void shouldRegisterClientProxyFactory() { // given final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class); // when JaxRsClientProxyFactory factory = context.getBean(JaxRsClientProxyFactory.class); // then assertNotNull(factory); assertTrue(RestEasyClientProxyFactory.class.equals(factory.getClass())); }
From source file:org.dalesbred.integration.spring.SpringConfigurationTest.java
@Test public void dalesbredUsesConnectionBoundToSpringTransactions() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SimpleConfiguration.class); DataSource dataSource = ctx.getBean(DataSource.class); Database db = ctx.getBean(Database.class); new TransactionTemplate(new DataSourceTransactionManager(dataSource)) .execute(status -> db.withTransaction(Propagation.MANDATORY, tx -> { assertThat(tx.getConnection(), is(DataSourceUtils.getConnection(dataSource))); return "ok"; }));//from ww w . j ava 2 s . co m }
From source file:org.springsource.investigation.ReproTests.java
@SuppressWarnings("unchecked") @Test// w w w .j ava2 s .c om public void repro() { ConfigurableApplicationContext parent = new GenericApplicationContext(); parent.refresh(); AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext(); child.setParent(parent); child.refresh(); ConfigurableEnvironment env = child.getBean(ConfigurableEnvironment.class); assertThat("UNKNOWN ENV", env, anyOf(sameInstance(parent.getEnvironment()), sameInstance(child.getEnvironment()))); assertThat("EXPECTED CHILD CTX ENV", env, sameInstance(child.getEnvironment())); }
From source file:org.dalesbred.integration.spring.SpringConfigurationTest.java
@Test public void rollbackForSpringTransactionDiscardsChangesOfDalesbred() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SimpleConfiguration.class); DataSource dataSource = ctx.getBean(DataSource.class); Database db = ctx.getBean(Database.class); db.update("drop table if exists spring_tx_test"); db.update("create table spring_tx_test (id int)"); new TransactionTemplate(new DataSourceTransactionManager(dataSource)).execute(status -> { db.update("insert into spring_tx_test (id) values (1)"); status.setRollbackOnly();//www.j av a 2s . com return ""; }); assertThat(db.findUniqueInt("select count(*) from spring_tx_test"), is(0)); }
From source file:org.glassfish.jersey.server.spring.profiles.SpringProfilesTest.java
@Test public void shouldGetDevProfileBean() { System.setProperty("spring.profiles.active", "dev"); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( "org.glassfish.jersey.server.spring.profiles"); assertEquals("dev", context.getBean(TestService.class).test()); }
From source file:org.glassfish.jersey.server.spring.profiles.SpringProfilesTest.java
@Test public void shouldGetDefaultBean() { System.setProperty("spring.profiles.active", ""); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( "org.glassfish.jersey.server.spring.profiles"); assertEquals("default", context.getBean(TestService.class).test()); }
From source file:com.github.jmnarloch.spring.jaxrs.client.cxf.CxfClientConfigurationTest.java
/** * Tests the registration of the proxy factory in application context. *//*from w w w.ja va 2 s . c o m*/ @Test public void shouldRegisterClientProxyFactory() { // given final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( CxfClientConfiguration.class); // when JaxRsClientProxyFactory factory = context.getBean(JaxRsClientProxyFactory.class); // then assertNotNull(factory); assertTrue(CxfClientProxyFactory.class.equals(factory.getClass())); }