From wookie-dev-return-2831-apmail-incubator-wookie-dev-archive=incubator.apache.org@incubator.apache.org Tue May 3 08:52:04 2011 Return-Path: X-Original-To: apmail-incubator-wookie-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-wookie-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 33E44BA9 for ; Tue, 3 May 2011 08:52:04 +0000 (UTC) Received: (qmail 99853 invoked by uid 500); 3 May 2011 08:52:04 -0000 Delivered-To: apmail-incubator-wookie-dev-archive@incubator.apache.org Received: (qmail 99830 invoked by uid 500); 3 May 2011 08:52:04 -0000 Mailing-List: contact wookie-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: wookie-dev@incubator.apache.org Delivered-To: mailing list wookie-dev@incubator.apache.org Received: (qmail 99822 invoked by uid 99); 3 May 2011 08:52:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 May 2011 08:52:04 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 May 2011 08:52:02 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id F12D423888FE; Tue, 3 May 2011 08:51:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1098970 - in /incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance: AbstractFunctionalConformanceTest.java PackagingAndConfiguration.java WidgetInterface.java WidgetUpdates.java Date: Tue, 03 May 2011 08:51:41 -0000 To: wookie-dev@incubator.apache.org From: scottbw@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110503085141.F12D423888FE@eris.apache.org> Author: scottbw Date: Tue May 3 08:51:41 2011 New Revision: 1098970 URL: http://svn.apache.org/viewvc?rev=1098970&view=rev Log: Added conformance tests for Widget Updates (see WOOKIE-103) and refactored the conformance tests to reuse a common set of utility methods Added: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/AbstractFunctionalConformanceTest.java incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/WidgetUpdates.java Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/WidgetInterface.java Added: 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=1098970&view=auto ============================================================================== --- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/AbstractFunctionalConformanceTest.java (added) +++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/AbstractFunctionalConformanceTest.java Tue May 3 08:51:41 2011 @@ -0,0 +1,111 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wookie.tests.conformance; + +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.io.IOUtils; +import org.apache.wookie.tests.functional.AbstractControllerTest; +import org.apache.wookie.tests.helpers.WidgetUploader; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.input.SAXBuilder; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +/** + * Abstract superclass for conformance tests including utility functions + * for working with widgets and outputting results + */ +public abstract class AbstractFunctionalConformanceTest extends +AbstractControllerTest { + + protected static String html = ""; + + @BeforeClass + public static void setup(){ + html = ""; + } + + @AfterClass + public static void finish(){ + html += ""; + System.out.println(html); + } + + //// Utility methods + protected static void doTest(String widget){ + String url; + try { + url = getWidgetUrl(widget); + html += ""; + } catch (IOException e) { + e.printStackTrace(); + } + } + + protected static void outputInstance(String widgetId){ + String url; + String response = instantiateWidget(widgetId); + url = getStartFile(response); + html += ""; + } + + protected static String getWidgetUrl(String widgetfname) throws IOException{ + WidgetUploader.uploadWidget(widgetfname); + Element widget = WidgetUploader.getLastWidget(); + String response = instantiateWidget(widget); + return getStartFile(response); + } + + protected static String instantiateWidget(Element widget){ + return instantiateWidget(widget.getAttributeValue("identifier")); + } + + protected static String instantiateWidget(String identifier){ + String response = null; + // instantiate widget and parse results + try { + HttpClient client = new HttpClient(); + PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID); + post.setQueryString("api_key="+API_KEY_VALID+"&widgetid="+identifier+"&userid=test&shareddatakey=test"); + client.executeMethod(post); + response = IOUtils.toString(post.getResponseBodyAsStream()); + post.releaseConnection(); + } + catch (Exception e) { + fail("failed to instantiate widget"); + } + return response; + } + + protected static String getStartFile(String response){ + SAXBuilder builder = new SAXBuilder(); + Reader in = new StringReader(response); + Document doc; + try { + doc = builder.build(in); + } catch (Exception e) { + return null; + } + return doc.getRootElement().getChild("url").getText(); + } + +} 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=1098970&r1=1098969&r2=1098970&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 Tue May 3 08:51:41 2011 @@ -19,23 +19,16 @@ import static org.junit.Assert.assertNot import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import java.io.Reader; -import java.io.StringReader; import java.net.MalformedURLException; import java.net.URL; import java.util.List; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; -import org.apache.wookie.tests.functional.AbstractControllerTest; import org.apache.wookie.tests.helpers.WidgetUploader; import org.apache.wookie.w3c.util.WidgetPackageUtils; -import org.jdom.Document; import org.jdom.Element; -import org.jdom.input.SAXBuilder; import org.junit.Ignore; import org.junit.Test; @@ -50,7 +43,7 @@ import org.junit.Test; * @author scott * */ -public class PackagingAndConfiguration extends AbstractControllerTest { +public class PackagingAndConfiguration extends AbstractFunctionalConformanceTest { // 1 files @Test public void b5(){ @@ -1195,7 +1188,7 @@ public class PackagingAndConfiguration e */ // Utility methods - private Element processWidgetNoErrors(String widgetfname){ + protected Element processWidgetNoErrors(String widgetfname){ try { //File file = new File("src-tests/testdata/conformance/"+widgetfname); String error = WidgetUploader.uploadWidget(widgetfname); @@ -1213,37 +1206,6 @@ public class PackagingAndConfiguration e return null; } - private String instantiateWidget(Element widget){ - String response = null; - String widgetUri = widget.getAttributeValue("identifier"); - // instantiate widget and parse results - try { - HttpClient client = new HttpClient(); - PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID); - post.setQueryString("api_key="+API_KEY_VALID+"&widgetid="+widgetUri+"&userid=test&shareddatakey=test"); - client.executeMethod(post); - response = IOUtils.toString(post.getResponseBodyAsStream()); - post.releaseConnection(); - } - catch (Exception e) { - //e.printStackTrace(); - fail("failed to instantiate widget"); - } - return response; - } - - private String getStartFile(String response){ - SAXBuilder builder = new SAXBuilder(); - Reader in = new StringReader(response); - Document doc; - try { - doc = builder.build(in); - } catch (Exception e) { - return null; - } - return doc.getRootElement().getChild("url").getText(); - } - private String getStartFileEncoding(Element widget){ String response = instantiateWidget(widget); String startFile = getStartFile(response); Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/WidgetInterface.java URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/WidgetInterface.java?rev=1098970&r1=1098969&r2=1098970&view=diff ============================================================================== --- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/WidgetInterface.java (original) +++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/WidgetInterface.java Tue May 3 08:51:41 2011 @@ -13,22 +13,6 @@ */ package org.apache.wookie.tests.conformance; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.io.IOUtils; -import org.apache.wookie.tests.functional.AbstractControllerTest; -import org.apache.wookie.tests.helpers.WidgetUploader; -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.input.SAXBuilder; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; /** @@ -38,20 +22,7 @@ import org.junit.Test; * Currently this just outputs HTML that you need to paste into a text file and view * in your browser to "eyeball" the results. But at least its a start */ -public class WidgetInterface extends AbstractControllerTest{ - - private static String html = ""; - - @BeforeClass - public static void setup(){ - html = ""; - } - - @AfterClass - public static void finish(){ - html += ""; - System.out.println(html); - } +public class WidgetInterface extends AbstractFunctionalConformanceTest{ @Test public void taza(){ @@ -207,55 +178,4 @@ public class WidgetInterface extends Abs doTest("http://dev.w3.org/2006/waf/widgets-api/test-suite/test-cases/ta-aa/au/au.wgt"); } - - //// Utility methods - private void doTest(String widget){ - String url; - try { - url = getWidgetUrl(widget); - html += ""; - } catch (IOException e) { - e.printStackTrace(); - } - } - - private String getWidgetUrl(String widgetfname) throws IOException{ - WidgetUploader.uploadWidget(widgetfname); - Element widget = WidgetUploader.getLastWidget(); - String response = instantiateWidget(widget); - return getStartFile(response); - } - - /// Reused from PackagingAndConfiguration - consider refactoring these - private String instantiateWidget(Element widget){ - String response = null; - String widgetUri = widget.getAttributeValue("identifier"); - // instantiate widget and parse results - try { - HttpClient client = new HttpClient(); - PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID); - post.setQueryString("api_key="+API_KEY_VALID+"&widgetid="+widgetUri+"&userid=test&shareddatakey=test"); - client.executeMethod(post); - response = IOUtils.toString(post.getResponseBodyAsStream()); - post.releaseConnection(); - } - catch (Exception e) { - //e.printStackTrace(); - fail("failed to instantiate widget"); - } - return response; - } - - private String getStartFile(String response){ - SAXBuilder builder = new SAXBuilder(); - Reader in = new StringReader(response); - Document doc; - try { - doc = builder.build(in); - } catch (Exception e) { - return null; - } - return doc.getRootElement().getChild("url").getText(); - } - } Added: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/WidgetUpdates.java URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/WidgetUpdates.java?rev=1098970&view=auto ============================================================================== --- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/WidgetUpdates.java (added) +++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/WidgetUpdates.java Tue May 3 08:51:41 2011 @@ -0,0 +1,93 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wookie.tests.conformance; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.IOException; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.wookie.tests.helpers.WidgetUploader; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test cases for Widget Updates + */ +public class WidgetUpdates extends AbstractFunctionalConformanceTest{ + + protected static final String TEST_UPDATES_URL_VALID = TEST_SERVER_LOCATION+"updates"; + + @BeforeClass + public static void setup(){ + html = ""; + + // Install all the test widgets + try { + WidgetUploader.uploadWidget("http://dev.w3.org/2006/waf/widgets-updates/test-suite/test-cases/ta-acquisition11/001/ta-ac-001.wgt");//ac11 + WidgetUploader.uploadWidget("http://dev.w3.org/2006/waf/widgets-updates/test-suite/test-cases/ta-acquisition13/001/ta-ac-001.wgt");//ac13 + WidgetUploader.uploadWidget("http://dev.w3.org/2006/waf/widgets-updates/test-suite/test-cases/ta-processing2/003/ta-pr-003.wgt");//pr203 + WidgetUploader.uploadWidget("http://dev.w3.org/2006/waf/widgets-updates/test-suite/test-cases/ta-processing2/008/ta-pr-008.wgt");//pr208 + WidgetUploader.uploadWidget("http://dev.w3.org/2006/waf/widgets-updates/test-suite/test-cases/ta-processing2/009/ta-pr-009.wgt");//pr209 + WidgetUploader.uploadWidget("http://dev.w3.org/2006/waf/widgets-updates/test-suite/test-cases/ta-processing2/010/ta-pr-010.wgt");//pr210 + WidgetUploader.uploadWidget("http://dev.w3.org/2006/waf/widgets-updates/test-suite/test-cases/ta-processing2/011/ta-pr-011.wgt");//pr211 + WidgetUploader.uploadWidget("http://dev.w3.org/2006/waf/widgets-updates/test-suite/test-cases/ta-processing2/012/ta-pr-012.wgt");//pr212 + WidgetUploader.uploadWidget("http://dev.w3.org/2006/waf/widgets-updates/test-suite/test-cases/ta-processing2/013/ta-pr-013.wgt");//pr213 + WidgetUploader.uploadWidget("http://dev.w3.org/2006/waf/widgets-updates/test-suite/test-cases/ta-processing2/015/ta-pr-015.wgt");//pr215 + WidgetUploader.uploadWidget("http://dev.w3.org/2006/waf/widgets-updates/test-suite/test-cases/ta-processing2/016/ta-pr-016.wgt");//pr216 + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void update(){ + // Install all updates by calling POST /updates + try { + HttpClient client = new HttpClient(); + PostMethod post = new PostMethod(TEST_UPDATES_URL_VALID); + post.setQueryString("api_key="+API_KEY_VALID+"&widgetid="+WIDGET_ID_VALID+"&userid=test&shareddatakey=propstest"); + setAuthenticationCredentials(client); + client.executeMethod(post); + int code = post.getStatusCode(); + assertEquals(201,code); + post.releaseConnection(); + } + catch (Exception e) { + e.printStackTrace(); + fail("post failed"); + } + + // Instantiate and output + outputInstance("ta-acquisition11:1"); + outputInstance("ta-acquisition13:1"); + outputInstance("http://a.net/widget/ta-xx/042"); + outputInstance("ta-processing2:8"); + outputInstance("ta-processing2:9"); + outputInstance("ta-processing2:10"); + outputInstance("ta-processing2:11"); + outputInstance("ta-processing2:12"); + outputInstance("ta-processing2:13"); + outputInstance("ta-processing2:15"); + outputInstance("ta-processing2:16"); + + } + + + + + +}