Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/LongTypeHandlerTest.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/LongTypeHandlerTest.java?rev=683745&view=auto ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/LongTypeHandlerTest.java (added) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/LongTypeHandlerTest.java Thu Aug 7 16:21:46 2008 @@ -0,0 +1,53 @@ +package org.apache.ibatis.type; + +import org.jmock.Expectations; +import org.junit.*; + +public class LongTypeHandlerTest extends BaseTypeHandlerTest { + + private static final TypeHandler TYPE_HANDLER = new LongTypeHandler(); + + @Test + public void shouldSetParameter() + throws Exception { + mockery.checking(new Expectations() { + { + one(ps).setLong(with(any(int.class)), with(any(long.class))); + } + }); + TYPE_HANDLER.setParameter(ps, 1, 100l, null); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromResultSet() + throws Exception { + mockery.checking(new Expectations() { + { + one(rs).getLong(with(any(String.class))); + will(returnValue(100l)); + one(rs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals(100l, TYPE_HANDLER.getResult(rs, "column")); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromCallableStatement() + throws Exception { + mockery.checking(new Expectations() { + { + one(cs).getLong(with(any(int.class))); + will(returnValue(100l)); + one(cs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals(100l, TYPE_HANDLER.getResult(cs, 1)); + mockery.assertIsSatisfied(); + } + + +} \ No newline at end of file
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/ObjectTypeHandlerTest.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/ObjectTypeHandlerTest.java?rev=683745&view=auto ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/ObjectTypeHandlerTest.java (added) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/ObjectTypeHandlerTest.java Thu Aug 7 16:21:46 2008 @@ -0,0 +1,53 @@ +package org.apache.ibatis.type; + +import org.jmock.Expectations; +import org.junit.*; + +public class ObjectTypeHandlerTest extends BaseTypeHandlerTest { + + private static final TypeHandler TYPE_HANDLER = new ObjectTypeHandler(); + + @Test + public void shouldSetParameter() + throws Exception { + mockery.checking(new Expectations() { + { + one(ps).setObject(with(any(int.class)), with(any(String.class))); + } + }); + TYPE_HANDLER.setParameter(ps, 1, "Hello", null); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromResultSet() + throws Exception { + mockery.checking(new Expectations() { + { + one(rs).getObject(with(any(String.class))); + will(returnValue("Hello")); + one(rs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals("Hello", TYPE_HANDLER.getResult(rs, "column")); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromCallableStatement() + throws Exception { + mockery.checking(new Expectations() { + { + one(cs).getObject(with(any(int.class))); + will(returnValue("Hello")); + one(cs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals("Hello", TYPE_HANDLER.getResult(cs, 1)); + mockery.assertIsSatisfied(); + } + + +} \ No newline at end of file Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/ShortTypeHandlerTest.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/ShortTypeHandlerTest.java?rev=683745&view=auto ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/ShortTypeHandlerTest.java (added) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/ShortTypeHandlerTest.java Thu Aug 7 16:21:46 2008 @@ -0,0 +1,53 @@ +package org.apache.ibatis.type; + +import org.jmock.Expectations; +import org.junit.*; + +public class ShortTypeHandlerTest extends BaseTypeHandlerTest { + + private static final TypeHandler TYPE_HANDLER = new ShortTypeHandler(); + + @Test + public void shouldSetParameter() + throws Exception { + mockery.checking(new Expectations() { + { + one(ps).setShort(with(any(int.class)), with(any(short.class))); + } + }); + TYPE_HANDLER.setParameter(ps, 1, (short) 100, null); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromResultSet() + throws Exception { + mockery.checking(new Expectations() { + { + one(rs).getShort(with(any(String.class))); + will(returnValue((short) 100)); + one(rs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals((short) 100, TYPE_HANDLER.getResult(rs, "column")); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromCallableStatement() + throws Exception { + mockery.checking(new Expectations() { + { + one(cs).getShort(with(any(int.class))); + will(returnValue((short) 100)); + one(cs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals((short) 100, TYPE_HANDLER.getResult(cs, 1)); + mockery.assertIsSatisfied(); + } + + +} \ No newline at end of file Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SimpleTypeRegistryTest.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SimpleTypeRegistryTest.java?rev=683745&view=auto ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SimpleTypeRegistryTest.java (added) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SimpleTypeRegistryTest.java Thu Aug 7 16:21:46 2008 @@ -0,0 +1,18 @@ +package org.apache.ibatis.type; + +import domain.misc.RichType; +import org.junit.*; + +public class SimpleTypeRegistryTest { + + @Test + public void shouldTestIfClassIsSimpleTypeAndReturnTrue() { + Assert.assertTrue(SimpleTypeRegistry.isSimpleType(String.class)); + } + + @Test + public void shouldTestIfClassIsSimpleTypeAndReturnFalse() { + Assert.assertFalse(SimpleTypeRegistry.isSimpleType(RichType.class)); + } + +} Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SqlDateTypeHandlerTest.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SqlDateTypeHandlerTest.java?rev=683745&view=auto ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SqlDateTypeHandlerTest.java (added) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SqlDateTypeHandlerTest.java Thu Aug 7 16:21:46 2008 @@ -0,0 +1,56 @@ +package org.apache.ibatis.type; + +import org.jmock.Expectations; +import org.junit.*; + +import java.util.Date; + +public class SqlDateTypeHandlerTest extends BaseTypeHandlerTest { + + private static final TypeHandler TYPE_HANDLER = new SqlDateTypeHandler(); + private static final java.sql.Date SQL_DATE = new java.sql.Date(new Date().getTime()); + + @Test + public void shouldSetParameter() + throws Exception { + mockery.checking(new Expectations() { + { + one(ps).setDate(with(any(int.class)), with(any(java.sql.Date.class))); + } + }); + TYPE_HANDLER.setParameter(ps, 1, SQL_DATE, null); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromResultSet() + throws Exception { + mockery.checking(new Expectations() { + { + one(rs).getDate(with(any(String.class))); + will(returnValue(SQL_DATE)); + one(rs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals(SQL_DATE, TYPE_HANDLER.getResult(rs, "column")); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromCallableStatement() + throws Exception { + mockery.checking(new Expectations() { + { + one(cs).getDate(with(any(int.class))); + will(returnValue(SQL_DATE)); + one(cs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals(SQL_DATE, TYPE_HANDLER.getResult(cs, 1)); + mockery.assertIsSatisfied(); + } + + +} \ No newline at end of file Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SqlTimeTypeHandlerTest.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SqlTimeTypeHandlerTest.java?rev=683745&view=auto ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SqlTimeTypeHandlerTest.java (added) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SqlTimeTypeHandlerTest.java Thu Aug 7 16:21:46 2008 @@ -0,0 +1,56 @@ +package org.apache.ibatis.type; + +import org.jmock.Expectations; +import org.junit.*; + +import java.util.Date; + +public class SqlTimeTypeHandlerTest extends BaseTypeHandlerTest { + + private static final TypeHandler TYPE_HANDLER = new SqlTimeTypeHandler(); + private static final java.sql.Time SQL_TIME = new java.sql.Time(new Date().getTime()); + + @Test + public void shouldSetParameter() + throws Exception { + mockery.checking(new Expectations() { + { + one(ps).setTime(with(any(int.class)), with(any(java.sql.Time.class))); + } + }); + TYPE_HANDLER.setParameter(ps, 1, SQL_TIME, null); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromResultSet() + throws Exception { + mockery.checking(new Expectations() { + { + one(rs).getTime(with(any(String.class))); + will(returnValue(SQL_TIME)); + one(rs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals(SQL_TIME, TYPE_HANDLER.getResult(rs, "column")); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromCallableStatement() + throws Exception { + mockery.checking(new Expectations() { + { + one(cs).getTime(with(any(int.class))); + will(returnValue(SQL_TIME)); + one(cs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals(SQL_TIME, TYPE_HANDLER.getResult(cs, 1)); + mockery.assertIsSatisfied(); + } + + +} \ No newline at end of file Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SqlTimetampTypeHandlerTest.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SqlTimetampTypeHandlerTest.java?rev=683745&view=auto ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SqlTimetampTypeHandlerTest.java (added) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/SqlTimetampTypeHandlerTest.java Thu Aug 7 16:21:46 2008 @@ -0,0 +1,56 @@ +package org.apache.ibatis.type; + +import org.jmock.Expectations; +import org.junit.*; + +import java.util.Date; + +public class SqlTimetampTypeHandlerTest extends BaseTypeHandlerTest { + + private static final TypeHandler TYPE_HANDLER = new SqlTimestampTypeHandler(); + private static final java.sql.Timestamp SQL_TIME = new java.sql.Timestamp(new Date().getTime()); + + @Test + public void shouldSetParameter() + throws Exception { + mockery.checking(new Expectations() { + { + one(ps).setTimestamp(with(any(int.class)), with(any(java.sql.Timestamp.class))); + } + }); + TYPE_HANDLER.setParameter(ps, 1, SQL_TIME, null); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromResultSet() + throws Exception { + mockery.checking(new Expectations() { + { + one(rs).getTimestamp(with(any(String.class))); + will(returnValue(SQL_TIME)); + one(rs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals(SQL_TIME, TYPE_HANDLER.getResult(rs, "column")); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromCallableStatement() + throws Exception { + mockery.checking(new Expectations() { + { + one(cs).getTimestamp(with(any(int.class))); + will(returnValue(SQL_TIME)); + one(cs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals(SQL_TIME, TYPE_HANDLER.getResult(cs, 1)); + mockery.assertIsSatisfied(); + } + + +} \ No newline at end of file Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/StringTypeHandlerTest.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/StringTypeHandlerTest.java?rev=683745&view=auto ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/StringTypeHandlerTest.java (added) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/StringTypeHandlerTest.java Thu Aug 7 16:21:46 2008 @@ -0,0 +1,95 @@ +package org.apache.ibatis.type; + +import org.jmock.Expectations; +import org.junit.*; + +public class StringTypeHandlerTest extends BaseTypeHandlerTest { + + private static final TypeHandler TYPE_HANDLER = new StringTypeHandler(); + + @Test + public void shouldSetParameter() + throws Exception { + mockery.checking(new Expectations() { + { + one(ps).setString(with(any(int.class)), with(any(String.class))); + } + }); + TYPE_HANDLER.setParameter(ps, 1, "Hello", null); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldSetNullParameter() + throws Exception { + mockery.checking(new Expectations() { + { + one(ps).setNull(with(any(int.class)), with(any(int.class))); + } + }); + TYPE_HANDLER.setParameter(ps, 1, null, JdbcType.VARCHAR); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromResultSet() + throws Exception { + mockery.checking(new Expectations() { + { + one(rs).getString(with(any(String.class))); + will(returnValue("Hello")); + one(rs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals("Hello", TYPE_HANDLER.getResult(rs, "column")); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetNullResultFromResultSet() + throws Exception { + mockery.checking(new Expectations() { + { + one(rs).getString(with(any(String.class))); + will(returnValue(null)); + one(rs).wasNull(); + will(returnValue(true)); + } + }); + Assert.assertEquals(null, TYPE_HANDLER.getResult(rs, "column")); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromCallableStatement() + throws Exception { + mockery.checking(new Expectations() { + { + one(cs).getString(with(any(int.class))); + will(returnValue("Hello")); + one(cs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals("Hello", TYPE_HANDLER.getResult(cs, 1)); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetNullResultFromCallableStatement() + throws Exception { + mockery.checking(new Expectations() { + { + one(cs).getString(with(any(int.class))); + will(returnValue(null)); + one(cs).wasNull(); + will(returnValue(true)); + } + }); + Assert.assertEquals(null, TYPE_HANDLER.getResult(cs, 1)); + mockery.assertIsSatisfied(); + } + + +} Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/TimeOnlyTypeHandlerTest.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/TimeOnlyTypeHandlerTest.java?rev=683745&view=auto ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/TimeOnlyTypeHandlerTest.java (added) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/TimeOnlyTypeHandlerTest.java Thu Aug 7 16:21:46 2008 @@ -0,0 +1,57 @@ +package org.apache.ibatis.type; + +import org.jmock.Expectations; +import org.junit.*; + +import java.util.Date; + +public class TimeOnlyTypeHandlerTest extends BaseTypeHandlerTest { + + private static final TypeHandler TYPE_HANDLER = new TimeOnlyTypeHandler(); + private static final Date DATE = new Date(); + private static final java.sql.Time SQL_TIME = new java.sql.Time(DATE.getTime()); + + @Test + public void shouldSetParameter() + throws Exception { + mockery.checking(new Expectations() { + { + one(ps).setTime(with(any(int.class)), with(any(java.sql.Time.class))); + } + }); + TYPE_HANDLER.setParameter(ps, 1, DATE, null); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromResultSet() + throws Exception { + mockery.checking(new Expectations() { + { + one(rs).getTime(with(any(String.class))); + will(returnValue(SQL_TIME)); + one(rs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals(DATE, TYPE_HANDLER.getResult(rs, "column")); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromCallableStatement() + throws Exception { + mockery.checking(new Expectations() { + { + one(cs).getTime(with(any(int.class))); + will(returnValue(SQL_TIME)); + one(cs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals(DATE, TYPE_HANDLER.getResult(cs, 1)); + mockery.assertIsSatisfied(); + } + + +} \ No newline at end of file Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/TypeAliasRegistryTest.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/TypeAliasRegistryTest.java?rev=683745&view=auto ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/TypeAliasRegistryTest.java (added) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/TypeAliasRegistryTest.java Thu Aug 7 16:21:46 2008 @@ -0,0 +1,17 @@ +package org.apache.ibatis.type; + +import org.junit.*; + +public class TypeAliasRegistryTest { + + @Test + public void shouldRegisterAndResolveTypeAlias() { + TypeAliasRegistry typeAliasRegistry = new TypeAliasRegistry(); + + typeAliasRegistry.registerAlias("rich", "domain.misc.RichType"); + + Assert.assertEquals("domain.misc.RichType", typeAliasRegistry.resolveAlias("rich")); + Assert.assertEquals("unknown", typeAliasRegistry.resolveAlias("unknown")); + } + +} Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/TypeHandlerRegistryTest.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/TypeHandlerRegistryTest.java?rev=683745&view=auto ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/TypeHandlerRegistryTest.java (added) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/TypeHandlerRegistryTest.java Thu Aug 7 16:21:46 2008 @@ -0,0 +1,23 @@ +package org.apache.ibatis.type; + +import domain.misc.RichType; +import org.junit.*; + +public class TypeHandlerRegistryTest { + + private TypeHandlerRegistry typeHandlerRegistry = new TypeHandlerRegistry(); + + @Test + public void shouldRegisterAndRetrieveTypeHandler() { + TypeHandler stringTypeHandler = typeHandlerRegistry.getTypeHandler(String.class); + typeHandlerRegistry.register(String.class, JdbcType.LONGVARCHAR, stringTypeHandler); + Assert.assertEquals(stringTypeHandler, typeHandlerRegistry.getTypeHandler(String.class, JdbcType.LONGVARCHAR)); + + Assert.assertTrue(typeHandlerRegistry.hasTypeHandler(String.class)); + Assert.assertFalse(typeHandlerRegistry.hasTypeHandler(RichType.class)); + Assert.assertTrue(typeHandlerRegistry.hasTypeHandler(String.class, JdbcType.LONGVARCHAR)); + Assert.assertTrue(typeHandlerRegistry.hasTypeHandler(String.class, JdbcType.INTEGER)); + Assert.assertTrue(typeHandlerRegistry.getUnkownTypeHandler() instanceof UnknownTypeHandler); + } + +} Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/UnknownTypeHandlerTest.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/UnknownTypeHandlerTest.java?rev=683745&view=auto ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/UnknownTypeHandlerTest.java (added) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/type/UnknownTypeHandlerTest.java Thu Aug 7 16:21:46 2008 @@ -0,0 +1,53 @@ +package org.apache.ibatis.type; + +import org.jmock.Expectations; +import org.junit.*; + +public class UnknownTypeHandlerTest extends BaseTypeHandlerTest { + + private static final TypeHandler TYPE_HANDLER = new UnknownTypeHandler(new TypeHandlerRegistry()); + + @Test + public void shouldSetParameter() + throws Exception { + mockery.checking(new Expectations() { + { + one(ps).setString(with(any(int.class)), with(any(String.class))); + } + }); + TYPE_HANDLER.setParameter(ps, 1, "Hello", null); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromResultSet() + throws Exception { + mockery.checking(new Expectations() { + { + one(rs).getObject(with(any(String.class))); + will(returnValue("Hello")); + one(rs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals("Hello", TYPE_HANDLER.getResult(rs, "column")); + mockery.assertIsSatisfied(); + } + + @Test + public void shouldGetResultFromCallableStatement() + throws Exception { + mockery.checking(new Expectations() { + { + one(cs).getObject(with(any(int.class))); + will(returnValue("Hello")); + one(cs).wasNull(); + will(returnValue(false)); + } + }); + Assert.assertEquals("Hello", TYPE_HANDLER.getResult(cs, 1)); + mockery.assertIsSatisfied(); + } + + +} \ No newline at end of file Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/xml/NodeletParserTest.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/xml/NodeletParserTest.java?rev=683745&view=auto ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/xml/NodeletParserTest.java (added) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/xml/NodeletParserTest.java Thu Aug 7 16:21:46 2008 @@ -0,0 +1,96 @@ +package org.apache.ibatis.xml; + +import domain.misc.Employee; +import org.apache.ibatis.io.Resources; +import org.junit.*; + +import java.io.Reader; +import java.util.*; + +public class NodeletParserTest { + + @Test + public void shouldParseAttribute() throws Exception { + NodeletParser parser = new NodeletParser(); + NodeHandler handler = new NodeHandler(); + parser.addNodeletHandler(handler); + parser.setVariables(new Properties() { + { + setProperty("id_var", "1234567890"); + } + }); + Reader resource = Resources.getResourceAsReader("resources/nodelet_test.xml"); + parser.parse(resource); + Employee emp = handler.getEmployee(); + Assert.assertEquals(1234567890, emp.getId()); + Assert.assertEquals("Jim", emp.getFirstName()); + Assert.assertEquals("Smith", emp.getLastName()); + Assert.assertEquals(new Date(1970 - 1900, 6 - 1, 15), emp.getBirthDate()); + Assert.assertEquals(5.8, emp.getHeight()); + Assert.assertEquals("ft", emp.getHeightUnits()); + Assert.assertEquals(200, emp.getWeight()); + Assert.assertEquals("lbs", emp.getWeightUnits()); + } + + + public static class NodeHandler { + + private Employee employee = new Employee(); + private int year; + private int month; + private int day; + + public Employee getEmployee() { + return employee; + } + + @Nodelet("/employee") + public void id(NodeletContext node) { + employee.setId(node.getIntAttribute("id", 0)); + } + + @Nodelet("/employee/first_name") + public void firstName(NodeletContext node) { + employee.setFirstName(node.getStringBody("")); + } + + @Nodelet("/employee/last_name") + public void lastName(NodeletContext node) { + employee.setLastName(node.getStringBody("")); + } + + @Nodelet("/employee/birth_date/year") + public void year(NodeletContext node) { + year = node.getIntBody(0); + } + + @Nodelet("/employee/birth_date/month") + public void month(NodeletContext node) { + month = node.getIntBody(0); + } + + @Nodelet("/employee/birth_date/day") + public void day(NodeletContext node) { + day = node.getIntBody(0); + } + + @Nodelet("/employee/birth_date/end()") + public void birth_date(NodeletContext node) { + employee.setBirthDate(new Date(year - 1900, month - 1, day)); + } + + @Nodelet("/employee/height") + public void height(NodeletContext node) { + employee.setHeight(node.getDoubleBody(0.0)); + employee.setHeightUnits(node.getStringAttribute("units", "")); + } + + @Nodelet("/employee/weight") + public void weight(NodeletContext node) { + employee.setWeight(node.getDoubleBody(0.0)); + employee.setWeightUnits(node.getStringAttribute("units", "")); + } + + } + +} Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/resources/nodelet_test.xml URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/resources/nodelet_test.xml?rev=683745&view=auto ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/resources/nodelet_test.xml (added) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/resources/nodelet_test.xml Thu Aug 7 16:21:46 2008 @@ -0,0 +1,11 @@ +<employee id="${id_var}"> + <first_name>Jim</first_name> + <last_name>Smith</last_name> + <birth_date> + <year>1970</year> + <month>6</month> + <day>15</day> + </birth_date> + <height units="ft">5.8</height> + <weight units="lbs">200</weight> +</employee> \ No newline at end of file Added: ibatis/trunk/java/ibatis-3/pom.xml URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/pom.xml?rev=683745&view=auto ============================================================================== --- ibatis/trunk/java/ibatis-3/pom.xml (added) +++ ibatis/trunk/java/ibatis-3/pom.xml Thu Aug 7 16:21:46 2008 @@ -0,0 +1,12 @@ +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.ibatis</groupId> + <artifactId>ibatis-3</artifactId> + <version>3.0-SNAPSHOT</version> + <packaging>pom</packaging> + <modules> + <module>ibatis-3-core</module> + <module>ibatis-3-compat</module> + </modules> +</project> +