Download"

From Documentation
m
Line 32: Line 32:
 
== Download files in a ZATS Mimic test case ==
 
== Download files in a ZATS Mimic test case ==
  
In order to simulate same behavior as ZK client engine doing, ZATS Mimic introduces the <tt>Resource</tt> interface. It represents a downloadable resource file at server. The typical steps for testing downloading are:
+
In order to simulate the behaviour of ZK client engine, ZATS Mimic introduces the <tt>Resource</tt> interface which represents a downloadable resource file saved at the server. Typical steps for testing whether a ZUL containing download features are as follows:
 +
 
 
# perform some operations through operation agents
 
# perform some operations through operation agents
# check is there a downloadable resource through desktop agent
+
# check presence of a downloadable resource through desktop agent
 
# fetch and verify the information or content of the resource
 
# fetch and verify the information or content of the resource
  
Line 50: Line 51:
 
}
 
}
 
</source>
 
</source>
* '''Line 14-16''': Because ZATS Mimic handles the response from ZK application automatically, we can get the current downloadable resource file from the <tt>DesktopAgent.getDownloadable()</tt>. The method might return <tt>null</tt> when getting the downloadable resource, it indicates that there is no downloadable resource after the previous operation.
+
* '''Line 14-16''': Since ZATS Mimic handles the response from ZK application automatically, we can retrieve current downloadable resource files from <tt>DesktopAgent.getDownloadable()</tt>. If the method returns a <tt>null</tt> when attempting to retrieve downloadable resources, it indicates that there are no downloadable resources after the previous operation.
* '''Line 17-19''': We can get more information from <tt>Resource</tt>, or fetch the content of resource file in binary through the input stream.
+
* '''Line 17-19''': We can get more information from <tt>Resource</tt>, or fetch the content of resource files in binary through the input stream.
  
 
{{ZATSEssentialsPageFooter}}
 
{{ZATSEssentialsPageFooter}}

Revision as of 08:18, 13 June 2012

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


Since 1.1.0


We usually perform file downloading through Filedownload when some events are triggered [1]. Following is a typical example of downloading a file:

download.zul

<zk>
	<div apply="DownloadComposer">
		<button id="btn" label="download" />
	</div>
</zk>

DownloadComposer.java

public class DownloadComposer extends GenericForwardComposer {
	@Listen("onClick=#btn")
	public void download() throws IOException {
		Filedownload.save("/hello.txt", "application/octet-stream");
	}
}

The download mechanism is a process containing two steps. When you invoke save(), the Filedownload simply notifies ZK client engine of the download URL. Then, ZK client engine downloads such file according to the referred URL.

Notes

Download files in a ZATS Mimic test case

In order to simulate the behaviour of ZK client engine, ZATS Mimic introduces the Resource interface which represents a downloadable resource file saved at the server. Typical steps for testing whether a ZUL containing download features are as follows:

  1. perform some operations through operation agents
  2. check presence of a downloadable resource through desktop agent
  3. fetch and verify the information or content of the resource
@Test
public void test() throws Exception {
	DesktopAgent desktop = Zats.newClient().connect("/download.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);
}
  • Line 14-16: Since ZATS Mimic handles the response from ZK application automatically, we can retrieve current downloadable resource files from DesktopAgent.getDownloadable(). If the method returns a null when attempting to retrieve downloadable resources, it indicates that there are no downloadable resources after the previous operation.
  • Line 17-19: We can get more information from Resource, or fetch the content of resource files in binary through the input stream.



Last Update : 2012/06/13

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