isami100のSwingin' Seasar日記

2000-01-13 test.s2study.app.login.service

LoginServiceImplTest.java

package test.s2study.app.login.service;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.seasar.extension.unit.S2TestCase;
import org.seasar.framework.exception.SRuntimeException;

import s2study.app.entity.User;
import s2study.app.login.service.LoginService;

public class LoginServiceImplTest extends S2TestCase {

    private static final String PATH = "LoginServiceImplTest.dicon";
    private LoginService _loginService;

    public LoginServiceImplTest(String name) {
        super(name);
    }

    protected void setUp() throws Exception {
        include(PATH);
    }

    protected void tearDown() throws Exception {
    }

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

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

    public void testLoginSuccessful() throws Exception {
        User user = _loginService.certify("00001", "00001".getBytes());
        assertNotNull("1", user);
        assertEquals("2", "Okita", user.getUserName());
    }

    public void testUserNotFound() throws Exception {
        try {
            User user = _loginService.certify("12345", "12345".getBytes());
            fail("must not found user, but logined successful.");
        }
        catch (SRuntimeException sre) {
            assertEquals("1", "EAPP0001", sre.getMessageCode());
        }
    }

    public void testInvalidPassword() throws Exception {
        try {
            User user = _loginService.certify("00001", "12345".getBytes());
            fail("password was invalid, but ogined successful.");
        }
        catch (SRuntimeException sre) {
            assertEquals("1", "EAPP0001", sre.getMessageCode());
        }
    }
}

LoginServiceImplTest.dicon



"http://www.seasar.org/dtd/components.dtd">
<components namespace="LoginServiceImplTest">
    <!-- Dao -->
    <component name="userDao" class="s2study.app.login.service.DummyUserDao"/>

    <!-- Services -->
    <component name="loginService" class="s2study.app.login.service.LoginServiceImpl">
        <arg>userDao</arg>
    </component>

</components>