⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logonactiontest.java

📁 一个功能较为完善的论坛
💻 JAVA
字号:
package org.redsoft.forum.web;

import javax.servlet.*;
import javax.servlet.http.*;
import org.redsoft.forum.fixture.MysqlFixture;

import servletunit.struts.MockStrutsTestCase;
import java.io.IOException;

import org.redsoft.forum.web.Account;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.redsoft.forum.ForumConstants;
import org.redsoft.forum.dao.DAOFactory;

/**
 * Title:        XP Forum
 * Description:
 * Copyright:    Copyright (c) 2002
 * Company:
 * @author Luo
 * @version 1.0
 * April 4, 2002
 */
/**
 * in order to compile and run this class, make sure that the followings are in your classpath:
 *             1.strutstest.jar
 *             2.the Path "\org\redsoft\forum\web" (which contains the "WEB-INF\struts-config.xml")
 */


public class LogonActionTest extends MockStrutsTestCase {

    private MysqlFixture mysqlFixtureIns = new MysqlFixture();

    public void setUp() throws Exception {
        super.setUp();
        DAOFactory.buildMockDAOFactory();
        //mysqlFixtureIns.setUp();
    }

    public void tearDown() throws Exception {
        super.tearDown();
        //mysqlFixtureIns.tearDown();
    }

    public LogonActionTest(String str) {
        super(str);
    }

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

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

    public void testGoodLogin() {
        //By default, the Struts ActionServlet will look for the file WEB-INF/struts-config.xml
        //so you must place the directory that contains WEB-INF in your CLASSPATH.
        //suppose have a User name:User1 password:111111
        setRequestPathInfo("/logon");
        addRequestParameter("userName", "User1");
        addRequestParameter("password", "111111");
        actionPerform();
        verifyForward("success");
//        verifyForwardPath("/logonsuccess.jsp");
//        assertEquals("User1", (String)(getSession().getAttribute(ForumConstants.USER_KEY)));
//        verifyNoActionErrors();
    }

/*
    public void testFailedLogin() {
        addRequestParameter("userName","xxxxxx");
        addRequestParameter("password","luo");
        setRequestPathInfo("/logon");
        actionPerform();
        verifyActionErrors(new String[] {"error.account.notFound"});
        assertNull((String)getSession().getAttribute(ForumConstants.USER_KEY));
    }
    public void testFailedPassword() {
        addRequestParameter("userName","User1");
        addRequestParameter("password","luo");
        setRequestPathInfo("/logon");
        actionPerform();
        verifyActionErrors(new String[] {"error.account.password"});
        assertNull((String)getSession().getAttribute(ForumConstants.USER_KEY));
    }
*/
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -