📄 actiontest.xdt
字号:
<XDtTagDef:tagDef namespace="Form" handler="org.example.antbook.xdoclet.FormTagsHandler"/><XDtTagDef:tagDef namespace="MethodEx" handler="org.example.antbook.xdoclet.MethodExTagsHandler"/>package <XDtForm:parentPackageName/>.webapp.action;import <XDtConfig:configParameterValue paramName="basePackageName"/>.webapp.action.BaseStrutsTestCase;import <XDtConfig:configParameterValue paramName="basePackageName"/>.Constants;import <XDtForm:parentPackageName/>.webapp.form.<XDtForm:className/>Form;public class <XDtForm:className/>ActionTest extends BaseStrutsTestCase { public <XDtForm:className/>ActionTest(String name) { super(name); } public void testAdd() throws Exception { setRequestPathInfo("/save<XDtForm:className/>"); addRequestParameter("method", "Save"); <XDtForm:className/>Form <XDtForm:classNameLower/>Form = new <XDtForm:className/>Form(); // set required fields <XDtMethodEx:forAllMethods> <XDtMethodEx:ifMethodTagValueEquals tagName="hibernate.property" paramName="not-null" value="true"> <XDtMethodEx:formSetterWithValue/> </XDtMethodEx:ifMethodTagValueEquals> <XDtMethodEx:ifMethodTagValueEquals tagName="hibernate.id" paramName="generator-class" value="assigned"> <XDtForm:classNameLower/>Form.<XDtMethodEx:setterMethod/>("4"); </XDtMethodEx:ifMethodTagValueEquals> </XDtMethodEx:forAllMethods> request.setAttribute(Constants.<XDtForm:classNameUpper/>_KEY, <XDtForm:classNameLower/>Form); actionPerform(); verifyNoActionErrors(); verifyForward("search"); } public void testSearch() { setRequestPathInfo("/<XDtForm:classNameLower/>s"); addRequestParameter("method", "Search"); actionPerform(); verifyNoActionErrors(); verifyForward("list"); assertNotNull(request.getAttribute(Constants.<XDtForm:classNameUpper/>_LIST)); } public void testEdit() throws Exception { setRequestPathInfo("/edit<XDtForm:className/>"); addRequestParameter("method", "Edit"); addRequestParameter("<XDtMethodEx:idField getType="propertyName"/>", "1"); actionPerform(); verifyNoActionErrors(); verifyForward("edit"); assertNotNull(request.getAttribute(Constants.<XDtForm:classNameUpper/>_KEY)); } public void testSave() throws Exception { setRequestPathInfo("/edit<XDtForm:className/>"); addRequestParameter("method", "Edit"); addRequestParameter("<XDtMethodEx:idField getType="propertyName"/>", "1"); actionPerform(); <XDtForm:className/>Form <XDtForm:classNameLower/>Form = (<XDtForm:className/>Form) request.getAttribute(Constants.<XDtForm:classNameUpper/>_KEY); assertNotNull(<XDtForm:classNameLower/>Form); setRequestPathInfo("/save<XDtForm:className/>"); addRequestParameter("method", "Save"); // update the form's required string fields and add it back to the request <XDtMethodEx:forAllMethods> <XDtMethodEx:ifMethodTagValueEquals tagName="hibernate.property" paramName="not-null" value="true"> <XDtMethodEx:formSetterWithValue/> </XDtMethodEx:ifMethodTagValueEquals> </XDtMethodEx:forAllMethods> request.setAttribute(Constants.<XDtForm:classNameUpper/>_KEY, <XDtForm:classNameLower/>Form); actionPerform(); verifyNoActionErrors(); verifyForward("edit"); // verify success messages verifyActionMessages(new String[] {"<XDtForm:classNameLower/>.updated"}); } public void testRemove() throws Exception { setRequestPathInfo("/edit<XDtForm:className/>"); addRequestParameter("method", "Delete"); addRequestParameter("<XDtMethodEx:idField getType="propertyName"/>", "2"); actionPerform(); verifyNoActionErrors(); verifyForward("search"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -