Author: scottbw
Date: Fri Sep  3 21:22:02 2010
New Revision: 992476

URL: http://svn.apache.org/viewvc?rev=992476&view=rev
Log:
Extracted utility methods from P&C test so I can use them to implement other 
tests (viewmodes, i18n) without sticking them all in one class. Also fixed an 
error in one of the tests (though its still wrong - but in w3c's test case and 
not in our implementation)

Added:
    
incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/ConformanceTest.java
Modified:
    
incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/PackagingAndConfiguration.java

Added: 
incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/ConformanceTest.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/ConformanceTest.java?rev=992476&view=auto
==============================================================================
--- 
incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/ConformanceTest.java
 (added)
+++ 
incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/ConformanceTest.java
 Fri Sep  3 21:22:02 2010
@@ -0,0 +1,91 @@
+/*
+ *  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.w3c.test;
+
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.wookie.w3c.W3CWidget;
+import org.apache.wookie.w3c.W3CWidgetFactory;
+import org.apache.wookie.w3c.exceptions.BadManifestException;
+import org.apache.wookie.w3c.exceptions.BadWidgetZipFileException;
+import org.apache.wookie.w3c.exceptions.InvalidContentTypeException;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * Abstract base class for conformance tests, including basic utility methods 
for loading and testing widget test cases from W3C
+ */
+public abstract class ConformanceTest {
+       
+       static File download;
+       static File output;
+       
+       @BeforeClass
+       public static void setup() throws IOException{
+               download = File.createTempFile("wookie-download", "wgt");
+               output = File.createTempFile("wookie-output", "tmp");
+       }
+       
+       @AfterClass
+       public static void tearDown(){
+               download.delete();
+               output.delete();
+       }
+       
+       private W3CWidget downloadWidget(String url) throws 
InvalidContentTypeException, BadWidgetZipFileException, BadManifestException, 
Exception{
+               return downloadWidget(url, true);
+       }
+       
+       protected W3CWidget downloadWidget(String url, boolean 
ignoreContentType) throws InvalidContentTypeException, 
BadWidgetZipFileException, BadManifestException, Exception{
+               W3CWidgetFactory fac = new W3CWidgetFactory();
+               fac.setLocalPath("http:localhost/widgets");
+               fac.setFeatures(new String[]{"feature:a9bb79c1"});
+               fac.setEncodings(new String[]{"UTF-8", 
"ISO-8859-1","Windows-1252"});
+               if (download.exists()) download.delete();
+               if (output.exists()) output.delete();
+               output.mkdir();
+               fac.setOutputDirectory(output.getAbsolutePath());
+               return fac.parse(new URL(url),ignoreContentType);
+       }
+       
+       public String processWidgetWithErrors(String url){
+               try {
+                       downloadWidget(url);
+               } catch (BadWidgetZipFileException e) {
+                       if (e.getMessage()!=null) return e.getMessage();
+                       return "Bad Widget Zip File";
+               } catch (BadManifestException e) {
+                       if (e.getMessage()!=null) return e.getMessage();
+                       return "Bad Manifest";
+               } catch (Exception e) {
+                       return e.getMessage();
+               }
+               return null;
+       }
+       
+       public W3CWidget processWidgetNoErrors(String url){
+               try {
+                       return downloadWidget(url);
+               } catch (Exception e) {
+                       e.printStackTrace();
+                       fail();
+                       return null;
+               }
+       }
+
+}

Modified: 
incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/PackagingAndConfiguration.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/PackagingAndConfiguration.java?rev=992476&r1=992475&r2=992476&view=diff
==============================================================================
--- 
incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/PackagingAndConfiguration.java
 (original)
+++ 
incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/PackagingAndConfiguration.java
 Fri Sep  3 21:22:02 2010
@@ -55,63 +55,7 @@ import org.junit.Test;
  * @author scott
  *
  */
-public class PackagingAndConfiguration{
-       
-        static File download;
-        static File output;
-       
-       @BeforeClass
-       public static void setup() throws IOException{
-               download = File.createTempFile("wookie-download", "wgt");
-               output = File.createTempFile("wookie-output", "tmp");
-       }
-       
-       @AfterClass
-       public static void tearDown(){
-               download.delete();
-               output.delete();
-       }
-       
-       private W3CWidget downloadWidget(String url) throws 
InvalidContentTypeException, BadWidgetZipFileException, BadManifestException, 
Exception{
-               return downloadWidget(url, true);
-       }
-       
-       private W3CWidget downloadWidget(String url, boolean ignoreContentType) 
throws InvalidContentTypeException, BadWidgetZipFileException, 
BadManifestException, Exception{
-               W3CWidgetFactory fac = new W3CWidgetFactory();
-               fac.setLocalPath("http:localhost/widgets");
-               fac.setFeatures(new String[]{"feature:a9bb79c1"});
-               fac.setEncodings(new String[]{"UTF-8", 
"ISO-8859-1","Windows-1252"});
-               if (download.exists()) download.delete();
-               if (output.exists()) output.delete();
-               output.mkdir();
-               fac.setOutputDirectory(output.getAbsolutePath());
-               return fac.parse(new URL(url),ignoreContentType);
-       }
-       
-       public String processWidgetWithErrors(String url){
-               try {
-                       downloadWidget(url);
-               } catch (BadWidgetZipFileException e) {
-                       if (e.getMessage()!=null) return e.getMessage();
-                       return "Bad Widget Zip File";
-               } catch (BadManifestException e) {
-                       if (e.getMessage()!=null) return e.getMessage();
-                       return "Bad Manifest";
-               } catch (Exception e) {
-                       return e.getMessage();
-               }
-               return null;
-       }
-       
-       public W3CWidget processWidgetNoErrors(String url){
-               try {
-                       return downloadWidget(url);
-               } catch (Exception e) {
-                       e.printStackTrace();
-                       fail();
-                       return null;
-               }
-       }
+public class PackagingAndConfiguration extends ConformanceTest{
        
        // 1 files
        @Test
@@ -577,7 +521,7 @@ public class PackagingAndConfiguration{
        public void cx(){
                W3CWidget widget = 
processWidgetNoErrors("http://dev.w3.org/2006/waf/widgets/test-suite/test-cases/ta-YUMJAPVEgI/004/cx.wgt";);
                assertEquals("",  getLicenseText(widget));      
-               assertEquals("license/pass.html", getLicenseHref(widget));
+               assertEquals("test-license/pass.html", getLicenseHref(widget));
        }
 
        // 21 Icon


Reply via email to