ZATS Richlet"
From Documentation
(Created page with "{{Template:UnderConstruction}} {{ZATSEssentialsPageHeader}} ZATS Mimic also support Richlet<ref>for more detail, please refer to [[ZK_Developer%27s_Reference/UI_Composing/Richle...") |
m (correct highlight (via JWB)) |
||
(10 intermediate revisions by one other user not shown) | |||
Line 2: | Line 2: | ||
{{ZATSEssentialsPageHeader}} | {{ZATSEssentialsPageHeader}} | ||
− | ZATS Mimic also | + | ZATS Mimic also supports to test <javadoc>org.zkoss.zk.ui.Richlet</javadoc><ref>for more detail, please refer to [[ZK_Developer%27s_Reference/UI_Composing/Richlet]]</ref>. It just needs a few custom configuration for [http://www.zkoss.org/javadoc/latest/zats/org/zkoss/zats/mimic/DefaultZatsEnvironment.html DefaultZatsEnvironment] and the test code is no different with testing a ZUML file. The ZATS Mimic built-in web configuration doesn't support Richlet. We can specify the folder contained 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 <code>Richlet</code>. |
+ | |||
+ | Following is a simple <code>Richlet</code> example, we assume that the '''web.xml''' and '''zk.xml''' are placed in the '''src/main/webapp/WEB-INF''' folder: | ||
'''web.xml''' | '''web.xml''' | ||
− | <source lang="xml" start="10" | + | <source lang="xml" start="10" highlight="11,12"> |
<servlet-mapping> | <servlet-mapping> | ||
<servlet-name>zkLoader</servlet-name> | <servlet-name>zkLoader</servlet-name> | ||
Line 13: | Line 15: | ||
'''zk.xml''' | '''zk.xml''' | ||
− | <source lang="xml" start="10" | + | <source lang="xml" start="10" highlight="12,16"> |
<richlet> | <richlet> | ||
<richlet-name>MyRichlet</richlet-name> | <richlet-name>MyRichlet</richlet-name> | ||
Line 24: | Line 26: | ||
</source> | </source> | ||
+ | '''MyRichlet.java''' | ||
+ | <source lang="java" start="10" highlight="12,14,16,19,20"> | ||
+ | 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); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | * '''Line 12, 14, 16''': After clicking the button, the text of label will be changed. | ||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | Following is a typical example of testing <code>Richlet</code>: | ||
+ | |||
+ | <source lang="java" start="10" highlight="12, 15, 22"> | ||
+ | @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(); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | * '''Line 12''': Specify the folder contains web configuration for testing the <code>Richlet</code>. | ||
+ | * '''Line 22''': Release the <code>DefaultZatsEnvironment</code> manually when the test finish. | ||
+ | |||
+ | ---- | ||
'''Notes''' | '''Notes''' | ||
<references/> | <references/> | ||
{{ZATSEssentialsPageFooter}} | {{ZATSEssentialsPageFooter}} |
Latest revision as of 02:59, 20 January 2022
ZATS Mimic also supports to test Richlet[1]. It just needs a few custom configuration for DefaultZatsEnvironment and the test code is no different with testing a ZUML file. The ZATS Mimic built-in web configuration doesn't support Richlet. We can specify the folder contained 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 detail, please refer to ZK_Developer's_Reference/UI_Composing/Richlet