1 |
3535
|
barteau
|
/*
|
2 |
|
|
* ClientViewHelperTest.java
|
3 |
|
|
* JUnit based test
|
4 |
|
|
*
|
5 |
|
|
* Created on October 25, 2007, 5:11 PM
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
package edu.ucsb.nceas.metacat.clientview;
|
9 |
|
|
|
10 |
|
|
import java.io.ByteArrayOutputStream;
|
11 |
|
|
import java.io.File;
|
12 |
|
|
import junit.framework.*;
|
13 |
|
|
import com.oreilly.servlet.multipart.MultipartParser;
|
14 |
|
|
import java.io.InputStream;
|
15 |
|
|
import java.util.HashMap;
|
16 |
|
|
import java.util.Stack;
|
17 |
|
|
import java.util.TreeMap;
|
18 |
|
|
import javax.servlet.http.HttpServletRequest;
|
19 |
|
|
import javax.servlet.http.HttpServletResponse;
|
20 |
|
|
import javax.servlet.http.HttpSession;
|
21 |
|
|
import javax.xml.xpath.XPath;
|
22 |
|
|
import org.w3c.dom.Document;
|
23 |
|
|
import org.w3c.dom.Node;
|
24 |
|
|
|
25 |
4125
|
daigle
|
import edu.ucsb.nceas.metacat.client.MetacatClient;
|
26 |
5035
|
daigle
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
27 |
4125
|
daigle
|
|
28 |
3535
|
barteau
|
/**
|
29 |
3536
|
barteau
|
* ClientViewHelper JUnit tests
|
30 |
3535
|
barteau
|
* @author barteau
|
31 |
|
|
*/
|
32 |
|
|
public class ClientViewHelperTest extends TestCase {
|
33 |
|
|
ClientViewHelper instance;
|
34 |
|
|
ClientView clientViewBean;
|
35 |
|
|
|
36 |
4125
|
daigle
|
// final static String PATH_TO_PROPERTIES = "projects/metacat/build/war/WEB-INF/metacat.properties";
|
37 |
|
|
final static String PATH_TO_PROPERTIES = "projects/metacat/build/war/WEB-INF";
|
38 |
3537
|
barteau
|
final static String USR = "";
|
39 |
3535
|
barteau
|
final static String ORG = "NCEAS";
|
40 |
3537
|
barteau
|
final static String PWD = "";
|
41 |
|
|
final static String DOWNLOAD_PACKAGE_DOCID = "";
|
42 |
|
|
final static String DOWNLOAD_DATA_DOCID = "";
|
43 |
3536
|
barteau
|
final static String HOST = "localhost:8084";
|
44 |
|
|
final static String CONTEXT = "/sanparks";
|
45 |
3535
|
barteau
|
|
46 |
3536
|
barteau
|
/**
|
47 |
|
|
* Constructor
|
48 |
|
|
* @param testName String
|
49 |
|
|
*/
|
50 |
3535
|
barteau
|
public ClientViewHelperTest(String testName) {
|
51 |
|
|
super(testName);
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
protected void setUp() throws Exception {
|
55 |
|
|
if (PWD.equals(""))
|
56 |
|
|
fail("Please set the class property PWD before running this test.");
|
57 |
|
|
if (USR.equals(""))
|
58 |
|
|
fail("Please set the class property USR before running this test.");
|
59 |
|
|
if (DOWNLOAD_PACKAGE_DOCID.equals(""))
|
60 |
|
|
fail("Please set the class property DOWNLOAD_PACKAGE_DOCID before running this test.");
|
61 |
|
|
if (DOWNLOAD_DATA_DOCID.equals(""))
|
62 |
|
|
fail("Please set the class property DOWNLOAD_DATA_DOCID before running this test.");
|
63 |
|
|
|
64 |
4719
|
daigle
|
// PropertyService.getInstance(PATH_TO_PROPERTIES);
|
65 |
|
|
PropertyService.getInstance();
|
66 |
3535
|
barteau
|
|
67 |
|
|
clientViewBean = new ClientView();
|
68 |
|
|
clientViewBean.setUsername(USR);
|
69 |
|
|
clientViewBean.setOrganization(ORG);
|
70 |
|
|
clientViewBean.setPassword(PWD);
|
71 |
|
|
|
72 |
3536
|
barteau
|
instance = new ClientViewHelper(HOST, CONTEXT, clientViewBean);
|
73 |
3535
|
barteau
|
}
|
74 |
|
|
|
75 |
|
|
protected void tearDown() throws Exception {
|
76 |
|
|
clientViewBean = null;
|
77 |
|
|
instance = null;
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
/**
|
81 |
|
|
* Test of handleClientRequest method, of class edu.ucsb.nceas.metacat.clientview.ClientViewHelper.
|
82 |
|
|
*/
|
83 |
|
|
public void testHandleClientRequest() {
|
84 |
|
|
HashMap expResult, result;
|
85 |
|
|
String expResultTxt, returnResultTxt;
|
86 |
|
|
|
87 |
|
|
System.out.println("handleClientRequest");
|
88 |
|
|
|
89 |
3536
|
barteau
|
|
90 |
3535
|
barteau
|
System.out.print("...setLoggedIn");
|
91 |
|
|
clientViewBean.setAction("Login");
|
92 |
3536
|
barteau
|
|
93 |
3535
|
barteau
|
result = instance.handleClientRequest(null);
|
94 |
|
|
returnResultTxt = (String) result.get("message");
|
95 |
3677
|
leinfelder
|
assertTrue("Login: Failed to login", (returnResultTxt.indexOf("Authentication successful for user:") > -1));
|
96 |
3535
|
barteau
|
System.out.println(" ...success!");
|
97 |
|
|
|
98 |
3536
|
barteau
|
|
99 |
3535
|
barteau
|
System.out.print("...download (data file)");
|
100 |
|
|
clientViewBean.setAction("Download");
|
101 |
3538
|
barteau
|
clientViewBean.setDocId(DOWNLOAD_DATA_DOCID);
|
102 |
|
|
clientViewBean.setMetaFileDocId(DOWNLOAD_PACKAGE_DOCID);
|
103 |
3535
|
barteau
|
|
104 |
|
|
result = instance.handleClientRequest(null);
|
105 |
|
|
returnResultTxt = (String) result.get("contentType");
|
106 |
|
|
assertEquals("Download: Content Type is incorrect for a data file download", returnResultTxt, "application/octet-stream");
|
107 |
|
|
returnResultTxt = (String) result.get("Content-Disposition");
|
108 |
|
|
assertNotNull("Download: Content-Disposition is not set", returnResultTxt);
|
109 |
|
|
assertNotNull("Download: OutputStream is not set", result.get("outputStream"));
|
110 |
|
|
assertTrue("Download: Returned an empty file", ((ByteArrayOutputStream) result.get("outputStream")).size() > 0);
|
111 |
|
|
System.out.println(" ...success!");
|
112 |
|
|
|
113 |
3536
|
barteau
|
|
114 |
3535
|
barteau
|
System.out.print("...download (package zip file)");
|
115 |
3538
|
barteau
|
clientViewBean.setDocId(DOWNLOAD_PACKAGE_DOCID);
|
116 |
|
|
clientViewBean.setMetaFileDocId(DOWNLOAD_PACKAGE_DOCID);
|
117 |
3535
|
barteau
|
|
118 |
|
|
result = instance.handleClientRequest(null);
|
119 |
|
|
returnResultTxt = (String) result.get("contentType");
|
120 |
3538
|
barteau
|
assertEquals("Download: Content Type is incorrect for a package download", returnResultTxt, "application/zip");
|
121 |
3535
|
barteau
|
returnResultTxt = (String) result.get("Content-Disposition");
|
122 |
|
|
assertNotNull("Download: Content-Disposition is not set", returnResultTxt);
|
123 |
|
|
assertNotNull("Download: OutputStream is not set", result.get("outputStream"));
|
124 |
|
|
assertTrue("Download: Returned an empty file", ((ByteArrayOutputStream) result.get("outputStream")).size() > 0);
|
125 |
|
|
System.out.println(" ...success!");
|
126 |
|
|
|
127 |
3536
|
barteau
|
|
128 |
3535
|
barteau
|
System.out.print("...logout");
|
129 |
|
|
clientViewBean.setAction("Logout");
|
130 |
3536
|
barteau
|
|
131 |
3535
|
barteau
|
result = instance.handleClientRequest(null);
|
132 |
|
|
assertNull("Logout: Session ID still exists", clientViewBean.getSessionid());
|
133 |
|
|
System.out.println(" ...success!");
|
134 |
|
|
|
135 |
|
|
}
|
136 |
|
|
}
|