??????Struts2???е?????????struts 2.2.1.1??? ?????????struts2???а??е?struts2-junit-plugin-2.2.1.1.jar??????????????????StrutsTestCase??StrutsSpringTestCase??????????struts??ú?struts+spring????????????????????????????

????1.StrutsTestCase

????????????????struts2??????????????????????????μ???

????Account.java????bean

package model;

public class Account {
    private String userName;
    private String password;

    public Account() {
    }

    public Account(String userName?? String password) {
        this.userName = userName;
        this.password = password;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

????AccountAction.java

package action;

import com.opensymphony.xwork2.ActionSupport;
import model.Account;

import java.util.logging.Logger;

public class AccountAction extends ActionSupport{

    private Account accountBean;
    public String execute() throws Exception {
        return SUCCESS;
    }

    public void validate(){
        if (accountBean.getUserName().length()==0){
            addFieldError("accountBean.userName"??"User name is required.");
        }

        if (accountBean.getUserName().length()<5){
            addFieldError("accountBean.userName"??"User name must be at least 5 characters long.");
        }

        if (accountBean.getUserName().length()>10){
            addFieldError("accountBean.userName"??"User name cannot be at more thant 10 characters long.");
        }
    }

    public Account getAccountBean() {
        return accountBean;
    }

    public void setAccountBean(Account accountBean) {
        this.accountBean = accountBean;
    }
}