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

📄 formtest.xdt

📁 spring struts hibernate
💻 XDT
字号:
<XDtTagDef:tagDef namespace="Form" handler="org.example.antbook.xdoclet.FormTagsHandler"/>package <XDtForm:parentPackageName/>.webapp.action;

import java.util.ResourceBundle;

import <XDtPackage:packageName/>.<XDtForm:className/>;
import <XDtForm:parentPackageName/>.service.<XDtForm:className/>Manager;

public class <XDtForm:className/>FormTest extends BasePageTestCase {
    private <XDtForm:className/>Form page;
	private <XDtForm:className/>Manager <XDtForm:classNameLower/>Manager;

    protected void setUp() throws Exception {    
        super.setUp();
        page = (<XDtForm:className/>Form) getPage(<XDtForm:className/>Form.class);
        
        // unfortunately this is a required step if you're calling 
        // getMessage in the page class
        page.setBundle(ResourceBundle.getBundle(MESSAGES));
        page.setValidationDelegate(new Validator());

        // this manager can be mocked if you want a more "pure" unit test
        <XDtForm:classNameLower/>Manager = (<XDtForm:className/>Manager) ctx.getBean("<XDtForm:classNameLower/>Manager");
        page.set<XDtForm:className/>Manager(<XDtForm:classNameLower/>Manager);
        
        // default request cycle
        page.setRequestCycle(getCycle(request, response));
    }

    protected void tearDown() throws Exception {
        super.tearDown();
        page = null;
    }

    public void testAdd() throws Exception {
        <XDtForm:className/> <XDtForm:classNameLower/> = new <XDtForm:className/>();
        // update the object's fields
        <XDtMethodEx:forAllMethods>
        <XDtMethodEx:ifMethodTagValueEquals tagName="hibernate.property" paramName="not-null" value="true">
        <XDtMethodEx:setterWithValue/>
        </XDtMethodEx:ifMethodTagValueEquals>
        </XDtMethodEx:forAllMethods>
        page.set<XDtForm:className/>(<XDtForm:classNameLower/>);

        page.save(page.getRequestCycle());
        assertFalse(page.hasErrors());
    }

    public void testSave() {
    	assertNotNull(<XDtForm:classNameLower/>Manager);
        <XDtForm:className/> <XDtForm:classNameLower/> = <XDtForm:classNameLower/>Manager.get<XDtForm:className/>("1");

        // update fields
        <XDtMethodEx:forAllMethods>
        <XDtMethodEx:ifMethodTagValueEquals tagName="hibernate.property" paramName="not-null" value="true">
        <XDtMethodEx:setterWithValue/>
        </XDtMethodEx:ifMethodTagValueEquals>
        </XDtMethodEx:forAllMethods>
        page.set<XDtForm:className/>(<XDtForm:classNameLower/>);

        page.save(page.getRequestCycle());
        assertFalse(page.hasErrors());
    }

    public void testRemove() throws Exception {
        <XDtForm:className/> <XDtForm:classNameLower/> = new <XDtForm:className/>();
        <XDtForm:classNameLower/>.<XDtMethodEx:idField getType="setterName"/>(new <XDtMethodEx:idField getType="propertyType"/>("2"));
        page.set<XDtForm:className/>(<XDtForm:classNameLower/>);

        page.delete(page.getRequestCycle());
        assertFalse(page.hasErrors());
    }
}

⌨️ 快捷键说明

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