From: <cg...@us...> - 2009-06-22 06:32:37
|
Revision: 6490 http://jython.svn.sourceforge.net/jython/?rev=6490&view=rev Author: cgroves Date: 2009-06-22 06:32:34 +0000 (Mon, 22 Jun 2009) Log Message: ----------- Add enough of mockrunner to run servlet tests and use that to run the modjy tests and some new PyServlet tests from our regular build. Modified Paths: -------------- trunk/jython/.classpath trunk/jython/build.xml trunk/jython/src/org/python/core/PySystemState.java trunk/jython/tests/modjy/build.xml trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java Added Paths: ----------- trunk/jython/Lib/test/pyservlet/ trunk/jython/Lib/test/pyservlet/__init__.py trunk/jython/Lib/test/pyservlet/basic.py trunk/jython/Lib/test/pyservlet/empty.py trunk/jython/Lib/test/pyservlet/increment.py trunk/jython/Lib/test/pyservlet/updated_basic.py trunk/jython/extlibs/mockrunner-0.4.1/ trunk/jython/extlibs/mockrunner-0.4.1/jar/ trunk/jython/extlibs/mockrunner-0.4.1/jar/commons-logging-1.0.4.jar trunk/jython/extlibs/mockrunner-0.4.1/jar/j2ee1.3/ trunk/jython/extlibs/mockrunner-0.4.1/jar/j2ee1.3/servlet.jar trunk/jython/extlibs/mockrunner-0.4.1/jar/jakarta-oro-2.0.8.jar trunk/jython/extlibs/mockrunner-0.4.1/jar/jdom.jar trunk/jython/extlibs/mockrunner-0.4.1/jar/nekohtml.jar trunk/jython/extlibs/mockrunner-0.4.1/lib/ trunk/jython/extlibs/mockrunner-0.4.1/lib/jdk1.5/ trunk/jython/extlibs/mockrunner-0.4.1/lib/jdk1.5/j2ee1.3/ trunk/jython/extlibs/mockrunner-0.4.1/lib/jdk1.5/j2ee1.3/dependencies.txt trunk/jython/extlibs/mockrunner-0.4.1/lib/jdk1.5/j2ee1.3/mockrunner-servlet.jar trunk/jython/extlibs/mockrunner-0.4.1/readme.txt trunk/jython/tests/modjy/java/org/ trunk/jython/tests/modjy/java/org/python/ trunk/jython/tests/modjy/java/org/python/util/ trunk/jython/tests/modjy/java/org/python/util/PyServletTest.java Property Changed: ---------------- trunk/jython/tests/modjy/ Modified: trunk/jython/.classpath =================================================================== --- trunk/jython/.classpath 2009-06-21 22:19:53 UTC (rev 6489) +++ trunk/jython/.classpath 2009-06-22 06:32:34 UTC (rev 6490) @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry excluding="com/ziclix/python/sql/handler/InformixDataHandler.java|com/ziclix/python/sql/handler/OracleDataHandler.java" kind="src" output="build/classes" path="src"/> + <classpathentry kind="src" path="tests/modjy/java"/> <classpathentry kind="src" output="build/classes" path="build/gensrc"/> <classpathentry kind="src" output="build/classes" path="tests/java"/> <classpathentry kind="src" path="bugtests/classes"/> @@ -18,5 +19,7 @@ <classpathentry kind="lib" path="extlibs/asm-commons-3.1.jar"/> <classpathentry kind="lib" path="extlibs/constantine-0.4.jar"/> <classpathentry kind="lib" path="extlibs/jna-posix.jar"/> + <classpathentry kind="lib" path="extlibs/mockrunner-0.4.1/jar/jdom.jar"/> + <classpathentry kind="lib" path="extlibs/mockrunner-0.4.1/lib/jdk1.5/j2ee1.3/mockrunner-servlet.jar"/> <classpathentry kind="output" path="bugtests/classes"/> </classpath> Added: trunk/jython/Lib/test/pyservlet/basic.py =================================================================== --- trunk/jython/Lib/test/pyservlet/basic.py (rev 0) +++ trunk/jython/Lib/test/pyservlet/basic.py 2009-06-22 06:32:34 UTC (rev 6490) @@ -0,0 +1,5 @@ +from javax.servlet.http import HttpServlet + +class basic(HttpServlet): + def doGet(self, req, resp): + resp.getOutputStream().write("Basic text response") Added: trunk/jython/Lib/test/pyservlet/increment.py =================================================================== --- trunk/jython/Lib/test/pyservlet/increment.py (rev 0) +++ trunk/jython/Lib/test/pyservlet/increment.py 2009-06-22 06:32:34 UTC (rev 6490) @@ -0,0 +1,8 @@ +from javax.servlet.http import HttpServlet + +class increment(HttpServlet): + def __init__(self): + self.counter = 0 + def doGet(self, req, resp): + self.counter += 1 + resp.outputStream.write(str(self.counter)) Added: trunk/jython/Lib/test/pyservlet/updated_basic.py =================================================================== --- trunk/jython/Lib/test/pyservlet/updated_basic.py (rev 0) +++ trunk/jython/Lib/test/pyservlet/updated_basic.py 2009-06-22 06:32:34 UTC (rev 6490) @@ -0,0 +1,5 @@ +from javax.servlet.http import HttpServlet + +class basic(HttpServlet): + def doGet(self, req, resp): + resp.outputStream.write("Updated text response") Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2009-06-21 22:19:53 UTC (rev 6489) +++ trunk/jython/build.xml 2009-06-22 06:32:34 UTC (rev 6490) @@ -813,7 +813,7 @@ </jar> </target> - <target name="test" depends="prepare-test,javatest,launchertest,regrtest"/> + <target name="test" depends="prepare-test,javatest,launchertest,regrtest,modjytest"/> <target name="singlejavatest" depends="compile,expose"> <junit haltonfailure="true" fork="true"> <formatter type="brief" usefile="false"/> @@ -842,6 +842,12 @@ </batchtest> </junit> </target> + <target name="modjytest" depends="developer-build"> + <ant dir="tests/modjy"> + <property name="jython_home" value="${dist.dir}"/> + <property name="mockrunner_home" value="${extlibs.dir}/mockrunner-0.4.1"/> + </ant> + </target> <target name="launchertest" depends="developer-build" if="os.family.unix"> <exec executable="${test.shell.dir}/test-jython.sh"> <arg value="${dist.dir}"/> Added: trunk/jython/extlibs/mockrunner-0.4.1/jar/commons-logging-1.0.4.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/mockrunner-0.4.1/jar/commons-logging-1.0.4.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/mockrunner-0.4.1/jar/j2ee1.3/servlet.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/mockrunner-0.4.1/jar/j2ee1.3/servlet.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/mockrunner-0.4.1/jar/jakarta-oro-2.0.8.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/mockrunner-0.4.1/jar/jakarta-oro-2.0.8.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/mockrunner-0.4.1/jar/jdom.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/mockrunner-0.4.1/jar/jdom.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/mockrunner-0.4.1/jar/nekohtml.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/mockrunner-0.4.1/jar/nekohtml.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/mockrunner-0.4.1/lib/jdk1.5/j2ee1.3/dependencies.txt =================================================================== --- trunk/jython/extlibs/mockrunner-0.4.1/lib/jdk1.5/j2ee1.3/dependencies.txt (rev 0) +++ trunk/jython/extlibs/mockrunner-0.4.1/lib/jdk1.5/j2ee1.3/dependencies.txt 2009-06-22 06:32:34 UTC (rev 6490) @@ -0,0 +1,135 @@ +This file lists all the jar files provided by Mockrunner and +the required third party libraries for each jar. Please note +that this file is created automatically by analyzing the +compile time dependencies of all classes in the jar. This +is done recursively, i.e. the dependencies of the third-party +jars are recognized as well. If you add all dependend jars +for a specified mockrunner-xyz.jar to your classpath, you +are on the safe side. However, not all listed dependencies +are necessary at runtime in all cases. Especially with the +"all-in-one"-file mockrunner.jar you don't have to add everything +to the classpath. E.g. if you're only using EJB and JMS, you don't have +to add the web related jar files, because the necessary factories and modules +are created when they are used and lazy initialized respectively. +Please note that the Struts test framework only needs CGLib, if custom action +mappings are used. The jasper related jar files are only necessary if +the JasperJspFactory is used. If you only need one technology it's recommended +to use the corresponding jar file instead of the "all-in-one" mockrunner.jar. +E.g. if you only want to use the JDBC test framework, you can use +mockrunner-jdbc.jar. Please note that each mockrunner-xyz.jar file contains a +jarversion.txt which lists the Mockrunner version and the supported JDK and +J2EE version. + +Created: 06/26/2008 05:59 PM + +Jar file name: mockrunner-tag.jar + +Depends on: + +commons-beanutils-1.7.0.jar +commons-logging-1.0.4.jar +jakarta-oro-2.0.8.jar +jdom.jar +junit.jar +nekohtml.jar +servlet.jar +xercesImpl.jar +xml-apis.jar + + +Jar file name: mockrunner-jms.jar + +Depends on: + +commons-logging-1.0.4.jar +jakarta-oro-2.0.8.jar +jboss-j2ee.jar +junit.jar + + +Jar file name: mockrunner-servlet.jar + +Depends on: + +commons-logging-1.0.4.jar +jakarta-oro-2.0.8.jar +jdom.jar +junit.jar +nekohtml.jar +servlet.jar +xercesImpl.jar +xml-apis.jar + + +Jar file name: mockrunner.jar + +Depends on: + +cglib-nodep-2.2.jar +commons-beanutils-1.7.0.jar +commons-digester-1.8.jar +commons-logging-1.0.4.jar +commons-validator-1.3.1.jar +jakarta-oro-2.0.8.jar +jboss-j2ee.jar +jdom.jar +junit.jar +mockejb.jar +nekohtml.jar +servlet.jar +struts.jar +xercesImpl.jar +xml-apis.jar + + +Jar file name: mockrunner-jca.jar + +Depends on: + +commons-logging-1.0.4.jar +jakarta-oro-2.0.8.jar +jboss-j2ee.jar +junit.jar + + +Jar file name: mockrunner-jdbc.jar + +Depends on: + +commons-logging-1.0.4.jar +jakarta-oro-2.0.8.jar +jdom.jar +junit.jar +xml-apis.jar + + +Jar file name: mockrunner-ejb.jar + +Depends on: + +cglib-nodep-2.2.jar +commons-beanutils-1.7.0.jar +commons-logging-1.0.4.jar +jakarta-oro-2.0.8.jar +jboss-j2ee.jar +junit.jar +mockejb.jar + + +Jar file name: mockrunner-struts.jar + +Depends on: + +cglib-nodep-2.2.jar +commons-beanutils-1.7.0.jar +commons-digester-1.8.jar +commons-logging-1.0.4.jar +commons-validator-1.3.1.jar +jakarta-oro-2.0.8.jar +jdom.jar +junit.jar +nekohtml.jar +servlet.jar +struts.jar +xercesImpl.jar +xml-apis.jar Added: trunk/jython/extlibs/mockrunner-0.4.1/lib/jdk1.5/j2ee1.3/mockrunner-servlet.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/mockrunner-0.4.1/lib/jdk1.5/j2ee1.3/mockrunner-servlet.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/mockrunner-0.4.1/readme.txt =================================================================== --- trunk/jython/extlibs/mockrunner-0.4.1/readme.txt (rev 0) +++ trunk/jython/extlibs/mockrunner-0.4.1/readme.txt 2009-06-22 06:32:34 UTC (rev 6490) @@ -0,0 +1,2 @@ +This contains the minimal set of jars from mockrunner-0.4.1 to run the modjy tests against j2ee1.3 +with jdk1.5. Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2009-06-21 22:19:53 UTC (rev 6489) +++ trunk/jython/src/org/python/core/PySystemState.java 2009-06-22 06:32:34 UTC (rev 6490) @@ -698,10 +698,10 @@ } } - public static Properties getBaseProperties(){ - try{ + public static Properties getBaseProperties() { + try { return System.getProperties(); - }catch(AccessControlException ace){ + } catch (AccessControlException ace) { return new Properties(); } } Property changes on: trunk/jython/tests/modjy ___________________________________________________________________ Added: svn:ignore + build Modified: trunk/jython/tests/modjy/build.xml =================================================================== --- trunk/jython/tests/modjy/build.xml 2009-06-21 22:19:53 UTC (rev 6489) +++ trunk/jython/tests/modjy/build.xml 2009-06-22 06:32:34 UTC (rev 6490) @@ -12,16 +12,17 @@ <!-- Jython properties --> - <property name="jython_home" location="${env.JYTHON_HOME}"/> + <property name="jython_home" location="${env.JYTHON_HOME}"/> <property name="jython_jar" value="jython-dev.jar"/> <property name="jython_jar_path" location="${jython_home}/${jython_jar}"/> <property name="jython_cachedir" location="${jython_home}/cachedir"/> + <property name="mockrunner_home" location="${env.MOCKRUNNER_HOME}"/> <target name="init"> - <available property="jython.home.set" file="${env.JYTHON_HOME}" /> - <fail unless="jython.home.set" message="JYTHON_HOME not set" /> - <available property="mockrunner.home.set" file="${env.MOCKRUNNER_HOME}" /> - <fail unless="mockrunner.home.set" message="MOCKRUNNER_HOME not set" /> + <available property="jython_home.exists" file="${jython_home}" /> + <fail unless="jython_home.exists" message="jython_home, ${jython_home}, doesn't exist" /> + <available property="mockrunner_home.exists" file="${mockrunner_home}" /> + <fail unless="mockrunner_home.exists" message="mockrunner_home, ${mockrunner_home}, doesn't exist" /> <!-- Create the build directory structure used by compile --> <mkdir dir="${build}"/> </target> @@ -35,12 +36,7 @@ <target name="do_test" depends="init" description="Run unit tests against a single jdk/servlet combo"> <echo message="Running tests against JDK ${jdk_version}, Servlet ${servlet_version}"/> - <echo message="Clearing jython package cache located at ${jython_home}/cachedir"/> - <delete quiet="true"> - <fileset dir="${jython_cachedir}"/> - </delete> - <property name="mockrunner_home" value="${env.MOCKRUNNER_HOME}"/> <property name="mockrunner_jar" location="${mockrunner_home}/jar"/> <property name="mockrunner_lib" location="${mockrunner_home}/lib/jdk${jdk_version}/${servlet_version}"/> @@ -57,15 +53,13 @@ srcdir="${test_src}" destdir="${build}" classpathref="test.classpath" - debug="on" - /> - - <java - classname="com.xhaus.modjy.ModjyTestBase" - dir="." - fork="yes" - classpathref="test.classpath" - /> + debug="on" + /> + <java classname="com.xhaus.modjy.ModjyTestBase" dir="." fork="yes" + classpathref="test.classpath"> + <sysproperty key="JYTHON_HOME" value="${jython_home}"/> + <sysproperty key="python.cachedir.skip" value="true"/> + </java> </target> <target name="test"> Modified: trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java =================================================================== --- trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java 2009-06-21 22:19:53 UTC (rev 6489) +++ trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java 2009-06-22 06:32:34 UTC (rev 6490) @@ -1,35 +1,27 @@ /*### # -# Copyright Alan Kennedy. -# +# Copyright Alan Kennedy. +# # You may contact the copyright holder at this uri: -# +# # http://www.xhaus.com/contact/modjy -# +# # The licence under which this code is released is the Apache License v2.0. -# +# # The terms and conditions of this license are listed in a file contained # in the distribution that also contained this file, under the name # LICENSE.txt. -# +# # You may also read a copy of the license at the following web address. -# +# # http://modjy.xhaus.com/LICENSE.txt # ###*/ package com.xhaus.modjy; -import java.io.File; - -import java.util.Map; -import java.util.Iterator; - import junit.framework.*; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServlet; - import com.mockrunner.servlet.BasicServletTestCaseAdapter; import com.mockrunner.mock.web.WebMockObjectFactory; import com.mockrunner.mock.web.MockServletConfig; @@ -37,16 +29,16 @@ import com.mockrunner.mock.web.MockHttpServletRequest; import com.mockrunner.mock.web.MockHttpServletResponse; -import org.jdom.Element; import org.jdom.output.XMLOutputter; import org.python.core.PyObject; +import org.python.util.PyServletTest; import org.python.util.PythonInterpreter; import com.xhaus.modjy.ModjyJServlet; /** - * + * */ public class ModjyTestBase extends BasicServletTestCaseAdapter @@ -226,7 +218,7 @@ throws Exception { super.setUp(); - String jythonHome = System.getenv("JYTHON_HOME"); + String jythonHome = System.getProperty("JYTHON_HOME"); setRealPath(jythonHome, jythonHome); setRealPath("/WEB-INF/"+LIB_PYTHON_DIR, LIB_PYTHON_TEST_PATH); setRealPath("/WEB-INF/lib/modjy.jar", "../modjy.jar"); @@ -267,7 +259,7 @@ baseSetUp(); createServlet(); doGet(); - String result = new XMLOutputter().outputString(getOutputAsJDOMDocument()); + new XMLOutputter().outputString(getOutputAsJDOMDocument()); } public static void main(String args[]) @@ -281,6 +273,7 @@ suite.addTestSuite(ModjyTestReturnIterable.class); suite.addTestSuite(ModjyTestWebInf.class); suite.addTestSuite(ModjyTestWSGIStreams.class); + suite.addTestSuite(PyServletTest.class); junit.textui.TestRunner.run(suite); } Added: trunk/jython/tests/modjy/java/org/python/util/PyServletTest.java =================================================================== --- trunk/jython/tests/modjy/java/org/python/util/PyServletTest.java (rev 0) +++ trunk/jython/tests/modjy/java/org/python/util/PyServletTest.java 2009-06-22 06:32:34 UTC (rev 6490) @@ -0,0 +1,88 @@ +package org.python.util; + +import javax.servlet.ServletException; + +import org.python.core.PyFile; +import com.mockrunner.base.NestedApplicationException; +import com.mockrunner.mock.web.MockServletConfig; +import com.mockrunner.mock.web.MockServletContext; +import com.mockrunner.mock.web.WebMockObjectFactory; +import com.mockrunner.servlet.BasicServletTestCaseAdapter; + +public class PyServletTest extends BasicServletTestCaseAdapter { + public void testGet() { + assertEquals("Basic text response", doGetAndRead("basic")); + } + + public void testNoCallable() { + try { + doGetAndRead("empty"); + fail("Using an empty file for PyServlet should raise a ServletException"); + } catch (NestedApplicationException e) { + assertTrue(e.getRootCause() instanceof ServletException); + } + } + + public void testReload() { + String originalBasic = readTestFile("basic"); + try { + testGet(); + writeToTestFile("basic", readTestFile("updated_basic")); + assertEquals("Updated text response", doGetAndRead("basic")); + } finally { + writeToTestFile("basic", originalBasic); + } + } + + public void testInstanceCaching() { + assertEquals("1", doGetAndRead("increment")); + assertEquals("2", doGetAndRead("increment")); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + MockServletConfig cfg = getWebMockObjectFactory().getMockServletConfig(); + cfg.setInitParameter("python.home", System.getProperty("JYTHON_HOME")); + createServlet(PyServlet.class); + } + + private String doGetAndRead(String testName) { + getWebMockObjectFactory().getMockRequest().setServletPath(getTestPath(testName)); + doGet(); + String result = getOutput(); + clearOutput(); + return result; + } + + private String getTestPath(String testName) { + return "/test/pyservlet/" + testName + ".py"; + } + + private String readTestFile(String testName) { + PyFile in = new PyFile(basePath + getTestPath(testName), "r", 4192); + String result = in.read().toString(); + return result; + } + + private void writeToTestFile(String testName, String newContents) { + PyFile out = new PyFile(basePath + getTestPath(testName), "w", 4192); + out.write(newContents); + out.close(); + } + + @Override + protected WebMockObjectFactory createWebMockObjectFactory() { + return new WebMockObjectFactory() { + @Override public MockServletContext createMockServletContext() { + return new MockServletContext() { + @Override public synchronized String getRealPath(String path) { + return basePath + path; + } + }; + } + }; + } + + private String basePath = System.getProperty("JYTHON_HOME") + "/Lib"; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |