isami100のSwingin' Seasar日記

2000-01-18 test.s2study.app.employeeref.dao

EmployeeDaoTest.java

package test.s2study.app.employeeref.dao;

import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import junit.framework.Test;
import junit.framework.TestSuite;
import org.seasar.extension.dataset.DataSet;
import org.seasar.extension.dataset.DataTable;
import org.seasar.extension.dataset.impl.DataTableImpl;
import org.seasar.extension.unit.S2TestCase;
import s2study.app.employeeref.dao.EmployeeDao;
import s2study.app.entity.Employee;

public class EmployeeDaoTest extends S2TestCase {

    private EmployeeDao dao_;

    public EmployeeDaoTest(String name) {
        super(name);
    }
    protected void setUp() throws Exception {
        include("j2ee.dicon");
        include("EmployeeDaoTest.dicon");
    }

    protected void tearDown() throws Exception {
    }

    public static Test suite() {
        return new TestSuite(EmployeeDaoTest.class);
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(suite());
    }

    public void testGetEmployees01Tx() throws Exception {
        readXlsReplaceDb("getEmployeesPrepare.xls");
        List employees =
            dao_.getEmployees(null, null, null, null, null, null, null);
        dumpBeans(employees);
        DataTable result = new DataTableImpl("emp");
        result.setupColumns(Employee.class);
        result.copyFrom(employees);
        DataSet dataSet = readXls("getEmployeesResult01.xls");
        DataTable expect = dataSet.getTable("emp");
        assertEquals("1", expect, result);
    }

    public void testGetEmployees02Tx() throws Exception {
        readXlsReplaceDb("getEmployeesPrepare.xls");
        List employees =
            dao_.getEmployees(
                new Integer(7800),
                null,
                null,
                null,
                null,
                null,
                null);
        dumpBeans(employees);
        DataTable result = new DataTableImpl("emp");
        result.setupColumns(Employee.class);
        result.copyFrom(employees);
        DataSet dataSet = readXls("getEmployeesResult02.xls");
        DataTable expect = dataSet.getTable("emp");
        assertEquals("1", expect, result);
    }

    public void testGetEmployees03Tx() throws Exception {
        readXlsReplaceDb("getEmployeesPrepare.xls");
        List employees =
            dao_.getEmployees(
                null,
                new Integer(7800),
                null,
                null,
                null,
                null,
                null);
        dumpBeans(employees);
        DataTable result = new DataTableImpl("emp");
        result.setupColumns(Employee.class);
        result.copyFrom(employees);
        DataSet dataSet = readXls("getEmployeesResult03.xls");
        DataTable expect = dataSet.getTable("emp");
        assertEquals("1", expect, result);
    }

    public void testGetEmployees04Tx() throws Exception {
        readXlsReplaceDb("getEmployeesPrepare.xls");
        List employees =
            dao_.getEmployees(null, null, "%M%", null, null, null, null);
        dumpBeans(employees);
        DataTable result = new DataTableImpl("emp");
        result.setupColumns(Employee.class);
        result.copyFrom(employees);
        DataSet dataSet = readXls("getEmployeesResult04.xls");
        DataTable expect = dataSet.getTable("emp");
        assertEquals("1", expect, result);
    }

    public void testGetEmployees05Tx() throws Exception {
        readXlsReplaceDb("getEmployeesPrepare.xls");
        List employees =
            dao_.getEmployees(
                null,
                null,
                null,
                createDate(1981, 9, 1),
                null,
                null,
                null);
        dumpBeans(employees);
        DataTable result = new DataTableImpl("emp");
        result.setupColumns(Employee.class);
        result.copyFrom(employees);
        DataSet dataSet = readXls("getEmployeesResult05.xls");
        DataTable expect = dataSet.getTable("emp");
        assertEquals("1", expect, result);
    }

    public void testGetEmployees06Tx() throws Exception {
        readXlsReplaceDb("getEmployeesPrepare.xls");
        List employees =
            dao_.getEmployees(
                null,
                null,
                null,
                null,
                createDate(1981, 8, 31),
                null,
                null);
        dumpBeans(employees);
        DataTable result = new DataTableImpl("emp");
        result.setupColumns(Employee.class);
        result.copyFrom(employees);
        DataSet dataSet = readXls("getEmployeesResult06.xls");
        DataTable expect = dataSet.getTable("emp");
        assertEquals("1", expect, result);
    }

    public void testGetEmployees07Tx() throws Exception {
        readXlsReplaceDb("getEmployeesPrepare.xls");
        List employees =
            dao_.getEmployees(
                null,
                null,
                null,
                null,
                null,
                new Integer(2000),
                null);
        dumpBeans(employees);
        DataTable result = new DataTableImpl("emp");
        result.setupColumns(Employee.class);
        result.copyFrom(employees);
        DataSet dataSet = readXls("getEmployeesResult07.xls");
        DataTable expect = dataSet.getTable("emp");
        assertEquals("1", expect, result);
    }

    public void testGetEmployees08Tx() throws Exception {
        readXlsReplaceDb("getEmployeesPrepare.xls");
        List employees =
            dao_.getEmployees(
                null,
                null,
                null,
                null,
                null,
                null,
                new Integer(2000));
        dumpBeans(employees);
        DataTable result = new DataTableImpl("emp");
        result.setupColumns(Employee.class);
        result.copyFrom(employees);
        DataSet dataSet = readXls("getEmployeesResult08.xls");
        DataTable expect = dataSet.getTable("emp");
        assertEquals("1", expect, result);
    }

    public void testGetEmployees09Tx() throws Exception {
        readXlsReplaceDb("getEmployeesPrepare.xls");
        List employees =
            dao_.getEmployees(
                new Integer(7500),
                new Integer(7900),
                "%A%",
                createDate(1980, 9, 01),
                createDate(1981, 9, 01),
                new Integer(1500),
                new Integer(2500));
        dumpBeans(employees);
        DataTable result = new DataTableImpl("emp");
        result.setupColumns(Employee.class);
        result.copyFrom(employees);
        DataSet dataSet = readXls("getEmployeesResult09.xls");
        DataTable expect = dataSet.getTable("emp");
        assertEquals("1", expect, result);
    }

    private void dumpBeans(List beans) {
        Iterator iter = beans.iterator();
        while (iter.hasNext()) {
            System.out.println(iter.next());
        }
    }

    private Date createDate(int year, int month, int date) {
        Calendar cal = Calendar.getInstance();
        cal.set(year, month - 1, date);
        return cal.getTime();
    }

}

Db2Excel4Prepare.dicon



"http://www.seasar.org/dtd/components.dtd">
<components>
    <include path="j2ee.dicon"/>
    <component class="org.seasar.extension.dataset.impl.SqlReader">
        <initMethod>#self.addTable("emp", null)</initMethod>
        <initMethod>#self.addTable("dept", null)</initMethod>
    </component>
    <component class="org.seasar.extension.dataset.impl.XlsWriter" instance="prototype">
        <arg>"../src/test/s2study/app/employeeref/dao/getEmployeesPrepare.xls"</arg>
    </component>
</components>

Db2Excel4Result.dicon



"http://www.seasar.org/dtd/components.dtd">
<components>
    <include path="j2ee.dicon"/>
    <component class="org.seasar.extension.dataset.impl.SqlReader">
        <initMethod>
            #self.addSql("SELECT e.*, d.dname, d.loc
            FROM emp e, dept d WHERE e.deptno = d.deptno", "emp")
        </initMethod>
    </component>
    <component class="org.seasar.extension.dataset.impl.XlsWriter" instance="prototype">
        <arg>"../src/test/s2study/app/employeeref/dao/getEmployeesResult.xls"</arg>
    </component>
</components>

EmployeeDaoTest.dicon



"http://www.seasar.org/dtd/components.dtd">
<components>
    <component class="s2study.app.employeeref.dao.EmployeeDao">
        <aspect>
            <component class="org.seasar.dao.interceptors.S2DaoInterceptor"/>
        </aspect>
    </component>
</components>