Search in sources :

Example 46 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.

the class JdbcNamespaceIntegrationTests method multipleDataSourcesHaveDifferentDatabaseNames.

@Test
public void multipleDataSourcesHaveDifferentDatabaseNames() throws Exception {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(factory).loadBeanDefinitions(new ClassPathResource("jdbc-config-multiple-datasources.xml", getClass()));
    assertBeanPropertyValueOf("databaseName", "firstDataSource", factory);
    assertBeanPropertyValueOf("databaseName", "secondDataSource", factory);
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 47 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.

the class GenericStoredProcedureTests method testAddInvoices.

@Test
public void testAddInvoices() throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource("org/springframework/jdbc/object/GenericStoredProcedureTests-context.xml"));
    Connection connection = mock(Connection.class);
    DataSource dataSource = mock(DataSource.class);
    given(dataSource.getConnection()).willReturn(connection);
    CallableStatement callableStatement = mock(CallableStatement.class);
    TestDataSourceWrapper testDataSource = (TestDataSourceWrapper) bf.getBean("dataSource");
    testDataSource.setTarget(dataSource);
    given(callableStatement.execute()).willReturn(false);
    given(callableStatement.getUpdateCount()).willReturn(-1);
    given(callableStatement.getObject(3)).willReturn(4);
    given(connection.prepareCall("{call " + "add_invoice" + "(?, ?, ?)}")).willReturn(callableStatement);
    StoredProcedure adder = (StoredProcedure) bf.getBean("genericProcedure");
    Map<String, Object> in = new HashMap<>(2);
    in.put("amount", 1106);
    in.put("custid", 3);
    Map<String, Object> out = adder.execute(in);
    Integer id = (Integer) out.get("newid");
    assertEquals(4, id.intValue());
    verify(callableStatement).setObject(1, 1106, Types.INTEGER);
    verify(callableStatement).setObject(2, 3, Types.INTEGER);
    verify(callableStatement).registerOutParameter(3, Types.INTEGER);
    verify(callableStatement).close();
}
Also used : HashMap(java.util.HashMap) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Connection(java.sql.Connection) ClassPathResource(org.springframework.core.io.ClassPathResource) DataSource(javax.sql.DataSource) CallableStatement(java.sql.CallableStatement) TestDataSourceWrapper(org.springframework.jdbc.datasource.TestDataSourceWrapper) Test(org.junit.Test)

Example 48 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.

the class ComponentScanParserBeanDefinitionDefaultsTests method testDefaultInitAndDestroyMethodsDefined.

@Test
public void testDefaultInitAndDestroyMethodsDefined() {
    GenericApplicationContext context = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultInitAndDestroyMethodsTests.xml");
    context.refresh();
    DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
    assertTrue("bean should have been initialized", bean.isInitialized());
    context.close();
    assertTrue("bean should have been destroyed", bean.isDestroyed());
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) Test(org.junit.Test)

Example 49 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.

the class ComponentScanParserBeanDefinitionDefaultsTests method testDefaultAutowire.

@Test
public void testDefaultAutowire() {
    GenericApplicationContext context = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml");
    context.refresh();
    DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
    assertNull("no dependencies should have been autowired", bean.getConstructorDependency());
    assertNull("no dependencies should have been autowired", bean.getPropertyDependency1());
    assertNull("no dependencies should have been autowired", bean.getPropertyDependency2());
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) Test(org.junit.Test)

Example 50 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.

the class ComponentScanParserBeanDefinitionDefaultsTests method testDefaultNonExistingInitAndDestroyMethodsDefined.

@Test
public void testDefaultNonExistingInitAndDestroyMethodsDefined() {
    GenericApplicationContext context = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultNonExistingInitAndDestroyMethodsTests.xml");
    context.refresh();
    DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
    assertFalse("bean should not have been initialized", bean.isInitialized());
    context.close();
    assertFalse("bean should not have been destroyed", bean.isDestroyed());
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) Test(org.junit.Test)

Aggregations

XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)152 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)82 Test (org.junit.Test)80 ClassPathResource (org.springframework.core.io.ClassPathResource)62 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)38 Before (org.junit.Before)30 ITestBean (org.springframework.tests.sample.beans.ITestBean)18 TestBean (org.springframework.tests.sample.beans.TestBean)11 BeansException (org.springframework.beans.BeansException)9 Resource (org.springframework.core.io.Resource)8 UrlResource (org.springframework.core.io.UrlResource)8 URL (java.net.URL)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)6 HashMap (java.util.HashMap)5 Person (org.springframework.tests.sample.beans.Person)5 ArrayList (java.util.ArrayList)4 BeanCreationException (org.springframework.beans.factory.BeanCreationException)4 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)4 ResourceEntityResolver (org.springframework.beans.factory.xml.ResourceEntityResolver)4