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

📄 formtest.xdt

📁 appfuse一套结合STRUTS+SPRING+HIBERNATE的框架
💻 XDT
字号:
<XDtTagDef:tagDef namespace="Form" handler="org.example.antbook.xdoclet.FormTagsHandler"/>package <XDtForm:parentPackageName/>.webapp.action;

import org.apache.tapestry.engine.ILink;

import <XDtConfig:configParameterValue paramName="basePackageName"/>.webapp.action.BasePageTestCase;
import <XDtConfig:configParameterValue paramName="basePackageName"/>.webapp.action.MockRequestCycle;
import <XDtPackage:packageName/>.<XDtForm:className/>;
import <XDtForm:parentPackageName/>.service.<XDtForm:className/>Manager;

import java.util.HashMap;
import java.util.Map;

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

    protected void onSetUp() throws Exception {
        super.onSetUp();
        // these can be mocked if you want a more "pure" unit test
        Map map = new HashMap();
        map.put("<XDtForm:classNameLower/>Manager", applicationContext.getBean("<XDtForm:classNameLower/>Manager"));
        page = (<XDtForm:className/>Form) getPage(<XDtForm:className/>Form.class, map);
    }

    protected void onTearDown() throws Exception {
        super.onTearDown();
        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/>);

        ILink link = page.save(new MockRequestCycle(this.getClass().getPackage().getName()));
        assertNotNull(page.get<XDtForm:className/>());
        assertFalse(page.hasErrors());
        assertEquals("<XDtForm:classNameLower/>s" + EXTENSION, link.getURL());
    }

    public void testSave() {
        <XDtForm:className/>Manager <XDtForm:classNameLower/>Manager = (<XDtForm:className/>Manager) applicationContext.getBean("<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/>);

        ILink link = page.save(new MockRequestCycle(this.getClass().getPackage().getName()));
        assertNotNull(page.get<XDtForm:className/>());
        assertFalse(page.hasErrors());
        assertNull(link);
    }

    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(new MockRequestCycle(this.getClass().getPackage().getName()));
        assertFalse(page.hasErrors());
    }
}

⌨️ 快捷键说明

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