[Yanel-commits] rev 40359 - in public/yanel/trunk/src: test/htmlunit/org/wyona/yanel/htmlunit test/htmlunit/org/wyona/yanel/htmlunit/yanelwebsite webapp/src/java/org/wyona/yanel/servlet

simon at wyona.com simon at wyona.com
Tue Dec 9 11:41:01 CET 2008


Author: simon
Date: 2008-12-09 11:41:01 +0100 (Tue, 09 Dec 2008)
New Revision: 40359

Added:
   public/yanel/trunk/src/test/htmlunit/org/wyona/yanel/htmlunit/yanelwebsite/GlobalDataWebTest.java
Modified:
   public/yanel/trunk/src/test/htmlunit/org/wyona/yanel/htmlunit/AbstractHtmlUnitTest.java
   public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java
Log:
see http://lists.wyona.org/pipermail/yanel-development/2008-December/002517.html thanks to guillaume

Modified: public/yanel/trunk/src/test/htmlunit/org/wyona/yanel/htmlunit/AbstractHtmlUnitTest.java
===================================================================
--- public/yanel/trunk/src/test/htmlunit/org/wyona/yanel/htmlunit/AbstractHtmlUnitTest.java	2008-12-09 10:25:44 UTC (rev 40358)
+++ public/yanel/trunk/src/test/htmlunit/org/wyona/yanel/htmlunit/AbstractHtmlUnitTest.java	2008-12-09 10:41:01 UTC (rev 40359)
@@ -28,6 +28,7 @@
 import org.apache.commons.logging.impl.SimpleLog;
 
 import com.gargoylesoftware.htmlunit.CollectingAlertHandler;
+import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
 import com.gargoylesoftware.htmlunit.Page;
 import com.gargoylesoftware.htmlunit.ThreadedRefreshHandler;
 import com.gargoylesoftware.htmlunit.WebClient;
@@ -199,6 +200,25 @@
         this.currentPage = handlePage(page);
     }
 
+    protected void loadErrorPage(String pageURL, int expectedErrorCode) throws Exception {
+        int statusCode;
+        try {
+            loadHtmlPage(pageURL);
+            statusCode = this.response.getStatusCode();
+        } catch (FailingHttpStatusCodeException e) {
+            statusCode = e.getStatusCode();
+        }
+        assertTrue("Response status for reserved "+pageURL+" error page not "+
+         expectedErrorCode+" but "+statusCode, statusCode == expectedErrorCode);
+    }
+
+    protected void loadResource(String resourceURL) throws Exception {
+        URL url = new URL(baseURL + resourceURL);
+        Page resource = webClient.getPage(url);
+        this.response = resource.getWebResponse();
+        assertTrue("Response should not be a HTML page", ! (resource instanceof HtmlPage));
+    }
+    
     /**
      * Click on an element like a button or an anchor (link).
      * 

Added: public/yanel/trunk/src/test/htmlunit/org/wyona/yanel/htmlunit/yanelwebsite/GlobalDataWebTest.java
===================================================================
--- public/yanel/trunk/src/test/htmlunit/org/wyona/yanel/htmlunit/yanelwebsite/GlobalDataWebTest.java	                        (rev 0)
+++ public/yanel/trunk/src/test/htmlunit/org/wyona/yanel/htmlunit/yanelwebsite/GlobalDataWebTest.java	2008-12-09 10:41:01 UTC (rev 40359)
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2008 Wyona
+ *
+ *  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.wyona.org/licenses/APACHE-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.wyona.yanel.htmlunit.yanelwebsite;
+
+import org.wyona.yanel.htmlunit.AbstractHtmlUnitTest;
+
+/**
+ * Test the resources under the Yanel reserved prefix.
+ */
+public class GlobalDataWebTest extends AbstractHtmlUnitTest {
+
+    private String getReservedURL(String resourceRelativeURL) throws Exception {
+        String reservedPrefix = "yanel/";//XXX HACK
+        return reservedPrefix  + resourceRelativeURL;
+    }
+
+    private void loadReservedHtmlPage(String pageRelativeURL) throws Exception {
+        loadHtmlPage(getReservedURL(pageRelativeURL));
+    }
+
+    private void loadReservedErrorPage(String pageRelativeURL, int expectedErrorCode) throws Exception {
+        loadErrorPage(getReservedURL(pageRelativeURL), expectedErrorCode);
+    }
+
+    private void loadReservedResource(String resourceRelativeURL) throws Exception {
+        loadResource(getReservedURL(resourceRelativeURL));
+    }
+
+    protected void setUp() throws Exception {
+        this.testName = "Global Data Web Test";
+        super.setUp();
+    }
+
+    public void testAboutPage() throws Exception {
+        loadReservedHtmlPage("about.html");
+        assertTitleEquals("About Yanel");
+        assertPageContainsText("Version");
+    }
+
+    public void testUsersPages() throws Exception {
+        //TODO: test an existing user page
+
+        //XXX: IMHO ( see http://lists.wyona.org/pipermail/yanel-development/2008-December/002514.html ) this should instead redirect to a login page or at least fail gracefully:
+        loadReservedErrorPage("users/dummy.html", 500);
+
+        loadReservedResource("user-mgmt/list-users.html");
+        assertEquals(0, response.getResponseBody().length);
+    }
+
+    public void testDataRepoSitetreePage() throws Exception {
+        loadReservedHtmlPage("data-repository-sitetree.html");
+        assertTitleContains("Sitetree");
+        assertTitleContains("Yanel");
+        //XXX should work, why does it not?!?: clickLink("?yanel.resource.viewid=xmlVersion");
+    }
+
+    public void testResourceTypesPages() throws Exception {
+        loadReservedErrorPage("resource-types/dummy", /* XXX: should be 404: */500);
+
+        loadReservedErrorPage("resource-types/http%3a%2f%2fwww.wyona.org%2fyanel%2fresource%2f1.0%3a%3afile/yanel/icons/1x1/rt-icon.png", /* XXX: should be 404: */500);
+        loadReservedResource("resource-types/http%3a%2f%2fwww.wyona.org%2fyanel%2fresource%2f1.0%3a%3afile/yanel/icons/32x32/rt-icon.png");
+        assertNotNull(response.getResponseHeaderValue("Last-Modified"));
+        //TODO: test 304 handling
+
+        loadReservedErrorPage("resource-types/http%3a%2f%2fwww.wyona.org%2fyanel%2fresource%2f1.0%3a%3atesting-control/dummy", /* XXX: should be 404: */500);
+        loadReservedResource("resource-types/http%3a%2f%2fwww.wyona.org%2fyanel%2fresource%2f1.0%3a%3atesting-control/js/ajaxexecutetests.js");
+        assertNotNull(response.getResponseHeaderValue("Last-Modified"));
+        //TODO: test 304 handling
+    }
+
+    public void testHtdocsPages() throws Exception {
+        loadReservedHtmlPage("help.html"); //XXX: Is this page really used anymore? Most of the links here are broken...
+        /* XXX: should be not null: */ assertNull(response.getResponseHeaderValue("Last-Modified"));
+        assertTitleContains("Help");
+        //assertTitleContains("Yanel");
+        clickLink("../index.html?yanel.toolbar=on");
+
+        loadReservedResource("yanel_toolbar_logo.png");
+    }
+
+    public void testNonExistingPage() throws Exception {
+        loadReservedErrorPage("dummy.html", 404);
+    }
+
+}

Modified: public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java
===================================================================
--- public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java	2008-12-09 10:25:44 UTC (rev 40358)
+++ public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java	2008-12-09 10:41:01 UTC (rev 40359)
@@ -1877,6 +1877,7 @@
             log.warn("TODO: Implementation not finished yet!");
         } else if (path.indexOf("about.html") >= 0) {
             response.setStatus(javax.servlet.http.HttpServletResponse.SC_OK);
+            response.setHeader("Content-Type", "text/html");
             StringBuffer sb = new StringBuffer("<html>");
             sb.append("<head><title>About Yanel</title></head>");
             sb.append("<body><h1>About Yanel</h1><p>Version " + yanel.getVersion() + "-r" + yanel.getRevision() + "</p><p>Copyright &#169; 2005 - 2008 Wyona. All rights reserved.</p></body>");
@@ -1938,7 +1939,7 @@
                 
                 if (htdocIn != null) {
                     log.debug("Resource-Type specific data: " + htdocsPath);
-                    // TODO: Set HTTP header (mime-type, size, etc.)
+                    // TODO: Set more HTTP headers (size, etc.)
                     String mimeType = guessMimeType(FilenameUtils.getExtension(FilenameUtils.getName(htdocsPath)));
                     if(sourceLastModified >= 0) response.setDateHeader("Last-Modified", sourceLastModified);
                     response.setHeader("Content-Type", mimeType);
@@ -1968,7 +1969,7 @@
             if (globalFile.exists()) {
                 log.debug("Global data: " + globalFile);
 
-                // TODO: Set HTTP header (mime-type, size, etc.)
+                // TODO: Set more HTTP headers (size, etc.)
                 String mimeType = guessMimeType(FilenameUtils.getExtension(globalFile.getName()));
                 response.setHeader("Content-Type", mimeType);
 



More information about the Yanel-commits mailing list