ZATS Cookies

From Documentation
< User:Paowang
Revision as of 07:06, 8 June 2012 by Paowang (talk | contribs) (Created page with "{{Template:UnderConstruction}} {{ZATSEssentialsPageHeader}} Since 1.1.0 =Cookies= We usually perform the file downloading through the <javadoc>org.zkoss.zul.Filedownload</java...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

aowang



Since 1.1.0

Cookies

We usually perform the file downloading through the Filedownload when some events occurred[1]. The following is a typical example about downloading a file:

<zk>
	<button id="btn" label="download">
		<attribute name="onClick"><![CDATA[
			org.zkoss.zul.Filedownload.save("foo.txt", "application/octet-stream");
		]]>
		</attribute>
	</button>
</zk>

Actually, the downloaded mechanism is a process with two steps. When you invoke save(), the Filedownload simply notifies ZK client engine of the downloaded URL. Then, the ZK client engine downloads such files according to the received URL.

Notes

Download files in a ZATS Mimic test case

In order to simulate same behavior as ZK client engine doing, ZATS Mimic introduces the Resource interface. It represents a downloadable resource file at server. The typical steps for testing downloading are:

  1. perform some operations through operation agents
  2. check is there a downloadable resource through desktop agent
  3. fetch and verify the information or content of the resource
@Test
public void test() throws Exception {
	Zats.init(".");
	try {
		DesktopAgent desktop = Zats.newClient().connect("/foo.zul");
		Assert.assertNull(desktop.getDownloadable());

		desktop.query("#btn").click();
		Resource resource = desktop.getDownloadable();
		Assert.assertNotNull(resource);
		Assert.assertEquals("hello.txt", resource.getName());
		String content = fetchContent(resource.getInputStream());
		Assert.assertEquals("Hello world!", content);
	} finally {
		Zats.end();
	}
}
  • Line 6, 9, 10: Because ZATS Mimic handles the response from ZK application automatically, we can get the current downloadable resource file from the DesktopAgent.getDownloadable(). The method might return null when getting the downloadable resource, it indicates that there is no downloadable resource after the previous operation.
  • Line 11-13: We can get more information from Resource, or fetch the content of resource file in binary through the input stream.



Last Update : 2012/06/08

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