harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r531796 [5/5] - in /harmony/enhanced/buildtest/branches/2.0: adaptors/JettyScenario/ tests/ tests/JettyScenario/ tests/JettyScenario/resources/ tests/JettyScenario/resources/JettyScenario/ tests/JettyScenario/src/
Date Tue, 24 Apr 2007 07:21:44 GMT
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/JettyScenario/resources/JettyScenario/static_content_ungzipped.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/JettyScenario/resources/JettyScenario/static_content_ungzipped.txt
------------------------------------------------------------------------------
    svn:executable = *

Added: harmony/enhanced/buildtest/branches/2.0/tests/JettyScenario/src/JettyScenario.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/JettyScenario/src/JettyScenario.java?view=auto&rev=531796
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/JettyScenario/src/JettyScenario.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/JettyScenario/src/JettyScenario.java Tue
Apr 24 00:21:40 2007
@@ -0,0 +1,191 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.
+ */
+
+import com.gargoylesoftware.htmlunit.*;
+import com.gargoylesoftware.htmlunit.html.*;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.zip.GZIPInputStream;
+
+public class JettyScenario extends JettyTestCase {
+
+    static {
+        scenarioRoot = "JettyScenario";
+    }
+
+    public void testInitialPage() {
+        LOG_OUT.println("\n==============================================================testInitialPage===");
+        LOG_OUT.println("Starting initial page test case.");
+        HtmlPage page = (HtmlPage)downloadPage("http://localhost:7070/test/");
+        WebResponse wr = page.getWebResponse();
+        String content = wr.getContentAsString();
+        File etalon = getResourceFile("initial_page.html");
+        savePageContent("initial_page.html", content);
+        assertTrue("Generated content is not correct.", comparePageContent(content, etalon));
+        LOG_OUT.println("Initial page test case passed.");
+    }
+
+    public void testStaticContent() {
+        LOG_OUT.println("\n============================================================testStaticContent===");
+        LOG_OUT.println("Starting static content page test case.");
+        Page page = downloadPage("http://localhost:7070/test/data.txt");
+        WebResponse wr = page.getWebResponse();
+        String content = wr.getContentAsString();
+        File etalon = getResourceFile("static_content.txt");
+        savePageContent("static_content.txt", content);
+        assertTrue("Content is not correct.", comparePageContent(content, etalon));
+        LOG_OUT.println("Static content page test case passed.");
+    }
+
+    public void testSessionDumpServlet() {
+        LOG_OUT.println("\n=======================================================testSessionDumpServlet===");
+        LOG_OUT.println("Starting servlet test case.");
+        HtmlPage page = (HtmlPage)downloadPage("http://localhost:7070/test/session/");
+        WebResponse wr = page.getWebResponse();
+        String content = wr.getContentAsString();
+        File etalon = getResourceFile("session_dump.html");
+        savePageContent("session_dump.html", content);
+        assertTrue("Generated content is not correct.", comparePageContent(content, etalon));
+        LOG_OUT.println("Session dump servlet page is OK.");
+
+        // Test create new session
+
+        HtmlForm[] forms = (HtmlForm[])page.getForms().toArray(new HtmlForm[0]);
+        HtmlForm form = forms[0];
+        try {
+            page = (HtmlPage)form.submit("Action");
+        } catch (IOException ioe) {
+            LOG_OUT.println("Can't submit the form: " + ioe);
+            ioe.printStackTrace(LOG_OUT);
+        }
+        wr = page.getWebResponse();
+        content = wr.getContentAsString();
+        etalon = getResourceFile("session_dump_new.html");
+        savePageContent("session_dump_new.html", content);
+        assertTrue("Generated content is not correct.", comparePageContent(content, etalon));
+        LOG_OUT.println("Session create page is OK.");
+
+        // Test set new value
+
+        forms = (HtmlForm[])page.getForms().toArray(new HtmlForm[0]);
+        form = forms[0];
+        HtmlInput text1 = form.getInputByName("Name");
+        text1.setValueAttribute("somename");
+        HtmlInput text2 = form.getInputByName("Value");
+        text2.setValueAttribute("somevalue");
+        try {
+            HtmlInput set = form.getInputByValue("Set");
+            page = (HtmlPage)form.submit(set);
+        } catch (IOException ioe) {
+            LOG_OUT.println("Can't submit the form: " + ioe);
+            ioe.printStackTrace(LOG_OUT);
+        }
+        wr = page.getWebResponse();
+        content = wr.getContentAsString();
+        etalon = getResourceFile("session_dump_set.html");
+        savePageContent("session_dump_set.html", content);
+        assertTrue("Generated content is not correct.", comparePageContent(content, etalon));
+        LOG_OUT.println("Session set page is OK.");
+
+        // Test remove value
+
+        forms = (HtmlForm[])page.getForms().toArray(new HtmlForm[0]);
+        form = forms[0];
+        text1 = form.getInputByName("Name");
+        text1.setValueAttribute("somename");
+        try {
+            HtmlInput remove = form.getInputByValue("Remove");
+            page = (HtmlPage)form.submit(remove);
+        } catch (IOException ioe) {
+            LOG_OUT.println("Can't submit the form: " + ioe);
+            ioe.printStackTrace(LOG_OUT);
+        }
+        wr = page.getWebResponse();
+        content = wr.getContentAsString();
+        etalon = getResourceFile("session_dump_remove.html");
+        savePageContent("session_dump_remove.html", content);
+        assertTrue("Generated content is not correct.", comparePageContent(content, etalon));
+        LOG_OUT.println("Session remove page is OK.");
+
+        // Test invalidate session
+
+        forms = (HtmlForm[])page.getForms().toArray(new HtmlForm[0]);
+        form = forms[0];
+        try {
+            HtmlInput invalidate = form.getInputByValue("Invalidate");
+            page = (HtmlPage)form.submit(invalidate);
+        } catch (IOException ioe) {
+            LOG_OUT.println("Can't submit the form: " + ioe);
+            ioe.printStackTrace(LOG_OUT);
+        }
+        wr = page.getWebResponse();
+        content = wr.getContentAsString();
+        etalon = getResourceFile("session_dump_invalidate.html");
+        savePageContent("session_dump_invalidate.html", content);
+        assertTrue("Generated content is not correct.", comparePageContent(content, etalon));
+        LOG_OUT.println("Session invalidate page is OK.");
+
+        LOG_OUT.println("Servlet test case passed.");
+    }
+
+    public void testRequestDumpJSP() {
+        LOG_OUT.println("\n===========================================================testRequestDumpJSP===");
+        LOG_OUT.println("Starting JSP test case.");
+        HtmlPage page = (HtmlPage)downloadPage("http://localhost:7070/test/snoop.jsp");
+        WebResponse wr = page.getWebResponse();
+        String content = wr.getContentAsString();
+        File etalon = getResourceFile("request_dump_JSP.html");
+        savePageContent("request_dump_JSP.html", content);
+        assertTrue("Generated content is not correct.", comparePageContent(content, etalon));
+        LOG_OUT.println("JSP test case passed.");
+    }
+
+    public void testGZippedStaticContent() {
+        LOG_OUT.println("\n=====================================================testGZippedStaticContent===");
+        LOG_OUT.println("Starting gzipped static content test case.");
+        Page page = downloadPage("http://localhost:7070/test/data.txt.gz");
+        WebResponse wr = page.getWebResponse();
+        String content = new String();
+
+        LOG_OUT.println("Unpacking content from archive.");
+        try {
+            InputStream contentStream = wr.getContentAsStream();
+            GZIPInputStream gzip = new GZIPInputStream(contentStream);
+            assertNotNull("Can't read from .gz file.", gzip);
+            byte[] buf = new byte[10000];
+            int total_bytes = 0;
+            while (gzip.available() > 0) {
+                int bytes = gzip.read(buf, 0, 10000);
+                if (bytes > 0) {
+                    content += new String(buf, 0, bytes);
+                    total_bytes += bytes;
+                }
+            }
+            gzip.close();
+        } catch (IOException ioe) {
+            LOG_OUT.println("Exception while unpacking gzip file: " + ioe);
+            ioe.printStackTrace(LOG_OUT);
+        }
+
+        File etalon = getResourceFile("static_content_ungzipped.txt");
+        savePageContent("static_content_ungzipped.txt", content);
+        assertTrue("Generated content is not correct.", comparePageContent(content, etalon));
+        LOG_OUT.println("Gzipped static content test case passed.");
+    }
+}

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/JettyScenario/src/JettyScenario.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/JettyScenario/src/JettyTestCase.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/JettyScenario/src/JettyTestCase.java?view=auto&rev=531796
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/JettyScenario/src/JettyTestCase.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/JettyScenario/src/JettyTestCase.java Tue
Apr 24 00:21:40 2007
@@ -0,0 +1,195 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.
+ */
+
+import com.gargoylesoftware.htmlunit.*;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.PrintStream;
+import java.io.StringReader;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+public class JettyTestCase extends TestCase {
+
+    protected static final String proxyHost = System.getProperty("http.proxy.host", null);
+    protected static final int    proxyPort = Integer.valueOf(System.getProperty("http.proxy.port",
"0")).intValue();
+
+    protected static String scenarioRoot;
+    protected static WebClient webClient;
+
+    protected static final String resourcePath = System.getProperty("jetty.scenario.resources.path",
"resources");
+    protected static final String outputPath   = System.getProperty("jetty.scenario.results.path",
"results");
+    protected static final String savePages    = System.getProperty("jetty.scenario.savepages",
"no");
+
+    protected static PrintStream LOG_OUT = System.out;
+    protected static PrintStream LOG_ERR = System.err;
+
+    protected static final int SERVER_START_TIMEOUT = Integer.valueOf(
+        System.getProperty("jetty.server.startup.timeout", "10000")).intValue();
+
+    static {
+        scenarioRoot = ".";
+        if (proxyHost != null) {
+            webClient = new WebClient(BrowserVersion.FULL_FEATURED_BROWSER, proxyHost, proxyPort);
+        } else {
+            webClient = new WebClient();
+        }
+        LOG_OUT.println("Setup completed.");
+    }
+
+    protected Page downloadPage(String link) {
+        Page page = null;
+        URL url = null;
+        try {
+            url = new URL(link);
+            LOG_OUT.println("Loading page from server: " + link);
+            page = webClient.getPage(url);
+        } catch (MalformedURLException mue) {
+            LOG_OUT.println("donwloadPage(): can't create URL for \"" + link + "\": " + mue);
+            mue.printStackTrace(LOG_OUT);
+            return null;
+        } catch (IOException ioe1) {
+            LOG_OUT.println("Looks like server is not started yet, waiting for timeout...");
+            try {
+                Thread.sleep(SERVER_START_TIMEOUT);
+                page = webClient.getPage(url);
+            } catch (IOException ioe2) {
+                LOG_OUT.println("donwloadPage(): can't download URL \"" + link + "\": " +
ioe2);
+                ioe2.printStackTrace(LOG_OUT);
+                return null;
+            } catch (InterruptedException ie) {
+                // ignore
+            }
+        }
+        return page;
+    }
+
+    protected boolean comparePageContent(String content, File etalon) {
+
+        LOG_OUT.println("Comparing page content with etalon: " + etalon.getName());
+
+        LineNumberReader creader = new LineNumberReader(new StringReader(content));
+        LineNumberReader freader = null;
+        try {
+            freader = new LineNumberReader(new FileReader(etalon));
+        } catch (FileNotFoundException fnfe) {
+            LOG_OUT.println("File \"" + etalon.getName() + "\" not found: " + fnfe);
+            fnfe.printStackTrace(LOG_OUT);
+            return false;
+        }
+
+        String cs = null;
+        String fs = null;
+        try {
+            cs = creader.readLine();
+            fs = freader.readLine();
+            while (cs != null && fs != null) {
+                if (!compareLines(cs, fs)) {
+                    LOG_OUT.println("Lines:");
+                    LOG_OUT.println("--content-----------------------------------------------------------------------");
+                    LOG_OUT.println("(" + creader.getLineNumber() + ") " + cs);
+                    LOG_OUT.println("--etalon------------------------------------------------------------------------");
+                    LOG_OUT.println("(" + freader.getLineNumber() + ") " + fs);
+                    LOG_OUT.println("--------------------------------------------------------------------------------");
+                    LOG_OUT.println("do not match each other.");
+                    return false;
+                }
+                cs = creader.readLine();
+                fs = freader.readLine();
+            }
+        } catch (IOException ioe) {
+            LOG_OUT.println("Exception while comparing page content: " + ioe);
+            ioe.printStackTrace(LOG_OUT);
+            return false;
+        }
+
+        if (cs != null || fs != null) {
+            LOG_OUT.println("Files have different number of lines.");
+            return false;
+        }
+
+        try {
+            creader.close();
+            freader.close();
+        } catch (IOException ioe) {
+            LOG_OUT.println("Exception while finishing comparision of page content: " + ioe);
+            ioe.printStackTrace(LOG_OUT);
+            return false;
+        }
+        LOG_OUT.println("Page is equal to etalon.");
+        return true;
+    }
+
+    protected boolean compareLines(String first, String second) {
+        if (second.startsWith("$$$")) {
+            return first.matches(second.substring(3));
+        }
+        return first.equals(second);
+    }
+
+    protected File getResourceFile(String resourceName) {
+        LOG_OUT.println("Getting resource with name: " + resourceName);
+        String s = File.separator;
+        String path = resourcePath + s + scenarioRoot + s + resourceName;
+        File file = null;
+        file = new File(path);
+        assertTrue("Path \"" + path + "\" does not exist.", file.exists());
+        assertTrue("\"" + path + "\" is not a file.", file.isFile());
+        LOG_OUT.println("Found resource: " + path);
+        return file;
+    }
+
+    protected void savePageContent(String name, String content) {
+        if (!savePages.equals("yes")) {
+            return;
+        }
+        String s = File.separator;
+        String dname = outputPath + s + scenarioRoot;
+        File dir = new File(dname);
+        if (!dir.exists()) {
+            assertTrue("Can't create dir for output files: \"" + dname + "\".", dir.mkdirs());
+        }
+        String fname = dname + s + name;
+        LOG_OUT.println("Saving content of downloaded page to: " + fname);
+        File file = new File(fname);
+        if (!file.exists()) {
+            try {
+                assertTrue("Can't create output file: \"" + fname + "\".", file.createNewFile());
+            } catch (IOException ioe) {
+                LOG_OUT.println("Exception while creating \"" + fname + "\" output file:
" + ioe);
+                ioe.printStackTrace(LOG_OUT);
+            }
+        }
+        assertTrue("Can't write to output file: \"" + fname + "\".", file.canWrite());
+        PrintStream writer = null;
+        try {
+            writer = new PrintStream(file);
+        } catch (FileNotFoundException fnfe) {
+            LOG_OUT.println("File \"" + fname + "\" not found: " + fnfe);
+            fnfe.printStackTrace(LOG_OUT);
+        }
+        writer.print(content);
+        writer.close();
+    }
+}

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/JettyScenario/src/JettyTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message