Index: tests/JettyScenario/src/JettyScenario.java =================================================================== --- tests/JettyScenario/src/JettyScenario.java (revision 546759) +++ tests/JettyScenario/src/JettyScenario.java (working copy) @@ -1,191 +0,0 @@ -/* - * 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."); - } -} Index: tests/JettyScenario/src/org/apache/harmony/test/jetty/JettyScenario.java =================================================================== --- tests/JettyScenario/src/org/apache/harmony/test/jetty/JettyScenario.java (revision 0) +++ tests/JettyScenario/src/org/apache/harmony/test/jetty/JettyScenario.java (revision 0) @@ -0,0 +1,193 @@ +/* + * 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. + */ + +package org.apache.harmony.test.jetty; + +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."); + } +} Index: tests/JettyScenario/src/org/apache/harmony/test/jetty/JettyTestCase.java =================================================================== --- tests/JettyScenario/src/org/apache/harmony/test/jetty/JettyTestCase.java (revision 0) +++ tests/JettyScenario/src/org/apache/harmony/test/jetty/JettyTestCase.java (revision 0) @@ -0,0 +1,232 @@ +/* + * 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. + */ + +package org.apache.harmony.test.jetty; + +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 java.util.Vector; + +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", "60")).intValue() * 1000; + + 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; + Vector cv = new Vector(); + Vector fv = new Vector(); + Vector sv = new Vector(); + try { + cs = creader.readLine(); + fs = freader.readLine(); + while (cs != null && fs != null) { + if (!compareLines(cs, fs)) { + cv.add(cs); + sv.add(fs); + } + fv.add(fs); + 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("Page have different number of lines than etalon."); + return false; + } + + if (cv.size() != 0 || fv.size() != 0) { + if (!compareRegardlessOrder(cv, sv, fv)) { + LOG_OUT.println("Page differs from etalon (even if lines order is not checked)."); + 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 compareRegardlessOrder(Vector first, Vector second, Vector third) { + for (int i = 0; i < first.size(); i++) { + boolean ok = false; + for (int j = 0; j < third.size(); j++) { + if (compareLines((String)first.elementAt(i), (String)third.elementAt(j))) { + ok = true; + } + } + if (!ok) { + LOG_OUT.println("Lines:"); + int linesCount = (first.size() > 20) ? 20 : first.size(); + for (int j = 0; j < linesCount; j++) { + LOG_OUT.println("--content-----------------------------------------------------------------------"); + LOG_OUT.println((String)first.elementAt(j)); + LOG_OUT.println("--etalon------------------------------------------------------------------------"); + LOG_OUT.println((String)second.elementAt(j)); + } + LOG_OUT.println("--------------------------------------------------------------------------------"); + if (first.size() > 20) { + LOG_OUT.println("and " + (first.size() - 20) + " lines more"); + } + LOG_OUT.println("do not match each other."); + return false; + } + } + 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(); + } +} Index: tests/JettyScenario/src/JettyTestCase.java =================================================================== --- tests/JettyScenario/src/JettyTestCase.java (revision 546759) +++ tests/JettyScenario/src/JettyTestCase.java (working copy) @@ -1,195 +0,0 @@ -/* - * 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", "60")).intValue() * 1000; - - 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(); - } -} Index: adaptors/JettyScenario/parameters.xml =================================================================== --- adaptors/JettyScenario/parameters.xml (revision 545082) +++ adaptors/JettyScenario/parameters.xml (working copy) @@ -28,6 +28,9 @@ + @@ -66,8 +69,8 @@ - + - + Index: adaptors/JettyScenario/adaptor.xml =================================================================== --- adaptors/JettyScenario/adaptor.xml (revision 545082) +++ adaptors/JettyScenario/adaptor.xml (working copy) @@ -25,6 +25,10 @@ + + + + @@ -77,6 +81,7 @@ + + + + + + + + + + + + + + @@ -100,7 +119,7 @@ - + @@ -124,6 +143,7 @@ haltonfailure="false" printsummary="on" failureproperty="scenario.failed"> + @@ -139,16 +159,18 @@ - + - + + + - + @@ -171,33 +193,14 @@ + + - - - - - - - - - - - - - - - - - @@ -221,7 +224,7 @@ message="${ls}================================================================================${ls}Scenario results:${ls}${ls}"/> - + - - - - - - - - - - - Sending notification - - -