From: <fg...@us...> - 2010-02-24 22:25:45
|
Revision: 2054 http://openutils.svn.sourceforge.net/openutils/?rev=2054&view=rev Author: fgiust Date: 2010-02-24 22:25:38 +0000 (Wed, 24 Feb 2010) Log Message: ----------- general cleanup, finally solved the problem with the stacktrace logged by tomcat by moving tlds found in the classpath to the test dir Modified Paths: -------------- trunk/openutils-testing4web/pom.xml trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/BaseJspEmbeddedTest.java trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/BaseJspJunitEmbeddedTest.java trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/BaseJspTestngEmbeddedTest.java trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/TestServletOptions.java trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/TestTldLocationsCache.java trunk/openutils-testing4web/src/test/java/net/sourceforge/openutils/testing4web/SampleEL.java trunk/openutils-testing4web/src/test/java/net/sourceforge/openutils/testing4web/SampleJunitServletUnitTest.java trunk/openutils-testing4web/src/test/java/net/sourceforge/openutils/testing4web/SampleTestNgServletUnitTest.java Removed Paths: ------------- trunk/openutils-testing4web/src/site/changes/ Modified: trunk/openutils-testing4web/pom.xml =================================================================== --- trunk/openutils-testing4web/pom.xml 2010-02-24 15:55:45 UTC (rev 2053) +++ trunk/openutils-testing4web/pom.xml 2010-02-24 22:25:38 UTC (rev 2054) @@ -1,4 +1,5 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>net.sourceforge.openutils</groupId> @@ -6,7 +7,7 @@ <version>1.2</version> </parent> <artifactId>openutils-testing4web</artifactId> - <name>Openutils web test utils</name> + <name>Openutils testing4web</name> <version>1.1.1-SNAPSHOT</version> <inceptionYear>2008</inceptionYear> <description>A simple infrastructure to build unit tests using ServletUnit, with all the needed Maven dependencies Modified: trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/BaseJspEmbeddedTest.java =================================================================== --- trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/BaseJspEmbeddedTest.java 2010-02-24 15:55:45 UTC (rev 2053) +++ trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/BaseJspEmbeddedTest.java 2010-02-24 22:25:38 UTC (rev 2054) @@ -1,6 +1,6 @@ /** * - * Openutils web test utils (http://www.openmindlab.com/lab/products/testing4web.html) + * Openutils testing4web (http://www.openmindlab.com/lab/products/testing4web.html) * Copyright(C) 2008-2010, Openmind S.r.l. http://www.openmindonline.it * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +20,7 @@ import java.io.File; import java.io.InputStream; +import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLDecoder; import java.util.Hashtable; @@ -54,54 +55,101 @@ */ protected ServletRunner runner; + /** + * The context path (by default "/context" + * @return the context path + */ protected String getContext() { return "/context"; } + /** + * Returns the path to a test web.xml available in the classpath, by default "WEB-INF/web.xml" + * @return path to a test web.xml available in the classpath + */ + protected String getWebXmlPathInClasspath() + { + return "WEB-INF/web.xml"; + } + + /** + * Returns the url used for accessing a jsp (defaults to "http://localhost" + getContext() + "/jsps/" + jsp) + * @param jsp jsp filename + * @return full url that can be used for servletunit requests + */ protected String getJspUrl(String jsp) { return "http://localhost" + getContext() + "/jsps/" + jsp; } /** - * @see junit.framework.TestCase#setUp() + * Setup Servletunit + * @throws Exception */ public void setUp() throws Exception { - // need to pass a web.xml file to setup servletunit working directory - ClassLoader classLoader = getClass().getClassLoader(); - URL webXmlUrl = classLoader.getResource("WEB-INF/web.xml"); - String path = URLDecoder.decode(webXmlUrl.getFile(), "UTF-8"); + File webxmlFile = getWebXml(); + if (!webxmlFile.exists()) + { + throw new AssertionError("No " + getWebXmlPathInClasspath() + " found in classpath"); + } HttpUnitOptions.setDefaultCharacterSet("utf-8"); System.setProperty("file.encoding", "utf-8"); // start servletRunner - runner = new ServletRunner(new File(path), getContext()); + runner = new ServletRunner(webxmlFile, getContext()); Hashtable<String, String> params = new Hashtable<String, String>(); params.put("javaEncoding", "utf-8"); params.put("development", "true"); params.put("keepgenerated", "false"); - params.put("modificationTestInterval", Integer.toString(Integer.MAX_VALUE / 1000)); + params.put("modificationTestInterval", "1000"); params.put("engineOptionsClass", TestServletOptions.class.getName()); runner.registerServlet("*.jsp", "org.apache.jasper.servlet.JspServlet", params); log.debug("ServletRunner setup OK"); + } + /** + * Returns the web.xml file, by loading the path specified by {@link #getWebXmlPathInClasspath()} from the classpath + * @return web.xml file + */ + protected File getWebXml() + { + // need to pass a web.xml file to setup servletunit working directory + ClassLoader classLoader = getClass().getClassLoader(); + URL webXmlUrl = classLoader.getResource(getWebXmlPathInClasspath()); + String path = null; + try + { + path = URLDecoder.decode(webXmlUrl.getFile(), "UTF-8"); + } + catch (UnsupportedEncodingException e) + { + // can't happen + } + File webxmlFile = new File(path); + return webxmlFile; } /** - * @see junit.framework.TestCase#tearDown() + * Tear down ServletUnit */ - public void tearDown() throws Exception + public void tearDown() { // shutdown servlet engine runner.shutDown(); } + /** + * Do a get request to the specified jsp and compare the results with a txt file found in the classpath (path + * "/jsps/<em>jspname.txt</em>" + * @param jspname jsp file name + * @throws Exception any exception thrown by servletunit + */ protected void checkGetWithExpectedTxt(String jspname) throws Exception { WebRequest request = new GetMethodWebRequest(getJspUrl(jspname)); @@ -124,6 +172,11 @@ assertEquals(responseText, expected); } + /** + * A generic assertEquals method that redirect to the appropriate junit/testng implementation. + * @param expected expected value + * @param actual actual value + */ protected abstract void assertEquals(String expected, String actual); } \ No newline at end of file Modified: trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/BaseJspJunitEmbeddedTest.java =================================================================== --- trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/BaseJspJunitEmbeddedTest.java 2010-02-24 15:55:45 UTC (rev 2053) +++ trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/BaseJspJunitEmbeddedTest.java 2010-02-24 22:25:38 UTC (rev 2054) @@ -1,6 +1,6 @@ /** * - * Openutils web test utils (http://www.openmindlab.com/lab/products/testing4web.html) + * Openutils testing4web (http://www.openmindlab.com/lab/products/testing4web.html) * Copyright(C) 2008-2010, Openmind S.r.l. http://www.openmindonline.it * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,6 +24,7 @@ /** + * Base TestCase class for jsp/web tests, junit flavor. * @author fgiust * @version $Id$ */ @@ -45,7 +46,7 @@ */ @Override @After - public void tearDown() throws Exception + public void tearDown() { super.tearDown(); } Modified: trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/BaseJspTestngEmbeddedTest.java =================================================================== --- trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/BaseJspTestngEmbeddedTest.java 2010-02-24 15:55:45 UTC (rev 2053) +++ trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/BaseJspTestngEmbeddedTest.java 2010-02-24 22:25:38 UTC (rev 2054) @@ -1,6 +1,6 @@ /** * - * Openutils web test utils (http://www.openmindlab.com/lab/products/testing4web.html) + * Openutils testing4web (http://www.openmindlab.com/lab/products/testing4web.html) * Copyright(C) 2008-2010, Openmind S.r.l. http://www.openmindonline.it * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,6 +24,7 @@ /** + * Base TestCase class for jsp/web tests, testng flavor. * @author fgiust * @version $Id$ */ @@ -45,7 +46,7 @@ */ @Override @AfterClass - public void tearDown() throws Exception + public void tearDown() { super.tearDown(); } Modified: trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/TestServletOptions.java =================================================================== --- trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/TestServletOptions.java 2010-02-24 15:55:45 UTC (rev 2053) +++ trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/TestServletOptions.java 2010-02-24 22:25:38 UTC (rev 2054) @@ -1,6 +1,6 @@ /** * - * Openutils web test utils (http://www.openmindlab.com/lab/products/testing4web.html) + * Openutils testing4web (http://www.openmindlab.com/lab/products/testing4web.html) * Copyright(C) 2008-2010, Openmind S.r.l. http://www.openmindonline.it * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,6 +32,7 @@ /** + * Extension of the standard ServletOptions class which provides a different TldLocationCache implementation. * @author fgiust * @version $Id$ */ Modified: trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/TestTldLocationsCache.java =================================================================== --- trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/TestTldLocationsCache.java 2010-02-24 15:55:45 UTC (rev 2053) +++ trunk/openutils-testing4web/src/main/java/net/sourceforge/openutils/testing4web/TestTldLocationsCache.java 2010-02-24 22:25:38 UTC (rev 2054) @@ -1,6 +1,6 @@ /** * - * Openutils web test utils (http://www.openmindlab.com/lab/products/testing4web.html) + * Openutils testing4web (http://www.openmindlab.com/lab/products/testing4web.html) * Copyright(C) 2008-2010, Openmind S.r.l. http://www.openmindonline.it * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,6 +33,7 @@ import javax.servlet.ServletContext; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.jasper.JasperException; @@ -44,6 +45,7 @@ /** + * A TldLocationsCache implementation that can find and load tlds from the classpath. * @author fgiust * @version $Id$ */ @@ -147,10 +149,28 @@ String uri = getUriFromTld(file); if (uri != null && filemappings.get(uri) == null) { - String base = ctxt2.getRealPath("/"); + String contextRoot = ctxt2.getRealPath("/"); + File filetomap = file; + if (!StringUtils.startsWith(file.getAbsolutePath(), contextRoot)) + { - String filepath = getRelativePath(new File(base), file); + File destination = new File(new File(contextRoot, "-tldsfromclasspath"), file.getName()); + try + { + FileUtils.copyFile(file, destination, true); + filetomap = destination; + } + catch (IOException e) + { + log.warn("Unable to copy tld " + + file.getAbsolutePath() + + " to " + + destination.getAbsolutePath()); + } + } + String filepath = getRelativePath(new File(contextRoot), filetomap); + log.debug("Adding {} to cache with url {}", uri, filepath); filemappings.put(uri, new String[]{filepath, null }); } Modified: trunk/openutils-testing4web/src/test/java/net/sourceforge/openutils/testing4web/SampleEL.java =================================================================== --- trunk/openutils-testing4web/src/test/java/net/sourceforge/openutils/testing4web/SampleEL.java 2010-02-24 15:55:45 UTC (rev 2053) +++ trunk/openutils-testing4web/src/test/java/net/sourceforge/openutils/testing4web/SampleEL.java 2010-02-24 22:25:38 UTC (rev 2054) @@ -1,6 +1,6 @@ /** * - * Openutils web test utils (http://www.openmindlab.com/lab/products/testing4web.html) + * Openutils testing4web (http://www.openmindlab.com/lab/products/testing4web.html) * Copyright(C) 2008-2010, Openmind S.r.l. http://www.openmindonline.it * * Licensed under the Apache License, Version 2.0 (the "License"); Modified: trunk/openutils-testing4web/src/test/java/net/sourceforge/openutils/testing4web/SampleJunitServletUnitTest.java =================================================================== --- trunk/openutils-testing4web/src/test/java/net/sourceforge/openutils/testing4web/SampleJunitServletUnitTest.java 2010-02-24 15:55:45 UTC (rev 2053) +++ trunk/openutils-testing4web/src/test/java/net/sourceforge/openutils/testing4web/SampleJunitServletUnitTest.java 2010-02-24 22:25:38 UTC (rev 2054) @@ -1,6 +1,6 @@ /** * - * Openutils web test utils (http://www.openmindlab.com/lab/products/testing4web.html) + * Openutils testing4web (http://www.openmindlab.com/lab/products/testing4web.html) * Copyright(C) 2008-2010, Openmind S.r.l. http://www.openmindonline.it * * Licensed under the Apache License, Version 2.0 (the "License"); Modified: trunk/openutils-testing4web/src/test/java/net/sourceforge/openutils/testing4web/SampleTestNgServletUnitTest.java =================================================================== --- trunk/openutils-testing4web/src/test/java/net/sourceforge/openutils/testing4web/SampleTestNgServletUnitTest.java 2010-02-24 15:55:45 UTC (rev 2053) +++ trunk/openutils-testing4web/src/test/java/net/sourceforge/openutils/testing4web/SampleTestNgServletUnitTest.java 2010-02-24 22:25:38 UTC (rev 2054) @@ -1,6 +1,6 @@ /** * - * Openutils web test utils (http://www.openmindlab.com/lab/products/testing4web.html) + * Openutils testing4web (http://www.openmindlab.com/lab/products/testing4web.html) * Copyright(C) 2008-2010, Openmind S.r.l. http://www.openmindonline.it * * Licensed under the Apache License, Version 2.0 (the "License"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |