diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/sql-error-codes.xml b/org.springframework.jdbc/src/main/resources/org/springframework/jdbc/support/sql-error-codes.xml similarity index 100% rename from org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/sql-error-codes.xml rename to org.springframework.jdbc/src/main/resources/org/springframework/jdbc/support/sql-error-codes.xml diff --git a/org.springframework.jdbc/src/test/java/org/springframework/beans/Colour.java b/org.springframework.jdbc/src/test/java/org/springframework/beans/Colour.java new file mode 100644 index 0000000000..60dc333e0b --- /dev/null +++ b/org.springframework.jdbc/src/test/java/org/springframework/beans/Colour.java @@ -0,0 +1,35 @@ +/* + * Copyright 2002-2007 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.beans; + +import org.springframework.core.enums.ShortCodedLabeledEnum; + +/** + * @author Rob Harrop + */ +public class Colour extends ShortCodedLabeledEnum { + + public static final Colour RED = new Colour(0, "RED"); + public static final Colour BLUE = new Colour(1, "BLUE"); + public static final Colour GREEN = new Colour(2, "GREEN"); + public static final Colour PURPLE = new Colour(3, "PURPLE"); + + private Colour(int code, String label) { + super(code, label); + } + +} \ No newline at end of file diff --git a/org.springframework.jdbc/src/test/java/org/springframework/beans/INestedTestBean.java b/org.springframework.jdbc/src/test/java/org/springframework/beans/INestedTestBean.java new file mode 100644 index 0000000000..7d87547b5f --- /dev/null +++ b/org.springframework.jdbc/src/test/java/org/springframework/beans/INestedTestBean.java @@ -0,0 +1,23 @@ +/* + * Copyright 2002-2005 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.beans; + +public interface INestedTestBean { + + public String getCompany(); + +} \ No newline at end of file diff --git a/org.springframework.jdbc/src/test/java/org/springframework/beans/IOther.java b/org.springframework.jdbc/src/test/java/org/springframework/beans/IOther.java new file mode 100644 index 0000000000..797486ec44 --- /dev/null +++ b/org.springframework.jdbc/src/test/java/org/springframework/beans/IOther.java @@ -0,0 +1,24 @@ + +/* + * Copyright 2002-2005 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.beans; + +public interface IOther { + + void absquatulate(); + +} \ No newline at end of file diff --git a/org.springframework.jdbc/src/test/java/org/springframework/beans/ITestBean.java b/org.springframework.jdbc/src/test/java/org/springframework/beans/ITestBean.java new file mode 100644 index 0000000000..cdf5ef510d --- /dev/null +++ b/org.springframework.jdbc/src/test/java/org/springframework/beans/ITestBean.java @@ -0,0 +1,71 @@ +/* + * Copyright 2002-2007 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.beans; + +import java.io.IOException; + +/** + * Interface used for {@link org.springframework.beans.TestBean}. + * + *

Two methods are the same as on Person, but if this + * extends person it breaks quite a few tests.. + * + * @author Rod Johnson + * @author Juergen Hoeller + */ +public interface ITestBean { + + int getAge(); + + void setAge(int age); + + String getName(); + + void setName(String name); + + ITestBean getSpouse(); + + void setSpouse(ITestBean spouse); + + ITestBean[] getSpouses(); + + String[] getStringArray(); + + void setStringArray(String[] stringArray); + + /** + * Throws a given (non-null) exception. + */ + void exceptional(Throwable t) throws Throwable; + + Object returnsThis(); + + INestedTestBean getDoctor(); + + INestedTestBean getLawyer(); + + IndexedTestBean getNestedIndexedBean(); + + /** + * Increment the age by one. + * @return the previous age + */ + int haveBirthday(); + + void unreliableFileOperation() throws IOException; + +} \ No newline at end of file diff --git a/org.springframework.jdbc/src/test/java/org/springframework/beans/IndexedTestBean.java b/org.springframework.jdbc/src/test/java/org/springframework/beans/IndexedTestBean.java new file mode 100644 index 0000000000..ddb091770e --- /dev/null +++ b/org.springframework.jdbc/src/test/java/org/springframework/beans/IndexedTestBean.java @@ -0,0 +1,145 @@ +/* + * Copyright 2002-2006 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.beans; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeSet; + +/** + * @author Juergen Hoeller + * @since 11.11.2003 + */ +public class IndexedTestBean { + + private TestBean[] array; + + private Collection collection; + + private List list; + + private Set set; + + private SortedSet sortedSet; + + private Map map; + + private SortedMap sortedMap; + + + public IndexedTestBean() { + this(true); + } + + public IndexedTestBean(boolean populate) { + if (populate) { + populate(); + } + } + + public void populate() { + TestBean tb0 = new TestBean("name0", 0); + TestBean tb1 = new TestBean("name1", 0); + TestBean tb2 = new TestBean("name2", 0); + TestBean tb3 = new TestBean("name3", 0); + TestBean tb4 = new TestBean("name4", 0); + TestBean tb5 = new TestBean("name5", 0); + TestBean tb6 = new TestBean("name6", 0); + TestBean tb7 = new TestBean("name7", 0); + TestBean tbX = new TestBean("nameX", 0); + TestBean tbY = new TestBean("nameY", 0); + this.array = new TestBean[] {tb0, tb1}; + this.list = new ArrayList(); + this.list.add(tb2); + this.list.add(tb3); + this.set = new TreeSet(); + this.set.add(tb6); + this.set.add(tb7); + this.map = new HashMap(); + this.map.put("key1", tb4); + this.map.put("key2", tb5); + this.map.put("key.3", tb5); + List list = new ArrayList(); + list.add(tbX); + list.add(tbY); + this.map.put("key4", list); + } + + + public TestBean[] getArray() { + return array; + } + + public void setArray(TestBean[] array) { + this.array = array; + } + + public Collection getCollection() { + return collection; + } + + public void setCollection(Collection collection) { + this.collection = collection; + } + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } + + public Set getSet() { + return set; + } + + public void setSet(Set set) { + this.set = set; + } + + public SortedSet getSortedSet() { + return sortedSet; + } + + public void setSortedSet(SortedSet sortedSet) { + this.sortedSet = sortedSet; + } + + public Map getMap() { + return map; + } + + public void setMap(Map map) { + this.map = map; + } + + public SortedMap getSortedMap() { + return sortedMap; + } + + public void setSortedMap(SortedMap sortedMap) { + this.sortedMap = sortedMap; + } + +} \ No newline at end of file diff --git a/org.springframework.jdbc/src/test/java/org/springframework/beans/NestedTestBean.java b/org.springframework.jdbc/src/test/java/org/springframework/beans/NestedTestBean.java new file mode 100644 index 0000000000..a06e15d150 --- /dev/null +++ b/org.springframework.jdbc/src/test/java/org/springframework/beans/NestedTestBean.java @@ -0,0 +1,60 @@ +/* + * Copyright 2002-2005 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.beans; + +/** + * Simple nested test bean used for testing bean factories, AOP framework etc. + * + * @author Trevor D. Cook + * @since 30.09.2003 + */ +public class NestedTestBean implements INestedTestBean { + + private String company = ""; + + public NestedTestBean() { + } + + public NestedTestBean(String company) { + setCompany(company); + } + + public void setCompany(String company) { + this.company = (company != null ? company : ""); + } + + public String getCompany() { + return company; + } + + public boolean equals(Object obj) { + if (!(obj instanceof NestedTestBean)) { + return false; + } + NestedTestBean ntb = (NestedTestBean) obj; + return this.company.equals(ntb.company); + } + + public int hashCode() { + return this.company.hashCode(); + } + + public String toString() { + return "NestedTestBean: " + this.company; + } + +} \ No newline at end of file diff --git a/org.springframework.jdbc/src/test/java/org/springframework/beans/TestBean.java b/org.springframework.jdbc/src/test/java/org/springframework/beans/TestBean.java new file mode 100644 index 0000000000..7842bbfeac --- /dev/null +++ b/org.springframework.jdbc/src/test/java/org/springframework/beans/TestBean.java @@ -0,0 +1,437 @@ +/* + * Copyright 2002-2008 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.beans; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.BeanNameAware; +import org.springframework.util.ObjectUtils; + +/** + * Simple test bean used for testing bean factories, the AOP framework etc. + * + * @author Rod Johnson + * @author Juergen Hoeller + * @since 15 April 2001 + */ +public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOther, Comparable { + + private String beanName; + + private String country; + + private BeanFactory beanFactory; + + private boolean postProcessed; + + private String name; + + private String sex; + + private int age; + + private boolean jedi; + + private ITestBean[] spouses; + + private String touchy; + + private String[] stringArray; + + private Integer[] someIntegerArray; + + private Date date = new Date(); + + private Float myFloat = new Float(0.0); + + private Collection friends = new LinkedList(); + + private Set someSet = new HashSet(); + + private Map someMap = new HashMap(); + + private List someList = new ArrayList(); + + private Properties someProperties = new Properties(); + + private INestedTestBean doctor = new NestedTestBean(); + + private INestedTestBean lawyer = new NestedTestBean(); + + private IndexedTestBean nestedIndexedBean; + + private boolean destroyed; + + private Number someNumber; + + private Colour favouriteColour; + + private Boolean someBoolean; + + private List otherColours; + + private List pets; + + + public TestBean() { + } + + public TestBean(String name) { + this.name = name; + } + + public TestBean(ITestBean spouse) { + this.spouses = new ITestBean[] {spouse}; + } + + public TestBean(String name, int age) { + this.name = name; + this.age = age; + } + + public TestBean(ITestBean spouse, Properties someProperties) { + this.spouses = new ITestBean[] {spouse}; + this.someProperties = someProperties; + } + + public TestBean(List someList) { + this.someList = someList; + } + + public TestBean(Set someSet) { + this.someSet = someSet; + } + + public TestBean(Map someMap) { + this.someMap = someMap; + } + + public TestBean(Properties someProperties) { + this.someProperties = someProperties; + } + + + public void setBeanName(String beanName) { + this.beanName = beanName; + } + + public String getBeanName() { + return beanName; + } + + public void setBeanFactory(BeanFactory beanFactory) { + this.beanFactory = beanFactory; + } + + public BeanFactory getBeanFactory() { + return beanFactory; + } + + public void setPostProcessed(boolean postProcessed) { + this.postProcessed = postProcessed; + } + + public boolean isPostProcessed() { + return postProcessed; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + if (this.name == null) { + this.name = sex; + } + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public boolean isJedi() { + return jedi; + } + + public void setJedi(boolean jedi) { + this.jedi = jedi; + } + + public ITestBean getSpouse() { + return (spouses != null ? spouses[0] : null); + } + + public void setSpouse(ITestBean spouse) { + this.spouses = new ITestBean[] {spouse}; + } + + public ITestBean[] getSpouses() { + return spouses; + } + + public String getTouchy() { + return touchy; + } + + public void setTouchy(String touchy) throws Exception { + if (touchy.indexOf('.') != -1) { + throw new Exception("Can't contain a ."); + } + if (touchy.indexOf(',') != -1) { + throw new NumberFormatException("Number format exception: contains a ,"); + } + this.touchy = touchy; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public String[] getStringArray() { + return stringArray; + } + + public void setStringArray(String[] stringArray) { + this.stringArray = stringArray; + } + + public Integer[] getSomeIntegerArray() { + return someIntegerArray; + } + + public void setSomeIntegerArray(Integer[] someIntegerArray) { + this.someIntegerArray = someIntegerArray; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public Float getMyFloat() { + return myFloat; + } + + public void setMyFloat(Float myFloat) { + this.myFloat = myFloat; + } + + public Collection getFriends() { + return friends; + } + + public void setFriends(Collection friends) { + this.friends = friends; + } + + public Set getSomeSet() { + return someSet; + } + + public void setSomeSet(Set someSet) { + this.someSet = someSet; + } + + public Map getSomeMap() { + return someMap; + } + + public void setSomeMap(Map someMap) { + this.someMap = someMap; + } + + public List getSomeList() { + return someList; + } + + public void setSomeList(List someList) { + this.someList = someList; + } + + public Properties getSomeProperties() { + return someProperties; + } + + public void setSomeProperties(Properties someProperties) { + this.someProperties = someProperties; + } + + public INestedTestBean getDoctor() { + return doctor; + } + + public void setDoctor(INestedTestBean doctor) { + this.doctor = doctor; + } + + public INestedTestBean getLawyer() { + return lawyer; + } + + public void setLawyer(INestedTestBean lawyer) { + this.lawyer = lawyer; + } + + public Number getSomeNumber() { + return someNumber; + } + + public void setSomeNumber(Number someNumber) { + this.someNumber = someNumber; + } + + public Colour getFavouriteColour() { + return favouriteColour; + } + + public void setFavouriteColour(Colour favouriteColour) { + this.favouriteColour = favouriteColour; + } + + public Boolean getSomeBoolean() { + return someBoolean; + } + + public void setSomeBoolean(Boolean someBoolean) { + this.someBoolean = someBoolean; + } + + public IndexedTestBean getNestedIndexedBean() { + return nestedIndexedBean; + } + + public void setNestedIndexedBean(IndexedTestBean nestedIndexedBean) { + this.nestedIndexedBean = nestedIndexedBean; + } + + public List getOtherColours() { + return otherColours; + } + + public void setOtherColours(List otherColours) { + this.otherColours = otherColours; + } + + public List getPets() { + return pets; + } + + public void setPets(List pets) { + this.pets = pets; + } + + + /** + * @see org.springframework.beans.ITestBean#exceptional(Throwable) + */ + public void exceptional(Throwable t) throws Throwable { + if (t != null) { + throw t; + } + } + + public void unreliableFileOperation() throws IOException { + throw new IOException(); + } + /** + * @see org.springframework.beans.ITestBean#returnsThis() + */ + public Object returnsThis() { + return this; + } + + /** + * @see org.springframework.beans.IOther#absquatulate() + */ + public void absquatulate() { + } + + public int haveBirthday() { + return age++; + } + + + public void destroy() { + this.destroyed = true; + } + + public boolean wasDestroyed() { + return destroyed; + } + + + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (other == null || !(other instanceof TestBean)) { + return false; + } + TestBean tb2 = (TestBean) other; + return (ObjectUtils.nullSafeEquals(this.name, tb2.name) && this.age == tb2.age); + } + + public int hashCode() { + return this.age; + } + + public int compareTo(Object other) { + if (this.name != null && other instanceof TestBean) { + return this.name.compareTo(((TestBean) other).getName()); + } + else { + return 1; + } + } + + public String toString() { + return this.name; + } + +} \ No newline at end of file diff --git a/org.springframework.jdbc/src/test/java/org/springframework/jdbc/AbstractJdbcTests.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/AbstractJdbcTests.java new file mode 100644 index 0000000000..8ddc2e5d3c --- /dev/null +++ b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/AbstractJdbcTests.java @@ -0,0 +1,85 @@ +/* + * AbstractJdbcTests.java + * + * Copyright (C) 2002 by Interprise Software. All rights reserved. + */ +/* + * Copyright 2002-2005 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.jdbc; + +import java.sql.Connection; + +import javax.sql.DataSource; + +import junit.framework.TestCase; +import org.easymock.MockControl; + +/** + * @author Trevor D. Cook + */ +public abstract class AbstractJdbcTests extends TestCase { + + protected MockControl ctrlDataSource; + protected DataSource mockDataSource; + protected MockControl ctrlConnection; + protected Connection mockConnection; + + /** + * Set to true if the user wants verification, indicated + * by a call to replay(). We need to make this optional, + * otherwise we setUp() will always result in verification failures + */ + private boolean shouldVerify; + + protected void setUp() throws Exception { + this.shouldVerify = false; + super.setUp(); + + ctrlConnection = MockControl.createControl(Connection.class); + mockConnection = (Connection) ctrlConnection.getMock(); + mockConnection.getMetaData(); + ctrlConnection.setDefaultReturnValue(null); + mockConnection.close(); + ctrlConnection.setDefaultVoidCallable(); + + ctrlDataSource = MockControl.createControl(DataSource.class); + mockDataSource = (DataSource) ctrlDataSource.getMock(); + mockDataSource.getConnection(); + ctrlDataSource.setDefaultReturnValue(mockConnection); + } + + protected void replay() { + ctrlDataSource.replay(); + ctrlConnection.replay(); + this.shouldVerify = true; + } + + protected void tearDown() throws Exception { + super.tearDown(); + + // we shouldn't verify unless the user called replay() + if (shouldVerify()) { + ctrlDataSource.verify(); + //ctrlConnection.verify(); + } + } + + protected boolean shouldVerify() { + return this.shouldVerify; + } + +} \ No newline at end of file diff --git a/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/AbstractRowMapperTests.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/AbstractRowMapperTests.java new file mode 100644 index 0000000000..8a5e6301d5 --- /dev/null +++ b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/AbstractRowMapperTests.java @@ -0,0 +1,146 @@ +/* + * Copyright 2002-2008 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.jdbc.core; + +import java.math.BigDecimal; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Timestamp; +import java.sql.Types; + +import junit.framework.TestCase; +import junit.framework.Assert; +import org.easymock.MockControl; +import org.apache.commons.logging.LogFactory; + +import org.springframework.jdbc.core.test.ConcretePerson; +import org.springframework.jdbc.core.test.Person; +import org.springframework.jdbc.datasource.SingleConnectionDataSource; +import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator; + +/** + * Mock object based abstract class for RowMapper tests. + * Initializes mock objects and verifies results. + * + * @author Thomas Risberg + */ +public abstract class AbstractRowMapperTests extends TestCase { + + private final boolean debugEnabled = LogFactory.getLog(JdbcTemplate.class).isDebugEnabled(); + + protected MockControl conControl; + protected Connection con; + protected MockControl rsmdControl; + protected ResultSetMetaData rsmd; + protected MockControl rsControl; + protected ResultSet rs; + protected MockControl stmtControl; + protected Statement stmt; + protected JdbcTemplate jdbcTemplate; + + protected void setUp() throws SQLException { + conControl = MockControl.createControl(Connection.class); + con = (Connection) conControl.getMock(); + con.isClosed(); + conControl.setDefaultReturnValue(false); + + rsmdControl = MockControl.createControl(ResultSetMetaData.class); + rsmd = (ResultSetMetaData)rsmdControl.getMock(); + rsmd.getColumnCount(); + rsmdControl.setReturnValue(4, 1); + rsmd.getColumnLabel(1); + rsmdControl.setReturnValue("name", 1); + rsmd.getColumnLabel(2); + rsmdControl.setReturnValue("age", 1); + rsmd.getColumnLabel(3); + rsmdControl.setReturnValue("birth_date", 1); + rsmd.getColumnLabel(4); + rsmdControl.setReturnValue("balance", 1); + rsmdControl.replay(); + + rsControl = MockControl.createControl(ResultSet.class); + rs = (ResultSet) rsControl.getMock(); + rs.getMetaData(); + rsControl.setReturnValue(rsmd, 1); + rs.next(); + rsControl.setReturnValue(true, 1); + rs.getString(1); + rsControl.setReturnValue("Bubba", 1); + rs.wasNull(); + rsControl.setReturnValue(false, 1); + rs.getLong(2); + rsControl.setReturnValue(22, 1); + rs.getTimestamp(3); + rsControl.setReturnValue(new Timestamp(1221222L), 1); + rs.getBigDecimal(4); + rsControl.setReturnValue(new BigDecimal("1234.56"), 1); + rs.next(); + rsControl.setReturnValue(false, 1); + rs.close(); + rsControl.setVoidCallable(1); + rsControl.replay(); + + stmtControl = MockControl.createControl(Statement.class); + stmt = (Statement) stmtControl.getMock(); + + con.createStatement(); + conControl.setReturnValue(stmt, 1); + stmt.executeQuery("select name, age, birth_date, balance from people"); + stmtControl.setReturnValue(rs, 1); + if (debugEnabled) { + stmt.getWarnings(); + stmtControl.setReturnValue(null, 1); + } + stmt.close(); + stmtControl.setVoidCallable(1); + + conControl.replay(); + stmtControl.replay(); + + jdbcTemplate = new JdbcTemplate(); + jdbcTemplate.setDataSource(new SingleConnectionDataSource(con, false)); + jdbcTemplate.setExceptionTranslator(new SQLStateSQLExceptionTranslator()); + jdbcTemplate.afterPropertiesSet(); + } + + protected void verifyPerson(Person bean) { + verify(); + Assert.assertEquals("Bubba", bean.getName()); + Assert.assertEquals(22L, bean.getAge()); + Assert.assertEquals(new java.util.Date(1221222L), bean.getBirth_date()); + Assert.assertEquals(new BigDecimal("1234.56"), bean.getBalance()); + } + + protected void verifyConcretePerson(ConcretePerson bean) { + verify(); + Assert.assertEquals("Bubba", bean.getName()); + Assert.assertEquals(22L, bean.getAge()); + Assert.assertEquals(new java.util.Date(1221222L), bean.getBirth_date()); + Assert.assertEquals(new BigDecimal("1234.56"), bean.getBalance()); + } + + private void verify() { + conControl.verify(); + rsControl.verify(); + rsmdControl.verify(); + stmtControl.verify(); + } + +} \ No newline at end of file diff --git a/org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/BeanPropertyRowMapperTests.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/BeanPropertyRowMapperTests.java similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/BeanPropertyRowMapperTests.java rename to org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/BeanPropertyRowMapperTests.java diff --git a/org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java rename to org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java diff --git a/org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java rename to org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java diff --git a/org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/RowMapperTests.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/RowMapperTests.java similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/RowMapperTests.java rename to org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/RowMapperTests.java diff --git a/org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java rename to org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java diff --git a/org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java rename to org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java diff --git a/org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReaderTests.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReaderTests.java similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReaderTests.java rename to org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReaderTests.java diff --git a/org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/support/JdbcDaoSupportTests.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/support/JdbcDaoSupportTests.java similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/support/JdbcDaoSupportTests.java rename to org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/support/JdbcDaoSupportTests.java diff --git a/org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java rename to org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java diff --git a/org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/support/SqlLobValueTests.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/support/SqlLobValueTests.java similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/jdbc/core/support/SqlLobValueTests.java rename to org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/support/SqlLobValueTests.java diff --git a/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/test/AbstractPerson.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/test/AbstractPerson.java new file mode 100644 index 0000000000..8526644e12 --- /dev/null +++ b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/test/AbstractPerson.java @@ -0,0 +1,57 @@ +/* + * Copyright 2002-2008 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.jdbc.core.test; + +import java.util.Date; + +/** + * @author Thomas Risberg + */ +public abstract class AbstractPerson { + + private String name; + + private long age; + + private Date birth_date; + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public long getAge() { + return age; + } + + public void setAge(long age) { + this.age = age; + } + + public Date getBirth_date() { + return birth_date; + } + + public void setBirth_date(Date birth_date) { + this.birth_date = birth_date; + } + +} \ No newline at end of file diff --git a/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/test/ConcretePerson.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/test/ConcretePerson.java new file mode 100644 index 0000000000..9864234397 --- /dev/null +++ b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/test/ConcretePerson.java @@ -0,0 +1,37 @@ +/* + * Copyright 2002-2008 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.jdbc.core.test; + +import java.math.BigDecimal; + +/** + * @author Thomas Risberg + */ +public class ConcretePerson extends AbstractPerson { + + private BigDecimal balance; + + + public BigDecimal getBalance() { + return balance; + } + + public void setBalance(BigDecimal balance) { + this.balance = balance; + } + +} \ No newline at end of file diff --git a/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/test/ExtendedPerson.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/test/ExtendedPerson.java new file mode 100644 index 0000000000..b8fd5c918a --- /dev/null +++ b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/test/ExtendedPerson.java @@ -0,0 +1,35 @@ +/* + * Copyright 2002-2008 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.jdbc.core.test; + +/** + * @author Juergen Hoeller + */ +public class ExtendedPerson extends ConcretePerson { + + private Object someField; + + + public Object getSomeField() { + return someField; + } + + public void setSomeField(Object someField) { + this.someField = someField; + } + +} \ No newline at end of file diff --git a/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/test/Person.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/test/Person.java new file mode 100644 index 0000000000..6b2ea62793 --- /dev/null +++ b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/test/Person.java @@ -0,0 +1,67 @@ +/* + * Copyright 2002-2008 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.jdbc.core.test; + +import java.math.BigDecimal; + +/** + * @author Thomas Risberg + */ +public class Person { + + private String name; + + private long age; + + private java.util.Date birth_date; + + private BigDecimal balance; + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public long getAge() { + return age; + } + + public void setAge(long age) { + this.age = age; + } + + public java.util.Date getBirth_date() { + return birth_date; + } + + public void setBirth_date(java.util.Date birth_date) { + this.birth_date = birth_date; + } + + public BigDecimal getBalance() { + return balance; + } + + public void setBalance(BigDecimal balanace) { + this.balance = balanace; + } + +} \ No newline at end of file