isami100のSwingin' Seasar日記

2000-01-12 test.s2study.app.login.dao

JdbcUserDaoTest.java

package test.s2study.app.login.dao;

import java.util.Arrays;

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.dataset.types.ColumnTypes;
import org.seasar.extension.unit.S2TestCase;

import s2study.app.entity.User;
import s2study.app.login.dao.UserDao;

public class JdbcUserDaoTest extends S2TestCase {

    private UserDao dao_;

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

    protected void tearDown() throws Exception {
    }

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

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

    public void testGetUserTx() throws Exception {
        readXlsReplaceDb("getUserPrepare.xls");
        User user = dao_.getUser("00001");
        DataTable result = new DataTableImpl("user");
        result.setupColumns(User.class);
        result.copyFrom(user);
        DataSet dataSet = readXls("getUserResult.xls");
        DataTable expect = dataSet.getTable("user");
        assertEquals("1", result, expect);
    }

}

UserDaoTest.java

package test.s2study.app.login.dao;

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.entity.User;
import s2study.app.login.dao.UserDao;

public class UserDaoTest extends S2TestCase {

    private UserDao dao_;

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

    protected void tearDown() throws Exception {
    }

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

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

    public void testGetUserTx() throws Exception {
        readXlsReplaceDb("getUserPrepare.xls");
        User user = dao_.getUser("00001");
        DataTable result = new DataTableImpl("user");
        result.setupColumns(User.class);
        result.copyFrom(user);
        DataSet dataSet = readXls("getUserResult.xls");
        DataTable expect = dataSet.getTable("user");
        assertEquals("1", result, expect);
    }

}

JdbcUserDaoTest.dicon



"http://www.seasar.org/dtd/components.dtd">
<components namespace="JdbcUserDaoTest">
    <!-- Handler -->
    <component name="userSelectHandler" class="org.seasar.extension.jdbc.impl.BasicSelectHandler">
        <property name="sql">
            "SELECT USERID, PASSWD, USERNAME FROM USER WHERE USERID = ?"
        </property>
        <property name="resultSetHandler">
            <component class="org.seasar.extension.jdbc.impl.BeanResultSetHandler">
                <arg>@s2study.app.entity.User@class</arg>
            </component>
        </property>
    </component>

    <!-- Dao -->
    <!-- S2JDBC     -->
    <component name="userDao" class="s2study.app.login.dao.JdbcUserDao">
        <arg>userSelectHandler</arg>
    </component>

</components>

UserDaoTest.dicon



"http://www.seasar.org/dtd/components.dtd">
<components namespace="UserDaoTest">
    <component name="userDao" class="s2study.app.login.dao.UserDao">
        <aspect>
            <component class="org.seasar.dao.interceptors.S2DaoInterceptor"/>
        </aspect>
    </component>
</components>