Author: psharples
Date: Thu Mar 15 12:48:46 2012
New Revision: 1300963
URL: http://svn.apache.org/viewvc?rev=1300963&view=rev
Log:
More improvements to the conformance tests, mainly making sure that they all
run clean and don't leave any widgets in wookie after they have run. (which
means you can run the tests multiple times without them failing)
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/AbstractFunctionalConformanceTest.java
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/AbstractControllerTest.java
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/UpdatesControllerTest.java
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/AbstractFunctionalConformanceTest.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/AbstractFunctionalConformanceTest.java?rev=1300963&r1=1300962&r2=1300963&view=diff
==============================================================================
---
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/AbstractFunctionalConformanceTest.java
(original)
+++
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/AbstractFunctionalConformanceTest.java
Thu Mar 15 12:48:46 2012
@@ -94,7 +94,8 @@ AbstractControllerTest {
* @throws IOException
*/
protected static String getWidgetUrl(String widgetfname) throws
IOException{
- WidgetUploader.uploadWidget(widgetfname);
+ String result = WidgetUploader.uploadWidget(widgetfname);
+ storeImportedPackageId(result);
Element widget = WidgetUploader.getLastWidget();
String response = instantiateWidget(widget);
return getStartFile(response);
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java?rev=1300963&r1=1300962&r2=1300963&view=diff
==============================================================================
---
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java
(original)
+++
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java
Thu Mar 15 12:48:46 2012
@@ -19,7 +19,6 @@ import static org.junit.Assert.assertNot
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
@@ -1198,24 +1197,23 @@ public class PackagingAndConfiguration e
// Utility methods
protected Element processWidgetNoErrors(String widgetfname){
try {
-
+ String id = null;
//
// Upload the widget, and process the response to get the
widget uri
//
SAXBuilder builder = new SAXBuilder();
- StringReader reader = new
StringReader(WidgetUploader.uploadWidget(widgetfname));
- Element widget = builder.build(reader).getRootElement();
- assertNotNull(widget);
- widget.getAttribute("id");
-
- //
- // Get and return the widget xml. We don't return the
original response
- // as that is the raw config.xml data - we have to make
another call to
- // get the corrected and normalized metadata to check
we have correctly
- // processed the .wgt package according to the W3C spec.
- //
- return
builder.build(TEST_WIDGETS_SERVICE_URL_VALID+"/"+widget.getAttribute("id").getValue()).getRootElement().getChild("widget");
-
+ String result = WidgetUploader.uploadWidget(widgetfname);
+ System.out.println(result);
+ id = storeImportedPackageId(result);
+ // id should not be null as they are generated if not found
during the initial parse
+ assertNotNull(id);
+ //
+ // Get and return the widget xml. We don't return the
original response
+ // as that is the raw config.xml data - we have to make
another call to
+ // get the corrected and normalized metadata to check we have
correctly
+ // processed the .wgt package according to the W3C spec.
+ //
+ return
builder.build(TEST_WIDGETS_SERVICE_URL_VALID+"/"+id).getRootElement().getChild("widget");
} catch (Exception e) {
fail("couldn't upload widget:"+e.getMessage());
}
@@ -1300,7 +1298,9 @@ public class PackagingAndConfiguration e
private String processWidgetWithErrors(String widgetfname){
try {
- return WidgetUploader.uploadWidget(widgetfname);
+ String result = WidgetUploader.uploadWidget(widgetfname);
+ storeImportedPackageId(result);
+ return result;
} catch (Exception e) {
fail("couldn't upload widget");
}
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=1300963&r1=1300962&r2=1300963&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 15 12:48:46 2012
@@ -14,11 +14,24 @@
package org.apache.wookie.tests.functional;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Collection;
+
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.wookie.tests.AbstractWookieTest;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.Namespace;
+import org.jdom.input.SAXBuilder;
+import org.junit.AfterClass;
/**
* Constants used in functional tests. Change these values to test servers
@@ -43,6 +56,8 @@ public abstract class AbstractController
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";
protected static final String WIDGET_ID_LOCALIZED =
"http://www.getwookie.org/widgets/localetest";
+
+ protected static Collection<String> importedWidgetList = new
ArrayList<String>();
/**
* Set credentials for accessing Wookie admin functions
@@ -53,4 +68,48 @@ public abstract class AbstractController
client.getState().setCredentials(new
AuthScope(TEST_SERVER_HOST, TEST_SERVER_PORT, AuthScope.ANY_REALM),
defaultcreds);
}
+ @AfterClass
+ public static void tearDown() throws HttpException, IOException{
+ for (String id : importedWidgetList){
+ removeWidget(id);
+ }
+ importedWidgetList.clear();
+ }
+
+ private static void removeWidget(String identifier) throws HttpException,
IOException{
+ HttpClient client = new HttpClient();
+ setAuthenticationCredentials(client);
+ DeleteMethod delete = new DeleteMethod(TEST_WIDGETS_SERVICE_URL_VALID +
"/" + identifier);
+ client.executeMethod(delete);
+ delete.releaseConnection();
+ }
+
+ protected static String storeImportedPackageId(String response){
+ if(response != null){
+ String result = getId(response);
+ importedWidgetList.add(result);
+ return result;
+ }
+ return null;
+ }
+
+ private static String getId(String response) {
+ String id = null;
+ SAXBuilder builder = new SAXBuilder();
+ Reader in = new StringReader(response);
+ Document doc;
+ try {
+ doc = builder.build(in);
+ Element widget = doc.getRootElement();
+ Namespace ns = widget.getNamespace();
+ id = widget.getAttributeValue("id");
+ if(id==null){
+ id = widget.getAttributeValue("id", ns);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return id;
+ }
+
}
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/UpdatesControllerTest.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/UpdatesControllerTest.java?rev=1300963&r1=1300962&r2=1300963&view=diff
==============================================================================
---
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/UpdatesControllerTest.java
(original)
+++
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/UpdatesControllerTest.java
Thu Mar 15 12:48:46 2012
@@ -16,19 +16,11 @@ package org.apache.wookie.tests.function
import static org.junit.Assert.assertEquals;
import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.Collection;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.wookie.tests.helpers.WidgetUploader;
-import org.jdom.Document;
-import org.jdom.input.SAXBuilder;
-import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -43,8 +35,6 @@ import org.junit.Test;
*/
public class UpdatesControllerTest extends AbstractControllerTest {
- protected static Collection<String> importedWidgetList = new
ArrayList<String>();
-
protected static final String TEST_UPDATES_URL_VALID = TEST_SERVER_LOCATION
+ "updates";
@@ -100,22 +90,6 @@ public class UpdatesControllerTest exten
.uploadWidget("http://dev.w3.org/2006/waf/widgets-updates/test-suite/test-cases/ta-processing2/016/ta-pr-016.wgt")//
pr216
);
}
-
- @AfterClass
- public static void tearDown() throws HttpException, IOException{
- for (String id : importedWidgetList){
- removeWidget(id);
- }
- importedWidgetList.clear();
- }
-
- private static void removeWidget(String identifier) throws HttpException,
IOException{
- HttpClient client = new HttpClient();
- setAuthenticationCredentials(client);
- DeleteMethod delete = new DeleteMethod(TEST_WIDGETS_SERVICE_URL_VALID +
"/" + identifier);
- client.executeMethod(delete);
- delete.releaseConnection();
- }
/**
* Tests that a request for updates is refused without admin credentials
@@ -133,7 +107,7 @@ public class UpdatesControllerTest exten
}
/**
- * Tests tha a request for updates with admin credentials returns a valid
+ * Tests that a request for updates with admin credentials returns a valid
* response
*
* @throws IOException
@@ -149,25 +123,5 @@ public class UpdatesControllerTest exten
int code = get.getStatusCode();
assertEquals(200, code);
}
-
- private static void storeImportedPackageId(String response){
- if(response != null){
- String result = getId(response);
- importedWidgetList.add(result);
- }
- }
-
- private static String getId(String response) {
- SAXBuilder builder = new SAXBuilder();
- Reader in = new StringReader(response);
- Document doc;
- try {
- doc = builder.build(in);
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- return doc.getRootElement().getAttributeValue("id");
- }
}