You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2009/10/26 17:19:01 UTC
svn commit: r829849 - in
/incubator/pivot/trunk/web/test/org/apache/pivot/web/test:
WebQueryTestClientBasic.java WebQueryTestClientDigest.java
WebQueryTestClientDigest.json
Author: smartini
Date: Mon Oct 26 16:19:01 2009
New Revision: 829849
URL: http://svn.apache.org/viewvc?rev=829849&view=rev
Log:
update Digest Test to usage of (its own) parametrized data
Added:
incubator/pivot/trunk/web/test/org/apache/pivot/web/test/WebQueryTestClientDigest.json
Modified:
incubator/pivot/trunk/web/test/org/apache/pivot/web/test/WebQueryTestClientBasic.java
incubator/pivot/trunk/web/test/org/apache/pivot/web/test/WebQueryTestClientDigest.java
Modified: incubator/pivot/trunk/web/test/org/apache/pivot/web/test/WebQueryTestClientBasic.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/test/org/apache/pivot/web/test/WebQueryTestClientBasic.java?rev=829849&r1=829848&r2=829849&view=diff
==============================================================================
--- incubator/pivot/trunk/web/test/org/apache/pivot/web/test/WebQueryTestClientBasic.java (original)
+++ incubator/pivot/trunk/web/test/org/apache/pivot/web/test/WebQueryTestClientBasic.java Mon Oct 26 16:19:01 2009
@@ -16,6 +16,7 @@
*/
package org.apache.pivot.web.test;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -215,8 +216,11 @@
result = query.execute();
log("Query result: \n" + result);
-
assertNull(result);
+
+ int status = query.getStatus();
+ log("Query: status = " + status + ", result: \n" + result);
+ assertEquals(401, status);
}
@Test(timeout = 10000, expected = QueryException.class)
@@ -237,8 +241,11 @@
result = query.execute();
log("Query result: \n" + result);
-
assertNull(result);
+
+ int status = query.getStatus();
+ log("Query: status = " + status + ", result: \n" + result);
+ assertEquals(401, status);
}
@Test(timeout = 10000)
@@ -266,9 +273,9 @@
result = query.execute();
assertNotNull(result);
- // int status = query.getStatus(); // method missing at the moment ...
- // log("Query: status = " + status + ", result: \n" + result);
- // assertEquals(401, status);
+ int status = query.getStatus();
+ log("Query: status = " + status + ", result: \n" + result);
+ assertEquals(200, status);
// dump content, but useful only for text resources ...
String dump = // result.toString()
Modified: incubator/pivot/trunk/web/test/org/apache/pivot/web/test/WebQueryTestClientDigest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/test/org/apache/pivot/web/test/WebQueryTestClientDigest.java?rev=829849&r1=829848&r2=829849&view=diff
==============================================================================
--- incubator/pivot/trunk/web/test/org/apache/pivot/web/test/WebQueryTestClientDigest.java (original)
+++ incubator/pivot/trunk/web/test/org/apache/pivot/web/test/WebQueryTestClientDigest.java Mon Oct 26 16:19:01 2009
@@ -16,10 +16,15 @@
*/
package org.apache.pivot.web.test;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import java.io.IOException;
+
import org.apache.pivot.serialization.ByteArraySerializer;
+import org.apache.pivot.serialization.SerializationException;
+import org.apache.pivot.util.Resources;
import org.apache.pivot.web.Authentication;
import org.apache.pivot.web.DigestAuthentication;
import org.apache.pivot.web.GetQuery;
@@ -36,59 +41,56 @@
* This is a JUnit 4 Test, but should be excluded from usual (Unit) Test Suite.
* <br/>
* To Run these tests, a local instance of Apache must be started and configured with
- * the required resources ( dir /public , and dir /protected_digest protected with digest authentication) and files.
+ * the required resources (by default folders /public , and /dir and /protected_digest
+ * protected with digest authentication) and files.
* Before to run these tests, ensure digest authentication has been successfully setup
* asking the same URLs from a Web Browser.
- * See the file WebQueryTestClientDigest.README for further info.
+ * Note that now this class loads (in a standard Pivot way) some test parameters
+ * from a json file that must be in the same folder of this class.
+ * For example, to run this Class on another Server (for example on a local Tomcat instance),
+ * some parameters have to be changed inside the json file, then rerun the test.
*
* TODO:
* - test other HTTP methods ...
- *
- * - in the future, verify if make a new Demo for accessing (digest etc) protected data,
- * as a Pivot Application, giving all the parameters
- * (username, password, url, auth method, http method, etc) from the GUI ...
- *
+ * - test also many queries after the first, to see if/how to handle the nonce count ...
+ * - test also with URL parameters ...
+ * - test also with long query:
+ * -- test the timeout (of query, and not of the test method)
+ * -- test the cancel (of query) , like downloading an iso file
+ * - test also with Tomcat ...
+ *
*/
public class WebQueryTestClientDigest {
- final static String HOSTNAME = "localhost";
- final static String PATH = null;
- final static int PORT = 80;
- final static boolean SECURE = false;
-
- final static String PATH_PUBLIC = "/public/";
- final static String PATH_PROTECTED_DIGEST = "/protected_digest/";
-
- final static String SAMPLE_FILE_BINARY = "test.jpg";
- final static String SAMPLE_FILE_TEXT = "test.txt";
-
- final static String USER_NAME = "test";
- final static String USER_PASSWORD = "test0";
-
- final static String USER_NAME_BY_RFC = "Mufasa";
- final static String USER_PASSWORD_BY_RFC = "Circle Of Life";
- final static String PROTECTED_DIGEST_URI_BY_RFC = "/dir/index.html";
-
- final static long TIMEOUT = 5000l; // default timeout for WebQuery tests
- // here: 5 sec
-
- final static int TOMCAT_PORT = 8080;
- final static String TOMCAT_PIVOT_TEST_WEBAPP = "pivot-tests";
+ static Resources resources = null; // parametric resources, using the
+ // Pivot-way
String host = null;
int port = 0;
String path = null;
+ boolean secure = false;
Authentication authentication = null;
Object result = null;
- public void log(String msg) {
+ public static void log(String msg) {
System.out.println(msg);
}
@BeforeClass
public static void runBeforeClass() {
// run for one time before all test cases
+
+ // load Test Case parametric values
+ try {
+ resources = new Resources(WebQueryTestClientDigest.class.getName());
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (SerializationException e) {
+ e.printStackTrace();
+ }
+
+ log("Loaded " + resources + " resources");
}
@AfterClass
@@ -115,15 +117,15 @@
// @Ignore
@Test(timeout = 10000, expected = QueryException.class)
- public void publicOnApache_noauth_NotExistingHost() throws QueryException {
- log("publicOnApache_noauth_NotExistingHost()");
+ public void public_noauth_NotExistingHost() throws QueryException {
+ log("public_noauth_NotExistingHost()");
host = "non_existing_host";
- port = PORT;
- path = PATH_PUBLIC;
+ port = resources.getInteger("port");
+ path = resources.getString("folder_public");
- GetQuery query = new GetQuery(host, port, path, SECURE);
- query.setTimeout(TIMEOUT);
+ GetQuery query = new GetQuery(host, port, path, secure);
+ query.setTimeout(resources.getLong("timeout"));
log("GET Query to " + query.getLocation());
result = query.execute();
@@ -133,15 +135,15 @@
}
@Test(timeout = 10000, expected = QueryException.class)
- public void publicOnApache_noauth_localhost_NotExistingResource() throws QueryException {
- log("publicOnApache_noauth_localhost_NotExistingResource()");
+ public void public_noauth_localhost_NotExistingResource() throws QueryException {
+ log("public_noauth_localhost_NotExistingResource()");
- host = HOSTNAME;
- port = PORT;
- path = PATH_PUBLIC + "non_existing_resource";
+ host = resources.getString("hostname");
+ port = resources.getInteger("port");
+ path = resources.getString("folder_public") + "non_existing_resource";
- GetQuery query = new GetQuery(host, port, path, SECURE);
- query.setTimeout(TIMEOUT);
+ GetQuery query = new GetQuery(host, port, path, secure);
+ query.setTimeout(resources.getLong("timeout"));
log("GET Query to " + query.getLocation());
result = query.execute();
@@ -151,19 +153,19 @@
}
@Test(timeout = 10000)
- public void publicOnApache_noauth_localhost_testFile() throws QueryException {
- log("publicOnApache_noauth_localhost_testFile()");
+ public void public_noauth_localhost_testFile() throws QueryException {
+ log("public_noauth_localhost_testFile()");
- host = HOSTNAME;
- port = PORT;
- path = PATH_PUBLIC + SAMPLE_FILE_TEXT;
+ host = resources.getString("hostname");
+ port = resources.getInteger("port");
+ path = resources.getString("folder_public") + resources.getString("file_text");
- GetQuery query = new GetQuery(host, port, path, SECURE);
+ GetQuery query = new GetQuery(host, port, path, secure);
// attention, don't use BinarySerializer here, but instead use the
// generic ByteArraySerializer
query.setSerializer(new ByteArraySerializer());
- query.setTimeout(TIMEOUT);
+ query.setTimeout(resources.getLong("timeout"));
log("GET Query to " + query.getLocation());
result = query.execute();
@@ -177,23 +179,23 @@
}
@Test(timeout = 10000)
- public void publicOnApache_digest_localhost_forceUnnecessaryAuthentication()
- throws QueryException {
- log("publicOnApache_digest_localhost_forceUnnecessaryAuthentication()");
-
- host = HOSTNAME;
- port = PORT;
- path = PATH_PUBLIC + SAMPLE_FILE_TEXT;
+ public void public_digest_localhost_forceUnnecessaryAuthentication() throws QueryException {
+ log("public_digest_localhost_forceUnnecessaryAuthentication()");
+
+ host = resources.getString("hostname");
+ port = resources.getInteger("port");
+ path = resources.getString("folder_public") + resources.getString("file_text");
- GetQuery query = new GetQuery(host, port, path, SECURE);
+ GetQuery query = new GetQuery(host, port, path, secure);
// attention, don't use BinarySerializer here, but instead use the
// generic ByteArraySerializer
query.setSerializer(new ByteArraySerializer());
- query.setTimeout(TIMEOUT);
+ query.setTimeout(resources.getLong("timeout"));
log("GET Query to " + query.getLocation());
- authentication = new DigestAuthentication(USER_NAME, USER_PASSWORD);
+ authentication = new DigestAuthentication(resources.getString("user_name"),
+ resources.getString("user_pass"));
authentication.authenticate(query);
result = query.execute();
@@ -207,37 +209,39 @@
}
// @Test(timeout = 10000, expected = QueryException.class)
- @Test(timeout = 1000000, expected = QueryException.class)
- // for debugging the execution
- public void protectedOnApache_digest_localhostWithoutAuthenticate() throws QueryException {
- log("protectedOnApache_digest_localhostWithoutAuthenticate()");
-
- host = HOSTNAME;
- port = PORT;
- path = PATH_PROTECTED_DIGEST + SAMPLE_FILE_TEXT;
+ @Test(timeout = 1000000, expected = QueryException.class) // for debugging the execution
+ public void protected_digest_localhostWithoutAuthenticate() throws QueryException {
+ log("protected_digest_localhostWithoutAuthenticate()");
+
+ host = resources.getString("hostname");
+ port = resources.getInteger("port");
+ path = resources.getString("folder_protected") + resources.getString("file_text");
- GetQuery query = new GetQuery(host, port, path, SECURE);
+ GetQuery query = new GetQuery(host, port, path, secure);
query.setSerializer(new ByteArraySerializer());
- query.setTimeout(TIMEOUT);
+ query.setTimeout(resources.getLong("timeout"));
log("GET Query to " + query.getLocation());
result = query.execute();
log("Query result: \n" + result);
-
assertNull(result);
+
+ int status = query.getStatus();
+ log("Query: status = " + status + ", result: \n" + result);
+ assertEquals(401, status);
}
@Test(timeout = 10000, expected = QueryException.class)
- public void protectedOnApache_digest_localhostWithWrongCredentials() throws QueryException {
- log("protectedOnApache_digest_localhostWithWrongCredentials()");
+ public void protected_digest_localhostWithWrongCredentials() throws QueryException {
+ log("protected_digest_localhostWithWrongCredentials()");
- host = HOSTNAME;
- port = PORT;
- path = PATH_PROTECTED_DIGEST + SAMPLE_FILE_TEXT;
+ host = resources.getString("hostname");
+ port = resources.getInteger("port");
+ path = resources.getString("folder_protected") + resources.getString("file_text");
- GetQuery query = new GetQuery(host, port, path, SECURE);
+ GetQuery query = new GetQuery(host, port, path, secure);
query.setSerializer(new ByteArraySerializer());
- query.setTimeout(TIMEOUT);
+ query.setTimeout(resources.getLong("timeout"));
log("GET Query to " + query.getLocation());
authentication = new DigestAuthentication("wrongUsername", "wrongPassword");
@@ -245,39 +249,42 @@
result = query.execute();
log("Query result: \n" + result);
-
assertNull(result);
- }
+
+ int status = query.getStatus();
+ log("Query: status = " + status + ", result: \n" + result);
+ assertEquals(401, status);
+ }
// @Test(timeout = 10000)
- @Test(timeout = 1000000)
- // for debugging the execution
- public void protectedOnApache_digest_localhost() throws QueryException {
- log("protectedOnApache_digest_localhost()");
-
- host = HOSTNAME;
- port = PORT;
- // path = PATH_PROTECTED_DIGEST + SAMPLE_FILE_TEXT;
- // path = PATH_PROTECTED_DIGEST + SAMPLE_FILE_BINARY;
- path = PATH_PROTECTED_DIGEST + SAMPLE_FILE_TEXT;
+ @Test(timeout = 1000000) // for debugging the execution
+ public void protected_digest_localhost() throws QueryException {
+ log("protected_digest_localhost()");
+
+ host = resources.getString("hostname");
+ port = resources.getInteger("port");
+ // path = resources.getString("folder_protected") + resources.getString("file_text");
+ // path = resources.getString("folder_protected") + resources.getString("file_binary");
+ path = resources.getString("folder_protected") + resources.getString("file_text");
- GetQuery query = new GetQuery(host, port, path, SECURE);
+ GetQuery query = new GetQuery(host, port, path, secure);
// attention, don't use BinarySerializer here, but instead use the
// generic ByteArraySerializer
query.setSerializer(new ByteArraySerializer());
- query.setTimeout(TIMEOUT);
+ query.setTimeout(resources.getLong("timeout"));
log("GET Query to " + query.getLocation());
- authentication = new DigestAuthentication(USER_NAME, USER_PASSWORD);
+ authentication = new DigestAuthentication(resources.getString("user_name"),
+ resources.getString("user_pass"));
authentication.authenticate(query);
result = query.execute();
assertNotNull(result);
- // int status = query.getStatus(); // method missing at the moment ...
- // log("Query: status = " + status + ", result: \n" + result);
- // assertEquals(401, status);
+ int status = query.getStatus();
+ log("Query: status = " + status + ", result: \n" + result);
+ assertEquals(200, status);
// dump content, but useful only for text resources ...
String dump = // result.toString()
@@ -287,29 +294,33 @@
}
// @Test(timeout = 10000)
- @Test(timeout = 1000000)
- // for debugging the execution
- public void protectedOnApache_digest_localhostByRFC() throws QueryException {
- log("protectedOnApache_digest_localhostByRFC()");
-
- host = HOSTNAME;
- port = PORT;
- path = PROTECTED_DIGEST_URI_BY_RFC;
+ @Test(timeout = 1000000) // for debugging the execution
+ public void protected_digest_localhostByRFC() throws QueryException {
+ log("protected_digest_localhostByRFC()");
+
+ host = resources.getString("hostname");
+ port = resources.getInteger("port");
+ path = resources.getString("rfc_uri_protected");
- GetQuery query = new GetQuery(host, port, path, SECURE);
+ GetQuery query = new GetQuery(host, port, path, secure);
// attention, don't use BinarySerializer here, but instead use the
// generic ByteArraySerializer
query.setSerializer(new ByteArraySerializer());
- query.setTimeout(TIMEOUT);
+ query.setTimeout(resources.getLong("timeout"));
log("GET Query to " + query.getLocation());
- authentication = new DigestAuthentication(USER_NAME_BY_RFC, USER_PASSWORD_BY_RFC);
+ authentication = new DigestAuthentication(resources.getString("rfc_user_name"),
+ resources.getString("rfc_user_pass"));
authentication.authenticate(query);
result = query.execute();
assertNotNull(result);
+ int status = query.getStatus();
+ log("Query: status = " + status + ", result: \n" + result);
+ assertEquals(200, status);
+
// dump content, but useful only for text resources ...
String dump = // result.toString()
// Arrays.toString((byte []) result);
@@ -317,12 +328,4 @@
log("Query result: " + (dump.getBytes().length) + " bytes \n" + dump);
}
- // TODO: test also many queries after the first, to see if/how to handle the
- // nonce count ...
- // TODO: test also with URL parameters ...
- // TODO: test also with long query:
- // - test the timeout (of query, and not of the test method)
- // - test the cancel (of query) , like downloading an iso file
- // TODO: test also with Tomcat ...
-
}
Added: incubator/pivot/trunk/web/test/org/apache/pivot/web/test/WebQueryTestClientDigest.json
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/test/org/apache/pivot/web/test/WebQueryTestClientDigest.json?rev=829849&view=auto
==============================================================================
--- incubator/pivot/trunk/web/test/org/apache/pivot/web/test/WebQueryTestClientDigest.json (added)
+++ incubator/pivot/trunk/web/test/org/apache/pivot/web/test/WebQueryTestClientDigest.json Mon Oct 26 16:19:01 2009
@@ -0,0 +1,27 @@
+{
+ secure: false,
+ hostname: "localhost",
+
+ // enable this for Test on Apache
+ port: 80, // for apache keep this on 80
+ webapp: "", // for apache keep this empty
+ //
+ // or enable this for Test on Tomcat
+ // port: 8080, // for tomcat enable this (default on 8080)
+ // webapp: "/pivot-test", // for tomcat keep this to the test webapp name
+ // end customizations
+
+ folder_public: "/public/",
+ folder_protected: "/protected_digest/",
+ file_binary: "test.jpg",
+ file_text: "test.txt",
+ user_name: "test",
+ user_pass: "test0",
+
+ rfc_uri_protected: "/dir/index.html",
+ rfc_user_name: "Mufasa",
+ rfc_user_pass: "Circle Of Life",
+
+ timeout: 5000
+
+}