You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by cb...@apache.org on 2008/08/08 01:21:58 UTC
svn commit: r683745 [9/22] - in /ibatis/trunk/java/ibatis-3: ./
ibatis-3-compat/ ibatis-3-compat/src/ ibatis-3-compat/src/main/
ibatis-3-compat/src/main/java/ ibatis-3-compat/src/main/java/com/
ibatis-3-compat/src/main/java/com/ibatis/ ibatis-3-compat/...
Added: ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/IterateTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/IterateTest.java?rev=683745&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/IterateTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/IterateTest.java Thu Aug 7 16:21:46 2008
@@ -0,0 +1,160 @@
+package com.ibatis.sqlmap;
+
+import testdomain.Account;
+
+import java.sql.SQLException;
+import java.util.*;
+
+public class IterateTest extends BaseSqlMapTest {
+
+ protected void setUp() throws Exception {
+ initSqlMap("com/ibatis/sqlmap/maps/SqlMapConfig.xml", null);
+ initScript("scripts/account-init.sql");
+ }
+
+ protected void tearDown() throws Exception {
+ }
+
+ // Iterate
+
+ public void testIterate() throws SQLException {
+ List params = Arrays.asList(new Integer[]{new Integer(1), new Integer(2), new Integer(3)});
+ List list = sqlMap.queryForList("dynamicIterate", params);
+ assertAccount1((Account) list.get(0));
+ assertEquals(3, list.size());
+ }
+
+ // Iterate
+
+ public void testIterateInConditional() throws SQLException {
+ List params = Arrays.asList(new Integer[]{new Integer(1), new Integer(2), new Integer(3)});
+ List list = sqlMap.queryForList("dynamicIterateInConditional", params);
+ assertEquals(2, list.size());
+ assertAccount1((Account) list.get(0));
+ assertEquals(1, ((Account) list.get(0)).getId());
+ assertEquals(3, ((Account) list.get(1)).getId());
+ }
+
+ public void testIterateLiteral() throws SQLException {
+ List params = Arrays.asList(new Integer[]{new Integer(1), new Integer(2), new Integer(3)});
+ List list = sqlMap.queryForList("dynamicIterateLiteral", params);
+ assertAccount1((Account) list.get(0));
+ assertEquals(3, list.size());
+ }
+
+ public void testMultiIterate() throws SQLException {
+ List params = Arrays.asList(new Integer[]{new Integer(1), new Integer(2), new Integer(3)});
+ List list = sqlMap.queryForList("multiDynamicIterate", params);
+ assertAccount1((Account) list.get(0));
+ assertEquals(3, list.size());
+ }
+
+ public void testMultiIterateLiteral() throws SQLException {
+ List params = Arrays.asList(new Integer[]{new Integer(1), new Integer(2), new Integer(3)});
+ List list = sqlMap.queryForList("multiDynamicIterateLiteral", params);
+ assertAccount1((Account) list.get(0));
+ assertEquals(3, list.size());
+ }
+
+ // ARRAY
+
+ public void testArrayPropertyIterate() throws SQLException {
+ Account account = new Account();
+ account.setIds(new int[]{1, 2, 3});
+ List list = sqlMap.queryForList("dynamicQueryByExample", account);
+ assertAccount1((Account) list.get(0));
+ assertEquals(3, list.size());
+ }
+
+ public void testArrayPropertyIterate2() throws SQLException {
+ Account account = new Account();
+ account.setAge(4);
+ account.setIds(new int[]{1, 2, 3});
+ List list = sqlMap.queryForList("dynamicQueryByExample2", account);
+ assertAccount1((Account) list.get(0));
+ assertEquals(3, list.size());
+ }
+
+ public void testArrayPropertyIterate2Literal() throws SQLException {
+ Account account = new Account();
+ account.setAge(4);
+ account.setIds(new int[]{1, 2, 3});
+ List list = sqlMap.queryForList("dynamicQueryByExample2Literal", account);
+ assertAccount1((Account) list.get(0));
+ assertEquals(3, list.size());
+ }
+
+ // LIST IN MAP
+
+ public void testListInMap() throws SQLException {
+ List paramList = new Vector();
+ paramList.add(new Integer(1));
+ paramList.add(new Integer(2));
+ paramList.add(new Integer(3));
+
+ Map paramMap = new HashMap();
+ paramMap.put("paramList", paramList);
+
+ List list = sqlMap.queryForList("iterateListInMap", paramMap);
+ assertAccount1((Account) list.get(0));
+ assertEquals(3, list.size());
+ }
+
+ public void testListDirect() throws SQLException {
+ List paramList = new Vector();
+ paramList.add(new Integer(1));
+ paramList.add(new Integer(2));
+ paramList.add(new Integer(3));
+
+ List list = sqlMap.queryForList("iterateListDirect", paramList);
+ assertAccount1((Account) list.get(0));
+ assertEquals(3, list.size());
+ }
+
+ public void testIterateNestedListProperty() throws SQLException {
+ Account account = new Account();
+ account.setAccountList(new ArrayList());
+ account.getAccountList().add(new Account(1));
+ account.getAccountList().add(new Account(2));
+ account.getAccountList().add(new Account(3));
+
+ List list = sqlMap.queryForList("iterateNestedListProperty", account);
+ assertAccount1((Account) list.get(0));
+ assertEquals(3, list.size());
+ }
+
+ public void testIterateNestedListPropertyB() throws SQLException {
+ Account account = new Account();
+ account.setId(99);
+ account.setAccountList(new ArrayList());
+ account.getAccountList().add(new Account(1));
+ account.getAccountList().add(new Account(2));
+ account.getAccountList().add(new Account(3));
+
+ List list = sqlMap.queryForList("iterateNestedListPropertyB", account);
+ assertAccount1((Account) list.get(0));
+ assertEquals(3, list.size());
+ }
+
+ public void testIterateNestedMapListProperty() throws SQLException {
+ Map account = new HashMap();
+ List accountList = new ArrayList();
+ account.put("accountList", accountList);
+ accountList.add(new Account(1));
+ accountList.add(new Account(2));
+ accountList.add(new Account(3));
+
+ List list = sqlMap.queryForList("iterateNestedMapListProperty", account);
+ assertAccount1((Account) list.get(0));
+ assertEquals(3, list.size());
+ }
+
+ public void xtestArrayPropertyIterate2() throws SQLException {
+ Account account = new Account();
+ account.setIds(new int[]{1, 2, 3});
+ List list = sqlMap.queryForList("dynamicQueryByExample2", account);
+ assertAccount1((Account) list.get(0));
+ assertEquals(3, list.size());
+ }
+
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/MultiResultSetTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/MultiResultSetTest.java?rev=683745&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/MultiResultSetTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/MultiResultSetTest.java Thu Aug 7 16:21:46 2008
@@ -0,0 +1,65 @@
+package com.ibatis.sqlmap;
+
+import com.ibatis.common.resources.Resources;
+
+import java.sql.*;
+import java.util.*;
+
+public class MultiResultSetTest extends BaseSqlMapTest {
+
+ // SETUP & TEARDOWN
+
+ protected void setUp() throws Exception {
+ initSqlMap("com/ibatis/sqlmap/maps/DerbySqlMapConfig.xml", Resources.getResourceAsProperties("com/ibatis/sqlmap/maps/DerbySqlMapConfig.properties"));
+ initScript("scripts/account-init.sql");
+ initScript("scripts/derby-proc-init.sql");
+
+ }
+
+ public void testShouldRetrieveTwoSetsOfTwoAccountsFromMultipleResultMaps() throws Exception {
+ Map persons = new HashMap();
+ persons.put("1", new Integer(1));
+ persons.put("2", new Integer(2));
+ persons.put("3", new Integer(3));
+ persons.put("4", new Integer(4));
+ List results = sqlMap.queryForList("getMultiListsRm", persons);
+ assertEquals(2, results.size());
+ assertEquals(2, ((List) results.get(0)).size());
+ assertEquals(2, ((List) results.get(1)).size());
+ }
+
+ public void testShouldRetrieveTwoSetsOfTwoAccountsFromMultipleResultClasses() throws Exception {
+ Map persons = new HashMap();
+ persons.put("1", new Integer(1));
+ persons.put("2", new Integer(2));
+ persons.put("3", new Integer(3));
+ persons.put("4", new Integer(4));
+ List results = sqlMap.queryForList("getMultiListsRc", persons);
+ assertEquals(2, results.size());
+ assertEquals(2, ((List) results.get(0)).size());
+ assertEquals(2, ((List) results.get(1)).size());
+ }
+
+ public void testCallableStatementShouldReturnTwoResultSets() throws Exception {
+ sqlMap.startTransaction();
+ Connection conn = sqlMap.getCurrentConnection();
+ CallableStatement cs = conn.prepareCall("{call MRESULTSET(?,?,?,?)}");
+ cs.setInt(1, 1);
+ cs.setInt(2, 2);
+ cs.setInt(3, 3);
+ cs.setInt(4, 4);
+ cs.execute();
+ ResultSet rs = cs.getResultSet();
+ assertNotNull(rs);
+ int found = 1;
+ while (cs.getMoreResults()) {
+ assertNotNull(cs.getResultSet());
+ found++;
+ }
+ rs.close();
+ cs.close();
+ assertEquals("Didn't find second result set.", 2, found);
+ }
+
+
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/NestedIterateTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/NestedIterateTest.java?rev=683745&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/NestedIterateTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/NestedIterateTest.java Thu Aug 7 16:21:46 2008
@@ -0,0 +1,916 @@
+package com.ibatis.sqlmap;
+
+import testdomain.*;
+
+import java.util.*;
+
+public class NestedIterateTest extends BaseSqlMapTest {
+
+ protected void setUp() throws Exception {
+ initSqlMap("com/ibatis/sqlmap/maps/SqlMapConfig.xml", null);
+ initScript("scripts/person-init.sql");
+ initScript("scripts/jpetstore-hsqldb-schema.sql");
+ initScript("scripts/jpetstore-hsqldb-dataload.sql");
+ }
+
+ /**
+ * This test should return 9 rows: ids 1-9
+ * <p/>
+ * This method works as expected
+ */
+ public void testShouldReturn9Rows() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+ try {
+ List results =
+ sqlMap.queryForList("NestedIterateTest1", po);
+ assertEquals(9, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(3, ((Person) results.get(2)).getId().intValue());
+ assertEquals(4, ((Person) results.get(3)).getId().intValue());
+ assertEquals(5, ((Person) results.get(4)).getId().intValue());
+ assertEquals(6, ((Person) results.get(5)).getId().intValue());
+ assertEquals(7, ((Person) results.get(6)).getId().intValue());
+ assertEquals(8, ((Person) results.get(7)).getId().intValue());
+ assertEquals(9, ((Person) results.get(8)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This test shoud return 1 row: id 4
+ */
+ public void test02() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest2", po);
+ assertEquals(1, results.size());
+ assertEquals(4, ((Person) results.get(0)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This test should return 8 rows: ids 1-3, 5-9
+ */
+ public void test03() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(4)); // put first to make the test fail
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest3", po);
+ assertEquals(8, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(3, ((Person) results.get(2)).getId().intValue());
+ assertEquals(5, ((Person) results.get(3)).getId().intValue());
+ assertEquals(6, ((Person) results.get(4)).getId().intValue());
+ assertEquals(7, ((Person) results.get(5)).getId().intValue());
+ assertEquals(8, ((Person) results.get(6)).getId().intValue());
+ assertEquals(9, ((Person) results.get(7)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This test should return 5 rows: ids 5-9
+ */
+ public void test04() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest4", po);
+ assertEquals(5, results.size());
+ assertEquals(5, ((Person) results.get(0)).getId().intValue());
+ assertEquals(6, ((Person) results.get(1)).getId().intValue());
+ assertEquals(7, ((Person) results.get(2)).getId().intValue());
+ assertEquals(8, ((Person) results.get(3)).getId().intValue());
+ assertEquals(9, ((Person) results.get(4)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This test should return 6 rows: ids 4-9
+ */
+ public void test05() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest5", po);
+ assertEquals(6, results.size());
+ assertEquals(4, ((Person) results.get(0)).getId().intValue());
+ assertEquals(5, ((Person) results.get(1)).getId().intValue());
+ assertEquals(6, ((Person) results.get(2)).getId().intValue());
+ assertEquals(7, ((Person) results.get(3)).getId().intValue());
+ assertEquals(8, ((Person) results.get(4)).getId().intValue());
+ assertEquals(9, ((Person) results.get(5)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This test should return 3 rows: ids 1-3
+ */
+ public void test06() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ // go backwards to make the test fail
+ po.addId(new Integer(9));
+ po.addId(new Integer(8));
+ po.addId(new Integer(7));
+ po.addId(new Integer(6));
+ po.addId(new Integer(5));
+ po.addId(new Integer(4));
+ po.addId(new Integer(3));
+ po.addId(new Integer(2));
+ po.addId(new Integer(1));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest6", po);
+ assertEquals(3, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(3, ((Person) results.get(2)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This test should return 4 rows: ids 1-4
+ */
+ public void test07() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ // go backwards to make the test fail
+ po.addId(new Integer(9));
+ po.addId(new Integer(8));
+ po.addId(new Integer(7));
+ po.addId(new Integer(6));
+ po.addId(new Integer(5));
+ po.addId(new Integer(4));
+ po.addId(new Integer(3));
+ po.addId(new Integer(2));
+ po.addId(new Integer(1));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest7", po);
+ assertEquals(4, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(3, ((Person) results.get(2)).getId().intValue());
+ assertEquals(4, ((Person) results.get(3)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This method should return four rows: ids 1, 2, 7, 8
+ */
+ public void test08() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addFirstName("Jeff");
+ po.addFirstName("Matt");
+ po.addLastName("Jones");
+ po.addLastName("Smith");
+
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest8", po);
+ assertEquals(4, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(7, ((Person) results.get(2)).getId().intValue());
+ assertEquals(8, ((Person) results.get(3)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This method should return two rows: ids 1, 2
+ * <p/>
+ * This method works when Christian's IBATIS-281 patches are applied
+ */
+ public void test09() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+
+ NestedIterateParameterObject.AndCondition andCondition = new NestedIterateParameterObject.AndCondition();
+ andCondition.addCondition("first_name =", "Jeff", new Boolean(true));
+ andCondition.addCondition("last_name =", "Jones", new Boolean(true));
+ po.addOrCondition(andCondition);
+
+ andCondition = new NestedIterateParameterObject.AndCondition();
+ andCondition.addCondition("first_name =", "Matt", new Boolean(true));
+ andCondition.addCondition("last_name =", "Jones", new Boolean(true));
+ po.addOrCondition(andCondition);
+
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest9", po);
+ assertEquals(2, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ public void test09a() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+
+ NestedIterateParameterObject.AndCondition andCondition = new NestedIterateParameterObject.AndCondition();
+ andCondition.addCondition("first_name =", "Jeff", new Boolean(true));
+ andCondition.addCondition("last_name =", "Jones", new Boolean(true));
+ po.addOrCondition(andCondition);
+
+ andCondition = new NestedIterateParameterObject.AndCondition();
+ andCondition.addCondition("first_name =", "Matt", new Boolean(true));
+ andCondition.addCondition("last_name =", "Jones", new Boolean(true));
+ po.addOrCondition(andCondition);
+
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest9a", po);
+ assertEquals(2, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This test shoud return 1 row: id 4
+ */
+ public void test10() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest10", po);
+ assertEquals(1, results.size());
+ assertEquals(4, ((Person) results.get(0)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This test should return 8 rows: ids 1-3, 5-9
+ */
+ public void test11() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(4)); // put first to make the test fail
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest11", po);
+ assertEquals(8, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(3, ((Person) results.get(2)).getId().intValue());
+ assertEquals(5, ((Person) results.get(3)).getId().intValue());
+ assertEquals(6, ((Person) results.get(4)).getId().intValue());
+ assertEquals(7, ((Person) results.get(5)).getId().intValue());
+ assertEquals(8, ((Person) results.get(6)).getId().intValue());
+ assertEquals(9, ((Person) results.get(7)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This test should return 5 rows: ids 5-9
+ */
+ public void test12() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest12", po);
+ assertEquals(5, results.size());
+ assertEquals(5, ((Person) results.get(0)).getId().intValue());
+ assertEquals(6, ((Person) results.get(1)).getId().intValue());
+ assertEquals(7, ((Person) results.get(2)).getId().intValue());
+ assertEquals(8, ((Person) results.get(3)).getId().intValue());
+ assertEquals(9, ((Person) results.get(4)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This test should return 6 rows: ids 4-9
+ */
+ public void test13() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest13", po);
+ assertEquals(6, results.size());
+ assertEquals(4, ((Person) results.get(0)).getId().intValue());
+ assertEquals(5, ((Person) results.get(1)).getId().intValue());
+ assertEquals(6, ((Person) results.get(2)).getId().intValue());
+ assertEquals(7, ((Person) results.get(3)).getId().intValue());
+ assertEquals(8, ((Person) results.get(4)).getId().intValue());
+ assertEquals(9, ((Person) results.get(5)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This test should return 3 rows: ids 1-3
+ */
+ public void test14() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ // go backwards to make the test fail
+ po.addId(new Integer(9));
+ po.addId(new Integer(8));
+ po.addId(new Integer(7));
+ po.addId(new Integer(6));
+ po.addId(new Integer(5));
+ po.addId(new Integer(4));
+ po.addId(new Integer(3));
+ po.addId(new Integer(2));
+ po.addId(new Integer(1));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest14", po);
+ assertEquals(3, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(3, ((Person) results.get(2)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This test should return 4 rows: ids 1-4
+ */
+ public void test15() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ // go backwards to make the test fail
+ po.addId(new Integer(9));
+ po.addId(new Integer(8));
+ po.addId(new Integer(7));
+ po.addId(new Integer(6));
+ po.addId(new Integer(5));
+ po.addId(new Integer(4));
+ po.addId(new Integer(3));
+ po.addId(new Integer(2));
+ po.addId(new Integer(1));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest15", po);
+ assertEquals(4, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(3, ((Person) results.get(2)).getId().intValue());
+ assertEquals(4, ((Person) results.get(3)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This method should return six rows: ids 1-6
+ * <p/>
+ * This method works when Christian's IBATIS-281 patches are applied
+ */
+ public void test16() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+
+ NestedIterateParameterObject.AndCondition andCondition = new NestedIterateParameterObject.AndCondition();
+ andCondition.addCondition("first_name =", "Jeff", new Boolean(false));
+ andCondition.addCondition("last_name =", "Jones", new Boolean(true));
+ po.addOrCondition(andCondition);
+
+ andCondition = new NestedIterateParameterObject.AndCondition();
+ andCondition.addCondition("first_name =", "Matt", new Boolean(true));
+ andCondition.addCondition("last_name =", "Jones", new Boolean(true));
+ po.addOrCondition(andCondition);
+
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest16", po);
+ assertEquals(6, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(3, ((Person) results.get(2)).getId().intValue());
+ assertEquals(4, ((Person) results.get(3)).getId().intValue());
+ assertEquals(5, ((Person) results.get(4)).getId().intValue());
+ assertEquals(6, ((Person) results.get(5)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This method should return six rows: ids 1-6
+ * <p/>
+ * This method works when Christian's IBATIS-281 patches are applied
+ */
+ public void test17() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+
+ NestedIterateParameterObject.AndCondition andCondition = new NestedIterateParameterObject.AndCondition();
+ andCondition.addCondition("first_name =", "Jeff", new Boolean(false));
+ andCondition.addCondition("last_name =", "Jones", new Boolean(true));
+ po.addOrCondition(andCondition);
+
+ andCondition = new NestedIterateParameterObject.AndCondition();
+ andCondition.addCondition("first_name =", "Matt", new Boolean(true));
+ andCondition.addCondition("last_name =", "Jones", new Boolean(true));
+ po.addOrCondition(andCondition);
+
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest17", po);
+ assertEquals(6, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(3, ((Person) results.get(2)).getId().intValue());
+ assertEquals(4, ((Person) results.get(3)).getId().intValue());
+ assertEquals(5, ((Person) results.get(4)).getId().intValue());
+ assertEquals(6, ((Person) results.get(5)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This method should return two rows: ids 1, 2
+ * <p/>
+ * This method tests <isNotPropertyAvailable> inside in <iterate>
+ */
+ public void test18() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+
+ NestedIterateParameterObject.AndCondition andCondition = new NestedIterateParameterObject.AndCondition();
+ andCondition.addCondition("first_name =", "Jeff", new Boolean(false));
+ andCondition.addCondition("last_name =", "Jones", new Boolean(true));
+ po.addOrCondition(andCondition);
+
+ andCondition = new NestedIterateParameterObject.AndCondition();
+ andCondition.addCondition("first_name =", "Matt", new Boolean(true));
+ andCondition.addCondition("last_name =", "Jones", new Boolean(true));
+ po.addOrCondition(andCondition);
+
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest18", po);
+ assertEquals(2, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This method should return two rows: ids 1, 2
+ * <p/>
+ * This method tests <isNotNull> inside an <iterate>
+ */
+ public void test19() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+
+ NestedIterateParameterObject.AndCondition andCondition = new NestedIterateParameterObject.AndCondition();
+ andCondition.addCondition("first_name =", "Jeff", new Boolean(false));
+ andCondition.addCondition("last_name =", "Jones", new Boolean(true));
+ po.addOrCondition(andCondition);
+
+ andCondition = new NestedIterateParameterObject.AndCondition();
+ andCondition.addCondition("first_name =", "Matt", new Boolean(true));
+ andCondition.addCondition("last_name =", "Jones", new Boolean(true));
+ po.addOrCondition(andCondition);
+
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest19", po);
+ assertEquals(2, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This method should return two rows: ids 1, 2
+ * <p/>
+ * This method tests <isNotEmpty> inside an <iterate>
+ */
+ public void test20() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+
+ NestedIterateParameterObject.AndCondition andCondition = new NestedIterateParameterObject.AndCondition();
+ andCondition.addCondition("first_name =", "Jeff", new Boolean(false));
+ andCondition.addCondition("last_name =", "Jones", new Boolean(true));
+ po.addOrCondition(andCondition);
+
+ andCondition = new NestedIterateParameterObject.AndCondition();
+ andCondition.addCondition("first_name =", "Matt", new Boolean(true));
+ andCondition.addCondition("last_name =", "Jones", new Boolean(true));
+ po.addOrCondition(andCondition);
+
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest20", po);
+ assertEquals(2, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This method should return nine rows: ids 1-9
+ * <p/>
+ * This method tests the open, close, and prepend attributes
+ * when no sub elements satisfy - so no where clause should be
+ * generated
+ */
+ public void test21() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest21", po);
+ assertEquals(9, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(3, ((Person) results.get(2)).getId().intValue());
+ assertEquals(4, ((Person) results.get(3)).getId().intValue());
+ assertEquals(5, ((Person) results.get(4)).getId().intValue());
+ assertEquals(6, ((Person) results.get(5)).getId().intValue());
+ assertEquals(7, ((Person) results.get(6)).getId().intValue());
+ assertEquals(8, ((Person) results.get(7)).getId().intValue());
+ assertEquals(9, ((Person) results.get(8)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This method should return one rows: id 4
+ * <p/>
+ * This method tests the open, close, and prepend attributes
+ * when the first element doesn't satisfy
+ */
+ public void test22() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest22", po);
+ assertEquals(1, results.size());
+ assertEquals(4, ((Person) results.get(0)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This method should return one rows: id 1
+ */
+ public void test23() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest23", po);
+ assertEquals(1, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This method should return one rows: id 9
+ */
+ public void test24() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest24", po);
+ assertEquals(1, results.size());
+ assertEquals(9, ((Person) results.get(0)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This method should return three rows: id 1-3
+ */
+ public void test25() {
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest25", po);
+ assertEquals(3, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(3, ((Person) results.get(2)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * This tests nesting when objects are maps and not a list nested in a list
+ */
+ public void test26() {
+
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+
+ Map params = new HashMap();
+ params.put("po", po);
+
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest26", params);
+ assertEquals(3, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(3, ((Person) results.get(2)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ /**
+ * This tests nesting when objects are maps and not a list nested in a list
+ * same as test26 except deeper
+ */
+ public void test27() {
+
+ Map firstMap = new HashMap();
+
+ List firstList = new ArrayList();
+
+ Map params = new HashMap();
+
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+
+ params.put("po", po);
+
+ firstList.add(params);
+
+ firstMap.put("firstList", firstList);
+
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest27", firstMap);
+ assertEquals(3, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(3, ((Person) results.get(2)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+
+ /**
+ * This tests nesting when objects are maps and not a list nested in a list
+ */
+ public void test28() {
+
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+
+ SimpleNestedParameterObject simpleNestedParameterObject =
+ new SimpleNestedParameterObject();
+
+ simpleNestedParameterObject.setNestedIterateParameterObject(po);
+
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest28", simpleNestedParameterObject);
+ assertEquals(3, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(3, ((Person) results.get(2)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ /**
+ * This tests nesting when objects are maps and not a list nested in a list
+ * same as test26 except deeper
+ */
+ public void test29() {
+
+ SimpleNestedParameterObject firstParameterObject =
+ new SimpleNestedParameterObject();
+
+ SimpleNestedParameterObject secondParameterObject =
+ new SimpleNestedParameterObject();
+
+ List parameterObjectList = new ArrayList();
+
+ NestedIterateParameterObject po = new NestedIterateParameterObject();
+ po.addId(new Integer(1));
+ po.addId(new Integer(2));
+ po.addId(new Integer(3));
+ po.addId(new Integer(4));
+ po.addId(new Integer(5));
+ po.addId(new Integer(6));
+ po.addId(new Integer(7));
+ po.addId(new Integer(8));
+ po.addId(new Integer(9));
+
+ secondParameterObject.setNestedIterateParameterObject(po);
+
+ parameterObjectList.add(secondParameterObject);
+
+ firstParameterObject.setNestedList(parameterObjectList);
+
+ try {
+ List results = sqlMap.queryForList("NestedIterateTest29", firstParameterObject);
+ assertEquals(3, results.size());
+ assertEquals(1, ((Person) results.get(0)).getId().intValue());
+ assertEquals(2, ((Person) results.get(1)).getId().intValue());
+ assertEquals(3, ((Person) results.get(2)).getId().intValue());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+
+ /**
+ * This tests nesting when a list is initially nested in a bean. so it tests
+ * [bean]->[list]->[property_of_object_on_exposed_index]
+ */
+ public void test30() {
+
+ try {
+
+ // prepare item list
+ Item item1 = new Item();
+ item1.setItemId("EST-1");
+ item1.setProductId("FI-SW-01");
+
+ List itemList = new ArrayList();
+ itemList.add(item1);
+
+ // prepare product list
+ Product product1 = new Product();
+ product1.setProductId("FI-SW-01");
+ product1.setCategoryId("DOGS");
+ product1.setItemList(itemList);
+
+ List productList = new ArrayList();
+ productList.add(product1);
+
+ //prepare parent category
+ Category parentCategory = new Category();
+ parentCategory.setCategoryId("DOGS");
+ parentCategory.setProductList(productList);
+
+ // setup Category
+ Category category = new Category();
+ category.setCategoryId("FISH");
+ category.setParentCategory(parentCategory);
+
+ List results = sqlMap.queryForList("NestedIterateTest30", category);
+ assertEquals(1, results.size());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ParameterMapTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ParameterMapTest.java?rev=683745&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ParameterMapTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ParameterMapTest.java Thu Aug 7 16:21:46 2008
@@ -0,0 +1,56 @@
+package com.ibatis.sqlmap;
+
+import testdomain.Account;
+
+import java.sql.SQLException;
+
+public class ParameterMapTest extends BaseSqlMapTest {
+
+ // SETUP & TEARDOWN
+
+ protected void setUp() throws Exception {
+ initSqlMap("com/ibatis/sqlmap/maps/SqlMapConfig.xml", null);
+ initScript("scripts/account-init.sql");
+ }
+
+ protected void tearDown() throws Exception {
+ }
+
+ // PARAMETER MAP FEATURE TESTS
+
+ public void testSpecifiedType() throws SQLException {
+ Account account = newAccount6();
+
+ sqlMap.update("insertAccountNullableEmail", account);
+
+ account = (Account) sqlMap.queryForObject("getAccountNullableEmail", new Integer(6));
+
+ assertAccount6(account);
+ }
+
+ public void testUnknownParameterClass() throws SQLException {
+ Account account = newAccount6();
+
+ sqlMap.update("insertAccountUknownParameterClass", account);
+
+ account = (Account) sqlMap.queryForObject("getAccountNullableEmail", new Integer(6));
+
+ assertAccount6(account);
+ }
+
+ public void testNullParameter() throws SQLException {
+
+ Account account = (Account) sqlMap.queryForObject("getAccountNullParameter", null);
+
+
+ assertNull(account);
+ }
+
+ public void testNullParameter2() throws SQLException {
+
+ Account account = (Account) sqlMap.queryForObject("getAccountNullParameter");
+
+
+ assertNull(account);
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/PrivateMethodAccessTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/PrivateMethodAccessTest.java?rev=683745&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/PrivateMethodAccessTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/PrivateMethodAccessTest.java Thu Aug 7 16:21:46 2008
@@ -0,0 +1,18 @@
+package com.ibatis.sqlmap;
+
+import java.util.List;
+
+public class PrivateMethodAccessTest extends BaseSqlMapTest {
+
+ protected void setUp() throws Exception {
+ initSqlMap("com/ibatis/sqlmap/maps/SqlMapConfig.xml", null);
+ initScript("scripts/docs-init.sql");
+ }
+
+ public void testShouldSetPrivateProperties() throws Exception {
+ List list = sqlMap.queryForList("getPrivateBooks");
+ assertNotNull(list);
+ assertEquals(2, list.size());
+ }
+
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/RepeatingGroupMappingTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/RepeatingGroupMappingTest.java?rev=683745&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/RepeatingGroupMappingTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/RepeatingGroupMappingTest.java Thu Aug 7 16:21:46 2008
@@ -0,0 +1,63 @@
+package com.ibatis.sqlmap;
+
+import testdomain.*;
+
+import java.util.List;
+
+public class RepeatingGroupMappingTest extends BaseSqlMapTest {
+
+ protected void setUp() throws Exception {
+ initSqlMap("com/ibatis/sqlmap/maps/SqlMapConfig.xml", null);
+ initScript("scripts/jpetstore-hsqldb-schema.sql");
+ initScript("scripts/jpetstore-hsqldb-dataload.sql");
+ }
+
+ public void testGroupBy() throws Exception {
+ List list = sqlMap.queryForList("getAllCategories", null);
+ assertEquals(5, list.size());
+ }
+
+ public void testGroupByExtended() throws Exception {
+ List list = sqlMap.queryForList("getAllCategoriesExtended", null);
+ assertEquals(5, list.size());
+ }
+
+ public void testNestedProperties() throws Exception {
+ List list = sqlMap.queryForList("getFish", null);
+ assertEquals(1, list.size());
+
+ Category cat = (Category) list.get(0);
+ assertEquals("FISH", cat.getCategoryId());
+ assertEquals("Fish", cat.getName());
+ assertNotNull("Expected product list.", cat.getProductList());
+ assertEquals(4, cat.getProductList().size());
+
+ Product product = (Product) cat.getProductList().get(0);
+ assertEquals(2, product.getItemList().size());
+ }
+
+ /**
+ * This is a test case for iBATIS JIRA-250 "SELECT statement
+ * returns unexpected result when 'groupBy' and 'nullValue'
+ * are specified in resultMaps."
+ * <p/>
+ * The problem was that when a child object in a resultmap only
+ * contained null values it would still be created when one of the
+ * properties of the child object contained a nullValue attribute
+ * in the ResultMap. The nullValue would be applied before checking
+ * whether all properties of the child were 'null', so at least 1
+ * property would always be non-null (the reason for the
+ * nullValue attribute).
+ * <p/>
+ * The fix is to first check whether all properties of the child are
+ * 'null', and if the child object contains at least 1 non-null property
+ * to then only create the child object and apply the nullValue attribute.
+ *
+ * @throws Exception none should be thrown.
+ */
+ public void testGroupByJIRA250() throws Exception {
+ List list = sqlMap.queryForList("getAllProductCategoriesJIRA250", null);
+ Category cat = (Category) list.get(0);
+ assertEquals(0, cat.getProductList().size());
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ResultMapTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ResultMapTest.java?rev=683745&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ResultMapTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ResultMapTest.java Thu Aug 7 16:21:46 2008
@@ -0,0 +1,133 @@
+package com.ibatis.sqlmap;
+
+import testdomain.*;
+
+import java.sql.SQLException;
+import java.util.*;
+
+public class ResultMapTest extends BaseSqlMapTest {
+
+ // SETUP & TEARDOWN
+
+ protected void setUp() throws Exception {
+ initSqlMap("com/ibatis/sqlmap/maps/SqlMapConfig.xml", null);
+ initScript("scripts/account-init.sql");
+ initScript("scripts/order-init.sql");
+ initScript("scripts/line_item-init.sql");
+ }
+
+ protected void tearDown() throws Exception {
+ }
+
+ // RESULT MAP FEATURE TESTS
+
+ public void testColumnsByName() throws SQLException {
+ Order order = (Order) sqlMap.queryForObject("getOrderLiteByColumnName", new Integer(1));
+ assertOrder1(order);
+ }
+
+ public void testExtendedResultMap() throws SQLException {
+ Order order = (Order) sqlMap.queryForObject("getOrderLiteByColumnName", new Integer(1));
+ assertOrder1(order);
+ }
+
+ public void testColumnsByIndex() throws SQLException {
+ Order order = (Order) sqlMap.queryForObject("getOrderLiteByColumnIndex", new Integer(1));
+ assertOrder1(order);
+ }
+
+ public void testTypeSpecified() throws SQLException {
+ Order order = (Order) sqlMap.queryForObject("getOrderWithTypes", new Integer(1));
+ assertOrder1(order);
+ }
+
+ public void testComplexObjectMapping() throws SQLException {
+ Order order = (Order) sqlMap.queryForObject("getOrderWithAccount", new Integer(1));
+ assertOrder1(order);
+ assertAccount1(order.getAccount());
+ }
+
+ public void testCollectionMappingAndExtends() throws SQLException {
+ Order order = (Order) sqlMap.queryForObject("getOrderWithLineItemsCollection", new Integer(1));
+
+ assertOrder1(order);
+ assertNotNull(order.getLineItems());
+ assertEquals(2, order.getLineItems().size());
+ }
+
+ public void testListMapping() throws SQLException {
+ Order order = (Order) sqlMap.queryForObject("getOrderWithLineItems", new Integer(1));
+
+ assertOrder1(order);
+ assertNotNull(order.getLineItemsList());
+ assertEquals(2, order.getLineItemsList().size());
+ }
+
+ public void testGetAllLineItemProps() throws SQLException {
+ List list = sqlMap.queryForList("getAllLineItemProps", new Integer(1));
+
+ assertNotNull(list);
+ assertEquals(2, list.size());
+ }
+
+ public void testArrayMapping() throws SQLException {
+ Order order = (Order) sqlMap.queryForObject("getOrderWithLineItemArray", new Integer(1));
+
+ assertOrder1(order);
+ assertNotNull(order.getLineItemArray());
+ assertEquals(2, order.getLineItemArray().length);
+ }
+
+ public void testHashMapMapping() throws SQLException {
+ Map order = (Map) sqlMap.queryForObject("getOrderAsMap", new Integer(1));
+ assertOrder1(order);
+ }
+
+ public void testNestedObjects() throws SQLException {
+ Order order = (Order) sqlMap.queryForObject("getOrderJoinedFavourite", new Integer(1));
+ assertOrder1(order);
+ }
+
+ public void testSimpleTypeMapping() throws SQLException {
+ List list = sqlMap.queryForList("getAllCreditCardNumbersFromOrders", null);
+
+ assertEquals(5, list.size());
+ assertEquals("555555555555", list.get(0));
+ }
+
+ public void testCompositeKeyMapping() throws SQLException {
+
+ Order order1 = (Order) sqlMap.queryForObject("getOrderWithFavouriteLineItem", new Integer(1));
+ Order order2 = (Order) sqlMap.queryForObject("getOrderWithFavouriteLineItem", new Integer(2));
+
+ assertNotNull(order1);
+ assertNotNull(order1.getFavouriteLineItem());
+ assertEquals(2, order1.getFavouriteLineItem().getId());
+ assertEquals(1, order1.getFavouriteLineItem().getOrderId());
+
+ assertNotNull(order2);
+ assertNotNull(order2.getFavouriteLineItem());
+ assertEquals(1, order2.getFavouriteLineItem().getId());
+ assertEquals(2, order2.getFavouriteLineItem().getOrderId());
+
+
+ }
+
+ public void testDynCompositeKeyMapping() throws SQLException {
+
+ Order order1 = (Order) sqlMap.queryForObject("getOrderWithDynFavouriteLineItem", new Integer(1));
+
+ assertNotNull(order1);
+ assertNotNull(order1.getFavouriteLineItem());
+ assertEquals(2, order1.getFavouriteLineItem().getId());
+ assertEquals(1, order1.getFavouriteLineItem().getOrderId());
+
+ }
+
+ public void testGetDoubleNestedResult() throws SQLException {
+ Account account = (Account) sqlMap.queryForObject("getNestedAccountViaColumnName", new Integer(1));
+ assertAccount1(account);
+ }
+
+
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ResultObjectFactoryImpl.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ResultObjectFactoryImpl.java?rev=683745&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ResultObjectFactoryImpl.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ResultObjectFactoryImpl.java Thu Aug 7 16:21:46 2008
@@ -0,0 +1,44 @@
+package com.ibatis.sqlmap;
+
+import org.apache.ibatis.reflection.ObjectFactory;
+import testdomain.*;
+
+import java.util.List;
+
+/**
+ * @author Jeff Butler
+ */
+public class ResultObjectFactoryImpl implements ObjectFactory {
+
+ /**
+ *
+ */
+ public ResultObjectFactoryImpl() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactory#createInstance(java.lang.String, java.lang.Class)
+ */
+ public Object create(Class clazz) {
+
+ Object obj = null;
+
+ if (clazz.equals(IItem.class)) {
+ obj = new IItemImpl();
+ } else if (clazz.equals((ISupplier.class))) {
+ obj = new ISupplierImpl();
+ } else if (clazz.equals((ISupplierKey.class))) {
+ obj = new ISupplierKeyImpl();
+ }
+
+ return obj;
+ }
+
+ public Object create(Class type, List<Class> constructorArgTypes, List<Object> constructorArgs) {
+ return create(type);
+ }
+
+ public void setProperty(String name, String value) {
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ResultObjectFactoryTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ResultObjectFactoryTest.java?rev=683745&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ResultObjectFactoryTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/ResultObjectFactoryTest.java Thu Aug 7 16:21:46 2008
@@ -0,0 +1,28 @@
+package com.ibatis.sqlmap;
+
+import testdomain.*;
+
+import java.util.List;
+
+public class ResultObjectFactoryTest extends BaseSqlMapTest {
+
+ protected void setUp() throws Exception {
+ initSqlMap("com/ibatis/sqlmap/maps/SqlMapConfig_rof.xml", null);
+ initScript("scripts/jpetstore-hsqldb-schema.sql");
+ initScript("scripts/jpetstore-hsqldb-dataload.sql");
+ }
+
+ /**
+ * This tests that the result object factory is working -
+ * everything in the sql map is declared as an interface.
+ */
+ public void testShouldDemonstrateThatTheObjectFactoryIsWorking() throws Exception {
+ List results = sqlMap.queryForList("getAllItemsROF");
+ assertEquals(28, results.size());
+ IItem iItem = (IItem) results.get(2);
+ ISupplier iSupplier = iItem.getSupplier();
+ Integer id = iSupplier.getSupplierId();
+ assertEquals((Integer) 1, id);
+ }
+
+}