??????????

????TestAccountAction.java

package ut;

import action.AccountAction;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.config.ConfigurationProvider;
import org.apache.struts2.StrutsTestCase;

import static org.testng.AssertJUnit.*;


public class TestAccountAction extends StrutsTestCase {
    private AccountAction action;
    private ActionProxy proxy;

    private void init() {
        proxy = getActionProxy("/createaccount"); //action url??????д?????".action"???????д
        action = (AccountAction) proxy.getAction();
    }

    public void testUserNameErrorMessage() throws Exception {
        request.setParameter("accountBean.userName"?? "Bruc");
        request.setParameter("accountBean.password"?? "test");

        init();
        proxy.execute();

        assertTrue("Problem There were no errors present in fieldErrors but there should have been one error present"??
                action.getFieldErrors().size() == 1);
        assertTrue("Problem field account.userName not present in fieldErrors but it should have been"??
                action.getFieldErrors().containsKey("accountBean.userName"));
    }

    public void testUserNameCorrect() throws Exception{
        request.setParameter("accountBean.userName"?? "Bruce");
        request.setParameter("accountBean.password"?? "test");

        init();
        String result=proxy.execute();

        assertTrue("Problem There were errors present in fieldErrors but there should not have been any errors present"??
                action.getFieldErrors().size()==0);

        assertEquals("Result returned form executing the action was not success but it should have been."??
                "success"?? result);

    }
}

?????????????????action?е?validate??????????????????5????9???

????????struts.xml????????·????????£?????web-inf/classes?£??????????????????????????????

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        http://struts.apache.org/dtds/struts-2.0.dtd>
<struts>
    <package name="testit" namespace="/" extends="struts-default">
        <action name="createaccount" class="action.AccountAction">
            <result name="success">/index.jsp</result>
            <result name="input">/createaccount.jsp</result>
        </action>
    </package>
</struts>

????????action/result????????????jsp??棬?????????????????????У?????action???????????resultδ???????????????????????action??????μ????С????У????OK??

????????????????????μ????У??????????????????????????????????????????????????£?

????MyInterceptor.java

package interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class MyInterceptor extends AbstractInterceptor{

    public String intercept(ActionInvocation actionInvocation) throws Exception {
        System.out.println("before processing");
       String rst= actionInvocation.invoke();
        System.out.println("bye bye "+actionInvocation.getProxy().getMethod());
        return rst;
    }
}