List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean
@Override public <T> T getBean(String name, Class<T> requiredType) throws BeansException
From source file:io.pivotal.spring.xd.jdbcgpfdist.support.LoadConfigurationFactoryBeanTests.java
@Test public void testListValuesToColumns() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "LoadConfigurationFactoryBeanTests1.xml"); LoadConfigurationFactoryBean factoryBean = context.getBean("&greenplumLoadConfiguration", LoadConfigurationFactoryBean.class); assertThat(factoryBean.getUpdateColumns().size(), is(2)); assertThat(factoryBean.getMatchColumns().size(), is(2)); context.close();/*from www . ja va 2 s .co m*/ }
From source file:net.sf.oval.test.integration.spring.ValidatorSpringBeanTest.java
public void testValidatorSpringBean() { final ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("ValidatorSpringBeanTest.xml", ValidatorSpringBeanTest.class); try {//from w ww .j a va2 s. com final Validator validator = ctx.getBean("validator", Validator.class); new XMLConfigurationTest().validateUser(validator); } finally { ctx.close(); } }
From source file:org.echocat.jemoni.carbon.spring.WriterDefinitionParserUnitTest.java
@Test public void test() throws Exception { final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("writerTestBeans.xml", WriterDefinitionParserUnitTest.class); try {//w w w .j a va 2 s . co m final CarbonWriter defaultWriter = context.getBean(CarbonWriter.class.getName(), CarbonWriter.class); assertThat(defaultWriter.getAddress(), is(new InetSocketAddress("localhost", 667))); assertThat(defaultWriter.getMaxBufferLifetime(), is(DEFAULT_MAX_BUFFER_LIFETIME)); assertThat(defaultWriter.getCharset(), is(DEFAULT_CHARSET)); final CarbonWriter xxxWriter = context.getBean("xxx", CarbonWriter.class); assertThat(xxxWriter.getAddress(), is(new InetSocketAddress("localhost", 666))); assertThat(xxxWriter.getMaxBufferLifetime(), is(new Duration("666h"))); assertThat(xxxWriter.getCharset(), is(forName("ISO-8859-15"))); } finally { context.close(); } }
From source file:org.echocat.jemoni.carbon.spring.CarbonPropertyEditorRegistrarUnitTest.java
@Test public void test() throws Exception { final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "registerPropertyEditorsTestBeans.xml", CarbonPropertyEditorRegistrarUnitTest.class); try {//w w w.j av a 2 s .c o m final Jmx2CarbonBridge bridge = context.getBean("bridge", Jmx2CarbonBridge.class); assertThat(bridge.getConfiguration(), is(createReferenceRules())); } finally { context.close(); } }
From source file:org.solmix.runtime.support.spring.SpringContainerTest.java
@Test public void testSchema() { ClassPathXmlApplicationContext context = null; try {/* w ww . ja v a 2 s. c o m*/ context = new ClassPathXmlApplicationContext("/org/solmix/runtime/support/spring/container.xml"); Container c = context.getBean("solmix1", Container.class); String v = c.getProperty("key").toString(); Assert.assertEquals("value", v); Assert.assertNotNull(c); Container c1 = context.getBean("solmix3", Container.class); Assert.assertNotSame(c, c1); Assert.assertNotNull(c1); List<ContainerListener> cls = c.getContainerListeners(); Assert.assertEquals(3, cls.size()); } finally { if (context != null) { context.close(); } } }
From source file:de.uniwue.dmir.heatmap.PointSpringTest.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public void testHeatmap() throws IOException { System.setProperty("configDir", "classpath:spring/example/points/config"); System.setProperty("workDir", "out/points/work-jar"); // System.setProperty("spring.profiles.active", "minmax"); // System.setProperty("min", "2013-06-01 00:00:00"); // System.setProperty("max", "2013-07-01 00:00:00"); ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( new String[] { "spring/example/points/config/config.xml" }, false); appContext.refresh();/* w ww . java2 s . c o m*/ IHeatmap heatmap = appContext.getBean(HEATMAP_BEAN, IHeatmap.class); ITileProcessor tileProcessor = appContext.getBean(WRITER_BEAN, ITileProcessor.class); heatmap.processTiles(tileProcessor); appContext.close(); }
From source file:de.uniwue.dmir.heatmap.SpringTest3.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public void testHeatmap() throws IOException { System.setProperty("minTimestamp", "2013-06-01 00:00:00"); System.setProperty("maxTimestamp", "2013-07-30 00:00:00"); System.setProperty("workDir", "out/basic/work-jar"); System.setProperty("configDir", "src/main/resources/spring/example/basic/config"); ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( new String[] { "spring/example/basic/config/config.xml" }, false); appContext.refresh();/*w w w . j a va 2 s . com*/ IHeatmap heatmap = appContext.getBean(HEATMAP_BEAN, IHeatmap.class); ITileProcessor tileProcessor = appContext.getBean(WRITER_BEAN, ITileProcessor.class); heatmap.processTiles(tileProcessor); tileProcessor.close(); appContext.close(); }
From source file:org.echocat.jemoni.carbon.spring.Jmx2CarbonBridgeDefinitionParserUnitTest.java
@Test public void test() throws Exception { final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "jmx2carbonBridgeTestBeans.xml", Jmx2CarbonBridgeDefinitionParserUnitTest.class); try {/* w ww . j a va2 s. c o m*/ final CarbonWriter carbonWriter = context.getBean("carbonWriter", CarbonWriter.class); final ClassLoader classLoader = context.getBean("classLoader", ClassLoader.class); final Jmx2CarbonBridge bridge1 = context.getBean("bridge1", Jmx2CarbonBridge.class); assertThat(bridge1.getCarbonWriter(), isSameAs(carbonWriter)); assertThat(bridge1.getClassLoader(), isSameAs(classLoader)); assertThat(bridge1.getPathPrefix(), is("foo.")); assertThat(bridge1.getConfiguration(), is(createReferenceRules())); final Jmx2CarbonBridge bridge2 = context.getBean(Jmx2CarbonBridge.class.getName(), Jmx2CarbonBridge.class); assertThat(bridge2.getCarbonWriter(), isSameAs(carbonWriter)); assertThat(bridge2.getClassLoader(), isSameAs(currentThread().getContextClassLoader())); assertThat(bridge2.getConfiguration(), is(null)); } finally { context.close(); } }
From source file:com.ryantenney.metrics.spring.RegistryTest.java
@Test public void testSuppliedRegistries() { ClassPathXmlApplicationContext ctx = null; try {//from w w w.j a v a 2 s. c o m ctx = new ClassPathXmlApplicationContext("classpath:supplied-registries.xml"); Assert.assertNotNull("Should have a MetricRegistry bean.", ctx.getBean("metrics", MetricRegistry.class)); Assert.assertNotNull("Should have a HealthCheckRegistry bean.", ctx.getBean("health", HealthCheckRegistry.class)); } finally { if (ctx != null) { ctx.close(); } } }
From source file:org.ldaptive.SpringTest.java
/** * Attempts to load all Spring application context XML files to * verify proper wiring./*from ww w . ja va 2s .co m*/ * * @throws Exception On test failure. */ @Test(groups = { "spring" }) public void testSpringWiring() throws Exception { final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "/spring-context.xml", }); AssertJUnit.assertTrue(context.getBeanDefinitionCount() > 0); ConnectionFactory cf = context.getBean("connectionFactory", ConnectionFactory.class); Connection conn = cf.getConnection(); try { conn.open(); } finally { conn.close(); } final ClassPathXmlApplicationContext factoryContext = new ClassPathXmlApplicationContext( new String[] { "/spring-factory-context.xml", }); AssertJUnit.assertTrue(factoryContext.getBeanDefinitionCount() > 0); cf = factoryContext.getBean("connectionFactory", ConnectionFactory.class); conn = cf.getConnection(); try { conn.open(); } finally { conn.close(); } final ClassPathXmlApplicationContext poolContext = new ClassPathXmlApplicationContext( new String[] { "/spring-pool-context.xml", }); AssertJUnit.assertTrue(poolContext.getBeanDefinitionCount() > 0); BlockingConnectionPool pool = null; try { pool = poolContext.getBean("pool", BlockingConnectionPool.class); } finally { pool.close(); } }