Polishing

(cherry picked from commit b9a2d0a)
This commit is contained in:
Juergen Hoeller
2016-08-17 20:43:41 +02:00
parent 22ca7ac927
commit de91b1a8a0
10 changed files with 80 additions and 90 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.springframework.jdbc.object;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -30,8 +29,6 @@ import javax.sql.DataSource;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
@@ -43,13 +40,14 @@ import static org.mockito.BDDMockito.*;
/**
* @author Thomas Risberg
* @author Juergen Hoeller
*/
public class GenericSqlQueryTests {
public class GenericSqlQueryTests {
private static final String SELECT_ID_FORENAME_NAMED_PARAMETERS_PARSED =
"select id, forename from custmr where id = ? and country = ?";
"select id, forename from custmr where id = ? and country = ?";
private BeanFactory beanFactory;
private DefaultListableBeanFactory beanFactory;
private Connection connection;
@@ -57,10 +55,11 @@ public class GenericSqlQueryTests {
private ResultSet resultSet;
@Before
public void setUp() throws Exception {
this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.beanFactory).loadBeanDefinitions(
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
new ClassPathResource("org/springframework/jdbc/object/GenericSqlQueryTests-context.xml"));
DataSource dataSource = mock(DataSource.class);
this.connection = mock(Connection.class);
@@ -72,13 +71,13 @@ public class GenericSqlQueryTests {
}
@Test
public void testPlaceHoldersCustomerQuery() throws SQLException {
SqlQuery<?> query = (SqlQuery<?>) beanFactory.getBean("queryWithPlaceHolders");
public void testCustomerQueryWithPlaceholders() throws SQLException {
SqlQuery<?> query = (SqlQuery<?>) beanFactory.getBean("queryWithPlaceholders");
doTestCustomerQuery(query, false);
}
@Test
public void testNamedParameterCustomerQuery() throws SQLException {
public void testCustomerQueryWithNamedParameters() throws SQLException {
SqlQuery<?> query = (SqlQuery<?>) beanFactory.getBean("queryWithNamedParameters");
doTestCustomerQuery(query, true);
}

View File

@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.TestDataSourceWrapper"/>
<bean id="queryWithPlaceHolders" class="org.springframework.jdbc.object.GenericSqlQuery">
<bean id="queryWithPlaceholders" class="org.springframework.jdbc.object.GenericSqlQuery">
<property name="dataSource" ref="dataSource"/>
<property name="sql" value="select id, forename from custmr where id = ? and country = ?"/>
<property name="parameters">
@@ -47,7 +47,7 @@
</bean>
</list>
</property>
<property name="rowMapperClass" value="org.springframework.jdbc.object.CustomerMapper"/>
<property name="rowMapperClass" value="org.springframework.jdbc.object.CustomerMapper"/>
</bean>
</beans>