001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.gl.dao.ojb;
017:
018: import java.math.BigDecimal;
019: import java.util.Iterator;
020: import java.util.List;
021: import java.util.Map;
022:
023: import org.kuali.core.util.TransactionalServiceUtils;
024: import org.kuali.core.util.UnitTestSqlDao;
025: import org.kuali.kfs.context.KualiTestBase;
026: import org.kuali.kfs.context.SpringContext;
027: import org.kuali.test.ConfigureContext;
028:
029: @ConfigureContext
030: public class TestUnitTestSqlDao extends KualiTestBase {
031: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
032: .getLogger(TestUnitTestSqlDao.class);
033:
034: private UnitTestSqlDao unitTestSqlDao;
035:
036: public TestUnitTestSqlDao() {
037: super ();
038: }
039:
040: @Override
041: protected void setUp() throws Exception {
042: super .setUp();
043:
044: unitTestSqlDao = SpringContext.getBean(UnitTestSqlDao.class);
045: }
046:
047: public void testSelect() throws Exception {
048: LOG.debug("testSelect() started");
049:
050: List results = unitTestSqlDao.sqlSelect("select 1 from dual");
051:
052: assertNotNull("List shouldn't be null", results);
053: assertEquals("Should return 1 result", 1, results.size());
054:
055: Iterator i = results.iterator();
056: if (i.hasNext()) {
057: Map m = (Map) i.next();
058: assertEquals("Map should have 1 field", 1, m.size());
059: Number value = (Number) m.get("1");
060: assertEquals("Field should equal 1", 1.00, value
061: .doubleValue(), 0.01);
062: }
063: TransactionalServiceUtils.exhaustIterator(i);
064: }
065:
066: public void testAllSql() throws Exception {
067: LOG.debug("testAllSql() started");
068:
069: // Delete from a table (just in case the code is already there)
070: unitTestSqlDao
071: .sqlCommand("delete from SH_STATE_T where POSTAL_STATE_CD = 'JJ'");
072:
073: // Insert into the table
074: int rows = unitTestSqlDao
075: .sqlCommand("insert into SH_STATE_T (POSTAL_STATE_CD,POSTAL_STATE_NM, OBJ_ID) values ('JJ','JJSTATE', 'BLAH BLAH BLAH')");
076: assertEquals("Should have inserted 1 row", 1, rows);
077:
078: List results = unitTestSqlDao
079: .sqlSelect("select POSTAL_STATE_CD,POSTAL_STATE_NM from SH_STATE_T where POSTAL_STATE_CD = 'JJ'");
080: assertNotNull("List shouldn't be null", results);
081: assertEquals("Should return 1 result", 1, results.size());
082: Iterator i = results.iterator();
083: Map row = (Map) i.next();
084:
085: assertEquals("State code should be JJ", "JJ", (String) row
086: .get("POSTAL_STATE_CD"));
087: assertEquals("State name should be JJSTATE", "JJSTATE",
088: (String) row.get("POSTAL_STATE_NM"));
089:
090: rows = unitTestSqlDao
091: .sqlCommand("update SH_STATE_T set POSTAL_STATE_NM = 'JJXX' where POSTAL_STATE_CD = 'JJ'");
092: assertEquals("Should have updated 1 row", 1, rows);
093:
094: results = unitTestSqlDao
095: .sqlSelect("select POSTAL_STATE_CD,POSTAL_STATE_NM from SH_STATE_T where POSTAL_STATE_CD = 'JJ'");
096: assertNotNull("List shouldn't be null", results);
097: assertEquals("Should return 1 result", 1, results.size());
098: i = results.iterator();
099: row = (Map) i.next();
100:
101: assertEquals("State code should be JJ", "JJ", (String) row
102: .get("POSTAL_STATE_CD"));
103: assertEquals("State name should be JJXX", "JJXX", (String) row
104: .get("POSTAL_STATE_NM"));
105:
106: rows = unitTestSqlDao
107: .sqlCommand("delete from SH_STATE_T where POSTAL_STATE_CD = 'JJ'");
108: assertEquals("Should have deleted 1 row", 1, rows);
109: }
110: }
|