Test Richlet"
From Documentation
m |
|||
Line 2: | Line 2: | ||
{{ZATSEssentialsPageHeader}} | {{ZATSEssentialsPageHeader}} | ||
− | ZATS Mimic also supports | + | ZATS Mimic also supports the testing of <javadoc>org.zkoss.zk.ui.Richlet</javadoc><ref>For more details, please refer to [[ZK_Developer%27s_Reference/UI_Composing/Richlet]]</ref>. Simply customize a few configurations for [http://www.zkoss.org/javadoc/latest/zats/org/zkoss/zats/mimic/DefaultZatsEnvironment.html DefaultZatsEnvironment] and the test code would be no different to testing a ZUML file. ZATS Mimic's built-in web configuration does not support Richlet, however, we can specify the folder containing custom web configuration ('''web.xml''' and '''zk.xml''') for the testing environment through the constructor of [http://www.zkoss.org/javadoc/latest/zats/org/zkoss/zats/mimic/DefaultZatsEnvironment.html#DefaultZatsEnvironment(java.lang.String) DefaultZatsEnvironment] when testing <tt>Richlet</tt>. |
Following is a simple <tt>Richlet</tt> example, we assume that the '''web.xml''' and '''zk.xml''' are placed in the '''src/main/webapp/WEB-INF''' folder: | Following is a simple <tt>Richlet</tt> example, we assume that the '''web.xml''' and '''zk.xml''' are placed in the '''src/main/webapp/WEB-INF''' folder: |
Revision as of 09:38, 22 June 2012
ZATS Mimic also supports the testing of Richlet[1]. Simply customize a few configurations for DefaultZatsEnvironment and the test code would be no different to testing a ZUML file. ZATS Mimic's built-in web configuration does not support Richlet, however, we can specify the folder containing custom web configuration (web.xml and zk.xml) for the testing environment through the constructor of DefaultZatsEnvironment when testing Richlet.
Following is a simple Richlet example, we assume that the web.xml and zk.xml are placed in the src/main/webapp/WEB-INF folder:
web.xml
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>/zk/*</url-pattern>
</servlet-mapping>
zk.xml
<richlet>
<richlet-name>MyRichlet</richlet-name>
<richlet-class>foo.MyRichlet</richlet-class>
</richlet>
<richlet-mapping>
<richlet-name>MyRichlet</richlet-name>
<url-pattern>/foo</url-pattern>
</richlet-mapping>
MyRichlet.java
public class MyRichlet extends GenericRichlet {
public void service(Page page) throws Exception {
final Label message = new Label("foo");
Button button = new Button("go");
button.addEventListener(Events.ON_CLICK, new EventListener() {
public void onEvent(Event event) throws Exception {
message.setValue("bar");
}
});
button.setId("btn");
message.setId("msg");
button.setPage(page);
message.setPage(page);
}
}
- Line 12, 14, 16: After clicking the button, the text of label will be changed.
Following is a typical example of testing Richlet:
@Test
public void test() {
DefaultZatsEnvironment env = new DefaultZatsEnvironment("./src/main/webapp/WEB-INF");
try {
env.init("./src/main/webapp");
DesktopAgent desktop = env.newClient().connect("/zk/foo");
Label msg = desktop.query("#msg").as(Label.class);
Assert.assertEquals("foo", msg.getValue());
desktop.query("#btn").click();
Assert.assertEquals("bar", msg.getValue());
}
finally {
env.destroy();
}
}
- Line 12: Specify the folder contains web configuration for testing the Richlet.
- Line 22: Release the DefaultZatsEnvironment manually when the test finish.
Notes
- ↑ For more details, please refer to ZK_Developer's_Reference/UI_Composing/Richlet