Author: scottbw
Date: Thu Mar 25 09:45:02 2010
New Revision: 927319
URL: http://svn.apache.org/viewvc?rev=927319&view=rev
Log:
Cleaned up the functional tests using a single set of constants to make it
easier to configure the tests to run on different servers, ports etc.
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/AbstractControllerTest.java
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/FolderLocalizationTest.java
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ProxyTest.java
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetServicesControllerTest.java
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/AbstractControllerTest.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/AbstractControllerTest.java?rev=927319&r1=927318&r2=927319&view=diff
==============================================================================
---
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/AbstractControllerTest.java
(original)
+++
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/AbstractControllerTest.java
Thu Mar 25 09:45:02 2010
@@ -14,21 +14,40 @@
package org.apache.wookie.tests.functional;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+
/**
- * @author scott
+ * Constants used in functional tests. Change these values to test servers
+ * at other locations.
*
*/
public abstract class AbstractControllerTest{
+ protected static final int TEST_SERVER_PORT = 8080;
+ protected static final String TEST_SERVER_HOST = "localhost";
+ protected static final String TEST_SERVER_ORIGIN =
"http://"+TEST_SERVER_HOST+":"+TEST_SERVER_PORT;
+ protected static final String TEST_SERVER_LOCATION =
TEST_SERVER_ORIGIN+"/wookie/";
- protected static final String TEST_INSTANCES_SERVICE_URL_VALID =
"http://localhost:8080/wookie/widgetinstances";
- protected static final String TEST_PROPERTIES_SERVICE_URL_VALID =
"http://localhost:8080/wookie/properties";
- protected static final String TEST_PARTICIPANTS_SERVICE_URL_VALID =
"http://localhost:8080/wookie/participants";
- protected static final String TEST_WIDGETS_SERVICE_URL_VALID =
"http://localhost:8080/wookie/widgets";
- protected static final String TEST_SERVICES_SERVICE_URL_VALID =
"http://localhost:8080/wookie/services";
+ protected static final String TEST_INSTANCES_SERVICE_URL_VALID =
TEST_SERVER_LOCATION+"widgetinstances";
+ protected static final String TEST_PROPERTIES_SERVICE_URL_VALID =
TEST_SERVER_LOCATION+"properties";
+ protected static final String TEST_PARTICIPANTS_SERVICE_URL_VALID =
TEST_SERVER_LOCATION+"participants";
+ protected static final String TEST_WIDGETS_SERVICE_URL_VALID =
TEST_SERVER_LOCATION+"widgets";
+ protected static final String TEST_SERVICES_SERVICE_URL_VALID =
TEST_SERVER_LOCATION+"services";
protected static final String API_KEY_VALID = "TEST";
protected static final String API_KEY_INVALID = "rubbish";
protected static final String WIDGET_ID_VALID =
"http://www.getwookie.org/widgets/weather";
protected static final String WIDGET_ID_INVALID =
"http://www.getwookie.org/widgets/nosuchwidget";
+ /**
+ * Set credentials for accessing Wookie admin functions
+ * @param client
+ */
+ protected static void setAuthenticationCredentials(HttpClient client){
+ Credentials defaultcreds = new
UsernamePasswordCredentials("java", "java");
+ client.getState().setCredentials(new
AuthScope(TEST_SERVER_HOST, TEST_SERVER_PORT, AuthScope.ANY_REALM),
defaultcreds);
+ }
+
}
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/FolderLocalizationTest.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/FolderLocalizationTest.java?rev=927319&r1=927318&r2=927319&view=diff
==============================================================================
---
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/FolderLocalizationTest.java
(original)
+++
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/FolderLocalizationTest.java
Thu Mar 25 09:45:02 2010
@@ -36,7 +36,6 @@ public class FolderLocalizationTest exte
private static final String LOCALIZED_WIDGET =
"http://www.getwookie.org/widgets/localetest";
private static String WIDGET_START_URL_ROOT;
- protected static final String SERVER_URL = "http://localhost:8080";
private static HttpClient client;
private static GetMethod get;
@@ -94,7 +93,7 @@ public class FolderLocalizationTest exte
get.setFollowRedirects(true);
try {
client.executeMethod(get);
- return SERVER_URL + get.getPath();
+ return TEST_SERVER_ORIGIN + get.getPath();
} catch (Exception e) {
e.printStackTrace();
}
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ProxyTest.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ProxyTest.java?rev=927319&r1=927318&r2=927319&view=diff
==============================================================================
---
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ProxyTest.java
(original)
+++
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ProxyTest.java
Thu Mar 25 09:45:02 2010
@@ -36,14 +36,14 @@ public class ProxyTest extends AbstractC
private static String instance_id_key;
private static String other_instance_id_key;
private static final String OTHER_WIDGET_ID =
"http://www.getwookie.org/widgets/natter";
- private static final String PROXY_URL =
"http://localhost:8080/wookie/proxy";
+ private static final String PROXY_URL = TEST_SERVER_LOCATION+"proxy";
private static final String VALID_SITE_URL =
"http://incubator.apache.org/wookie/";
- private static final String VALID_SITE_XML_URL =
"http://localhost:8080/wookie/widgets?all=true";
+ private static final String VALID_SITE_XML_URL =
TEST_SERVER_LOCATION+"widgets?all=true";
private static final String INVALID_SITE_URL =
"DFASFAFEQ3FQ32145235123452";
private static final String BLOCKED_SITE_URL = "http://very.bad.place";
private static final String POLICY_ALLOWED_SITE_URL =
"http://feeds.bbc.co.uk/weather/feeds/rss.shtml?world=11";
private static final String POLICY_DISALLOWED_SITE_URL =
"http://news.bbc.co.uk";
- private static final String PROTECTED_SITE_URL =
"http://localhost:8080/wookie/admin/";
+ private static final String PROTECTED_SITE_URL =
TEST_SERVER_LOCATION+"admin/";
/**
* Create an instance of a widget
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetServicesControllerTest.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetServicesControllerTest.java?rev=927319&r1=927318&r2=927319&view=diff
==============================================================================
---
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetServicesControllerTest.java
(original)
+++
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetServicesControllerTest.java
Thu Mar 25 09:45:02 2010
@@ -17,28 +17,20 @@ import static org.junit.Assert.assertEqu
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.junit.Test;
-/**
- * @author scott
- *
- */
public class WidgetServicesControllerTest extends AbstractControllerTest {
@Test
public void addService(){
try {
HttpClient client = new HttpClient();
- Credentials defaultcreds = new
UsernamePasswordCredentials("java", "java");
- client.getState().setCredentials(new
AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds);
+ setAuthenticationCredentials(client);
PostMethod post = new
PostMethod(TEST_SERVICES_SERVICE_URL_VALID+"/test");
post.setDoAuthentication(true);
client.executeMethod(post);
@@ -71,8 +63,7 @@ public class WidgetServicesControllerTes
public void modifyService(){
try {
HttpClient client = new HttpClient();
- Credentials defaultcreds = new
UsernamePasswordCredentials("java", "java");
- client.getState().setCredentials(new
AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds);
+ setAuthenticationCredentials(client);
PutMethod put = new
PutMethod(TEST_SERVICES_SERVICE_URL_VALID+"/test");
put.setQueryString("name=test2");
put.setDoAuthentication(true);
@@ -108,8 +99,7 @@ public class WidgetServicesControllerTes
public void deleteService(){
try {
HttpClient client = new HttpClient();
- Credentials defaultcreds = new
UsernamePasswordCredentials("java", "java");
- client.getState().setCredentials(new
AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds);
+ setAuthenticationCredentials(client);
DeleteMethod del = new
DeleteMethod(TEST_SERVICES_SERVICE_URL_VALID+"/test2");
del.setDoAuthentication(true);
client.executeMethod(del);
@@ -190,8 +180,7 @@ public class WidgetServicesControllerTes
public void addServiceAlreadyExists(){
try {
HttpClient client = new HttpClient();
- Credentials defaultcreds = new
UsernamePasswordCredentials("java", "java");
- client.getState().setCredentials(new
AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds);
+ setAuthenticationCredentials(client);
PostMethod post = new
PostMethod(TEST_SERVICES_SERVICE_URL_VALID+"/test_add2");
post.setDoAuthentication(true);
client.executeMethod(post);
@@ -205,8 +194,7 @@ public class WidgetServicesControllerTes
}
try {
HttpClient client = new HttpClient();
- Credentials defaultcreds = new
UsernamePasswordCredentials("java", "java");
- client.getState().setCredentials(new
AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds);
+ setAuthenticationCredentials(client);
PostMethod post = new
PostMethod(TEST_SERVICES_SERVICE_URL_VALID+"/test_add2");
post.setDoAuthentication(true);
client.executeMethod(post);
@@ -221,8 +209,7 @@ public class WidgetServicesControllerTes
// clean up
try {
HttpClient client = new HttpClient();
- Credentials defaultcreds = new
UsernamePasswordCredentials("java", "java");
-
client.getState().setCredentials(new AuthScope("localhost", 8080,
AuthScope.ANY_REALM), defaultcreds);
+ setAuthenticationCredentials(client);
DeleteMethod del = new
DeleteMethod(TEST_SERVICES_SERVICE_URL_VALID+"/test_add2");
del.setDoAuthentication(true);
client.executeMethod(del);
@@ -240,8 +227,7 @@ public class WidgetServicesControllerTes
public void modifyServiceNonExists(){
try {
HttpClient client = new HttpClient();
- Credentials defaultcreds = new
UsernamePasswordCredentials("java", "java");
- client.getState().setCredentials(new
AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds);
+ setAuthenticationCredentials(client);
PutMethod put = new
PutMethod(TEST_SERVICES_SERVICE_URL_VALID+"/test999");
put.setQueryString("name=test2");
put.setDoAuthentication(true);
@@ -260,8 +246,7 @@ public class WidgetServicesControllerTes
public void deleteServiceNonExists(){
try {
HttpClient client = new HttpClient();
- Credentials defaultcreds = new
UsernamePasswordCredentials("java", "java");
- client.getState().setCredentials(new
AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds);
+ setAuthenticationCredentials(client);
DeleteMethod del = new
DeleteMethod(TEST_SERVICES_SERVICE_URL_VALID+"/test999");
del.setDoAuthentication(true);
client.executeMethod(del);
@@ -279,8 +264,7 @@ public class WidgetServicesControllerTes
public void modifyServiceNoName(){
try {
HttpClient client = new HttpClient();
- Credentials defaultcreds = new
UsernamePasswordCredentials("java", "java");
- client.getState().setCredentials(new
AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds);
+ setAuthenticationCredentials(client);
PutMethod put = new
PutMethod(TEST_SERVICES_SERVICE_URL_VALID+"/test999");
put.setDoAuthentication(true);
client.executeMethod(put);