ZATS Richlet"

From Documentation
Line 2: Line 2:
 
{{ZATSEssentialsPageHeader}}
 
{{ZATSEssentialsPageHeader}}
  
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 following is a simple <tt>Richlet</tt> example:
+
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. When testing the <tt>Richlet</tt>, we only need to provide custom web configuration(such as '''web.xml''' and '''zk.xml''') for <tt>DefaultZatsEnvironment</tt>. The default configuration ZATS Mimic used doesn't support Richlet. We can specify the folder 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].
 +
 
 +
Following is a simple <tt>Richlet</tt> example, we assume that the '''src/main/webapp/WEB-INF''' folder contains the '''web.xml''' and '''zk.xml''':
  
 
'''web.xml'''
 
'''web.xml'''
Line 44: Line 46:
 
* '''Line 12, 14, 16''': After clicking the button, the text of label will be changed.
 
* '''Line 12, 14, 16''': After clicking the button, the text of label will be changed.
  
'''Notes'''
 
<references/>
 
 
----
 
----
  
  
When testing the <tt>Richlet</tt>, we only need to provide custom web configuration(such as '''web.xml''' and '''zk.xml''') for <tt>DefaultZatsEnvironment</tt>. The default configuration ZATS Mimic used doesn't support Richlet. We can specify the ''' WEB-INF''' folder path 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]. The following is a typical example for testing <tt>Richlet</tt>:
+
Following is a typical example of testing <tt>Richlet</tt>:
  
 
<source lang="java" start="10" high="12, 15, 22">
 
<source lang="java" start="10" high="12, 15, 22">
Line 70: Line 70:
 
* '''Line 12''': It specifies the folder path of web configuration for testing the <tt>Richlet</tt>.
 
* '''Line 12''': It specifies the folder path of web configuration for testing the <tt>Richlet</tt>.
 
* '''Line 22''': If we use the <tt>DefaultZatsEnvironment</tt> not <tt>Zats</tt>, it should be released when the test finish.
 
* '''Line 22''': If we use the <tt>DefaultZatsEnvironment</tt> not <tt>Zats</tt>, it should be released when the test finish.
 +
 +
'''Notes'''
 +
<references/>
  
 
{{ZATSEssentialsPageFooter}}
 
{{ZATSEssentialsPageFooter}}

Revision as of 02:21, 15 June 2012

WarningTriangle-32x32.png This page is under construction, so we cannot guarantee the accuracy of the content!

aowang



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. When testing the Richlet, we only need to provide custom web configuration(such as web.xml and zk.xml) for DefaultZatsEnvironment. The default configuration ZATS Mimic used doesn't support Richlet. We can specify the folder for the testing environment through the constructor of DefaultZatsEnvironment.

Following is a simple Richlet example, we assume that the src/main/webapp/WEB-INF folder contains the web.xml and zk.xml:

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: It specifies the folder path of web configuration for testing the Richlet.
  • Line 22: If we use the DefaultZatsEnvironment not Zats, it should be released when the test finish.

Notes

  1. for more detail, please refer to ZK_Developer's_Reference/UI_Composing/Richlet



Last Update : 2012/06/15

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.