Java Code Examples for org.springframework.jdbc.datasource.TestDataSourceWrapper

The following examples show how to use org.springframework.jdbc.datasource.TestDataSourceWrapper. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note   Source File: GenericStoredProcedureTests.java    License: MIT License 5 votes vote down vote up
@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();
}
 
Example 2
Source Project: spring-analysis-note   Source File: GenericSqlQueryTests.java    License: MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	this.beanFactory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
			new ClassPathResource("org/springframework/jdbc/object/GenericSqlQueryTests-context.xml"));
	DataSource dataSource = mock(DataSource.class);
	this.connection = mock(Connection.class);
	this.preparedStatement = mock(PreparedStatement.class);
	this.resultSet = mock(ResultSet.class);
	given(dataSource.getConnection()).willReturn(connection);
	TestDataSourceWrapper testDataSource = (TestDataSourceWrapper) beanFactory.getBean("dataSource");
	testDataSource.setTarget(dataSource);
}
 
Example 3
@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();
}
 
Example 4
Source Project: java-technology-stack   Source File: GenericSqlQueryTests.java    License: MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	this.beanFactory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
			new ClassPathResource("org/springframework/jdbc/object/GenericSqlQueryTests-context.xml"));
	DataSource dataSource = mock(DataSource.class);
	this.connection = mock(Connection.class);
	this.preparedStatement = mock(PreparedStatement.class);
	this.resultSet = mock(ResultSet.class);
	given(dataSource.getConnection()).willReturn(connection);
	TestDataSourceWrapper testDataSource = (TestDataSourceWrapper) beanFactory.getBean("dataSource");
	testDataSource.setTarget(dataSource);
}
 
Example 5
@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<String, Object>(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();
}
 
Example 6
@Before
public void setUp() throws Exception {
	this.beanFactory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.beanFactory).loadBeanDefinitions(
			new ClassPathResource("org/springframework/jdbc/object/GenericSqlQueryTests-context.xml"));
	DataSource dataSource = mock(DataSource.class);
	this.connection = mock(Connection.class);
	this.preparedStatement = mock(PreparedStatement.class);
	this.resultSet = mock(ResultSet.class);
	given(dataSource.getConnection()).willReturn(connection);
	TestDataSourceWrapper testDataSource = (TestDataSourceWrapper) beanFactory.getBean("dataSource");
	testDataSource.setTarget(dataSource);
}
 
Example 7
Source Project: effectivejava   Source File: GenericStoredProcedureTests.java    License: Apache License 2.0 5 votes vote down vote up
@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<String, Object>(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();
}
 
Example 8
Source Project: effectivejava   Source File: GenericSqlQueryTests.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	this.beanFactory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.beanFactory).loadBeanDefinitions(
			new ClassPathResource("org/springframework/jdbc/object/GenericSqlQueryTests-context.xml"));
	DataSource dataSource = mock(DataSource.class);
	this.connection = mock(Connection.class);
	this.preparedStatement = mock(PreparedStatement.class);
	this.resultSet = mock(ResultSet.class);
	given(dataSource.getConnection()).willReturn(connection);
	TestDataSourceWrapper testDataSource = (TestDataSourceWrapper) beanFactory.getBean("dataSource");
	testDataSource.setTarget(dataSource);
}