From: <cg...@us...> - 2009-06-22 08:43:10
|
Revision: 6493 http://jython.svn.sourceforge.net/jython/?rev=6493&view=rev Author: cgroves Date: 2009-06-22 08:43:07 +0000 (Mon, 22 Jun 2009) Log Message: ----------- Windows line endings to unix, tabs to spaces, unused import removal, and general coding standard conformity. Modified Paths: -------------- trunk/jython/src/com/xhaus/modjy/ModjyJServlet.java trunk/jython/tests/modjy/build.xml trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestAppInvocation.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestContentHeaders.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestEnviron.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestHeaders.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestReturnIterable.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestWSGIStreams.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestWebInf.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestWriteCallable.java Modified: trunk/jython/src/com/xhaus/modjy/ModjyJServlet.java =================================================================== --- trunk/jython/src/com/xhaus/modjy/ModjyJServlet.java 2009-06-22 08:27:10 UTC (rev 6492) +++ trunk/jython/src/com/xhaus/modjy/ModjyJServlet.java 2009-06-22 08:43:07 UTC (rev 6493) @@ -1,193 +1,201 @@ -/*### -# -# 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.*; -import java.util.*; -import javax.servlet.*; -import javax.servlet.http.*; -import org.python.core.*; -import org.python.util.*; - -public class ModjyJServlet extends HttpServlet -{ - - protected final static String MODJY_PYTHON_CLASSNAME = "modjy_servlet"; - protected final static String LIB_PYTHON = "/WEB-INF/lib-python"; - protected final static String PTH_FILE_EXTENSION = ".pth"; - - protected PythonInterpreter interp; - protected HttpServlet modjyServlet; - - /** - * Read configuration - * 1. Both context and servlet parameters are included in the set, - * so that the definition of some parameters (e.g python.*) can be shared - * between multiple WSGI servlets. - * 2. servlet params take precedence over context parameters - */ - - protected Properties readConfiguration ( ) - { - Properties props = new Properties(); - // Context parameters - ServletContext context = getServletContext(); - Enumeration e = context.getInitParameterNames(); - while (e.hasMoreElements()) - { - String name = (String) e.nextElement(); - props.put(name, context.getInitParameter(name)); - } - // Servlet parameters override context parameters - e = getInitParameterNames(); - while (e.hasMoreElements()) - { - String name = (String) e.nextElement(); - props.put(name, getInitParameter(name)); - } - return props; - } - - /** - * Initialise the modjy servlet. - * 1. Read the configuration - * 2. Initialise the jython runtime - * 3. Setup, in relation to the J2EE servlet environment - * 4. Create the jython-implemented servlet - * 5. Initialise the jython-implemented servlet - */ - - public void init ( ) - throws ServletException - { - try - { - Properties props = readConfiguration(); - PythonInterpreter.initialize(System.getProperties(), props, new String[0]); - PySystemState systemState = new PySystemState(); - interp = new PythonInterpreter(null, systemState); - setupEnvironment(interp, props, systemState); - try - { interp.exec("from modjy.modjy import "+MODJY_PYTHON_CLASSNAME); } - catch (PyException ix) - { throw new ServletException("Unable to import '"+MODJY_PYTHON_CLASSNAME+ - "': maybe you need to set the 'python.home' parameter?", ix);} - PyObject pyServlet = ((PyType)interp.get(MODJY_PYTHON_CLASSNAME)).__call__(); - Object temp = pyServlet.__tojava__(HttpServlet.class); - if (temp == Py.NoConversion) - throw new ServletException("Corrupted modjy file: cannot find definition of '"+MODJY_PYTHON_CLASSNAME+"' class"); - modjyServlet = (HttpServlet) temp; - modjyServlet.init(this); - } - catch (PyException pyx) - { - throw new ServletException("Exception creating modjy servlet: " + pyx.toString(), pyx); - } - } - - /** - * Actually service the incoming request. - * Simply delegate to the jython servlet. - * - * @param request - The incoming HttpServletRequest - * @param response - The outgoing HttpServletResponse - */ - - public void service ( HttpServletRequest req, HttpServletResponse resp ) - throws ServletException, IOException - { - modjyServlet.service(req, resp); - } - - /** - * Setup the modjy environment, i.e. - * 1. Find the location of the modjy.jar file and add it to sys.path - * 2. Process the WEB-INF/lib-python directory, if it exists - * - * @param interp - The PythinInterpreter used to service requests - * @param props - The properties from which config options are found - * @param systemState - The PySystemState corresponding to the interpreter servicing requests - * @returns A String giving the path to the modjy.jar file (which is used only for error reporting) - */ - - protected void setupEnvironment(PythonInterpreter interp, Properties props, PySystemState systemState) - { - processPythonLib(interp, systemState); - } - - /** - * Do all processing in relation to the lib-python subdirectory of WEB-INF - * - * @param interp - The PythinInterpreter used to service requests - * @param systemState - The PySystemState whose path should be updated - */ - - protected void processPythonLib(PythonInterpreter interp, PySystemState systemState) - { - // Add the lib-python directory to sys.path - String pythonLibPath = getServletContext().getRealPath(LIB_PYTHON); - if (pythonLibPath == null) - return; - File pythonLib = new File(pythonLibPath); - if (!pythonLib.exists()) - return; - systemState.path.append(new PyString(pythonLibPath)); - // Now check for .pth files in lib-python and process each one - String[] libPythonContents = pythonLib.list(); - for (int ix = 0 ; ix < libPythonContents.length ; ix++) - if (libPythonContents[ix].endsWith(PTH_FILE_EXTENSION)) - processPthFile(interp, systemState, pythonLibPath, libPythonContents[ix]); - } - - /** - * Process an individual file .pth file in the lib-python directory - * - * @param systemState - The PySystemState whose path should be updated - * @param pythonLibPath - The actual path to the lib-python directory - * @param pthFilename - The PySystemState whose path should be updated - */ - - protected void processPthFile(PythonInterpreter interp, PySystemState systemState, String pythonLibPath, String pthFilename) - { - try - { - LineNumberReader lineReader = new LineNumberReader(new FileReader(new File(pythonLibPath, pthFilename))); - String line; - while ((line = lineReader.readLine()) != null) - { - line = line.trim(); - if (line.length() == 0) - continue; - if (line.startsWith("#")) - continue; - if (line.startsWith("import")) - interp.exec(line); - File archiveFile = new File(pythonLibPath, line); - String archiveRealpath = archiveFile.getAbsolutePath(); - systemState.path.append(new PyString(archiveRealpath)); - } - } - catch (IOException iox) - { - System.err.println("IOException: " + iox.toString()); - } - } -} +/*### +# +# 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.io.FileReader; +import java.io.IOException; +import java.io.LineNumberReader; +import java.util.Enumeration; +import java.util.Properties; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.python.core.Py; +import org.python.core.PyException; +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.core.PySystemState; +import org.python.core.PyType; +import org.python.util.PythonInterpreter; + +public class ModjyJServlet extends HttpServlet { + + protected final static String MODJY_PYTHON_CLASSNAME = "modjy_servlet"; + + protected final static String LIB_PYTHON = "/WEB-INF/lib-python"; + + protected final static String PTH_FILE_EXTENSION = ".pth"; + + protected PythonInterpreter interp; + + protected HttpServlet modjyServlet; + + /** + * Read configuration 1. Both context and servlet parameters are included in the set, so that + * the definition of some parameters (e.g python.*) can be shared between multiple WSGI + * servlets. 2. servlet params take precedence over context parameters + */ + protected Properties readConfiguration() { + Properties props = new Properties(); + // Context parameters + ServletContext context = getServletContext(); + Enumeration<?> e = context.getInitParameterNames(); + while (e.hasMoreElements()) { + String name = (String)e.nextElement(); + props.put(name, context.getInitParameter(name)); + } + // Servlet parameters override context parameters + e = getInitParameterNames(); + while (e.hasMoreElements()) { + String name = (String)e.nextElement(); + props.put(name, getInitParameter(name)); + } + return props; + } + + /** + * Initialise the modjy servlet. 1. Read the configuration 2. Initialise the jython runtime 3. + * Setup, in relation to the J2EE servlet environment 4. Create the jython-implemented servlet + * 5. Initialise the jython-implemented servlet + */ + @Override + public void init() throws ServletException { + try { + Properties props = readConfiguration(); + PythonInterpreter.initialize(System.getProperties(), props, new String[0]); + PySystemState systemState = new PySystemState(); + interp = new PythonInterpreter(null, systemState); + setupEnvironment(interp, props, systemState); + try { + interp.exec("from modjy.modjy import " + MODJY_PYTHON_CLASSNAME); + } catch (PyException ix) { + throw new ServletException("Unable to import '" + MODJY_PYTHON_CLASSNAME + + "': maybe you need to set the 'python.home' parameter?", ix); + } + PyObject pyServlet = ((PyType)interp.get(MODJY_PYTHON_CLASSNAME)).__call__(); + Object temp = pyServlet.__tojava__(HttpServlet.class); + if (temp == Py.NoConversion) + throw new ServletException("Corrupted modjy file: cannot find definition of '" + + MODJY_PYTHON_CLASSNAME + "' class"); + modjyServlet = (HttpServlet)temp; + modjyServlet.init(this); + } catch (PyException pyx) { + throw new ServletException("Exception creating modjy servlet: " + pyx.toString(), pyx); + } + } + + /** + * Actually service the incoming request. Simply delegate to the jython servlet. + * + * @param request + * - The incoming HttpServletRequest + * @param response + * - The outgoing HttpServletResponse + */ + @Override + public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, + IOException { + modjyServlet.service(req, resp); + } + + /** + * Setup the modjy environment, i.e. 1. Find the location of the modjy.jar file and add it to + * sys.path 2. Process the WEB-INF/lib-python directory, if it exists + * + * @param interp + * - The PythinInterpreter used to service requests + * @param props + * - The properties from which config options are found + * @param systemState + * - The PySystemState corresponding to the interpreter servicing requests + * @returns A String giving the path to the modjy.jar file (which is used only for error + * reporting) + */ + protected void setupEnvironment(PythonInterpreter interp, + Properties props, + PySystemState systemState) { + processPythonLib(interp, systemState); + } + + /** + * Do all processing in relation to the lib-python subdirectory of WEB-INF + * + * @param interp + * - The PythinInterpreter used to service requests + * @param systemState + * - The PySystemState whose path should be updated + */ + protected void processPythonLib(PythonInterpreter interp, PySystemState systemState) { + // Add the lib-python directory to sys.path + String pythonLibPath = getServletContext().getRealPath(LIB_PYTHON); + if (pythonLibPath == null) + return; + File pythonLib = new File(pythonLibPath); + if (!pythonLib.exists()) + return; + systemState.path.append(new PyString(pythonLibPath)); + // Now check for .pth files in lib-python and process each one + String[] libPythonContents = pythonLib.list(); + for (String libPythonContent : libPythonContents) + if (libPythonContent.endsWith(PTH_FILE_EXTENSION)) + processPthFile(interp, systemState, pythonLibPath, libPythonContent); + } + + /** + * Process an individual file .pth file in the lib-python directory + * + * @param systemState + * - The PySystemState whose path should be updated + * @param pythonLibPath + * - The actual path to the lib-python directory + * @param pthFilename + * - The PySystemState whose path should be updated + */ + protected void processPthFile(PythonInterpreter interp, + PySystemState systemState, + String pythonLibPath, + String pthFilename) { + try { + LineNumberReader lineReader = new LineNumberReader(new FileReader(new File(pythonLibPath, + pthFilename))); + String line; + while ((line = lineReader.readLine()) != null) { + line = line.trim(); + if (line.length() == 0) + continue; + if (line.startsWith("#")) + continue; + if (line.startsWith("import")) + interp.exec(line); + File archiveFile = new File(pythonLibPath, line); + String archiveRealpath = archiveFile.getAbsolutePath(); + systemState.path.append(new PyString(archiveRealpath)); + } + } catch (IOException iox) { + System.err.println("IOException: " + iox.toString()); + } + } +} Modified: trunk/jython/tests/modjy/build.xml =================================================================== --- trunk/jython/tests/modjy/build.xml 2009-06-22 08:27:10 UTC (rev 6492) +++ trunk/jython/tests/modjy/build.xml 2009-06-22 08:43:07 UTC (rev 6493) @@ -1,103 +1,97 @@ -<project name="modjy" default="test"> - - <description>Modjy test build.xml</description> - - <!-- set global properties for this build --> - - <property name="test_src" location="java"/> - <property name="build" location="build"/> - - <!-- Import the environment --> - <property environment="env"/> - - <!-- Jython properties --> - - <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.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> - - <target name="clean" description="clean up" > - <!-- Delete the ${build} and ${dist} directory trees --> - <delete dir="${build}"/> - </target> - - <!-- Now testing related targets --> - - <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}"/> - - <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}"/> - - <path id="test.classpath"> - <pathelement path="${build}"/> - <pathelement path="${jython_jar_path}"/> - <fileset dir="${jython_home}/javalib" includes="**/*.jar"/> - <fileset dir="${mockrunner_jar}" includes="**/*.jar"/> - <fileset dir="${mockrunner_lib}" includes="**/*.jar"/> - </path> - - <javac - srcdir="${test_src}" - destdir="${build}" - 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"> - <antcall target="do_test"> - <param name="jdk_version" value="1.5"/> - <param name="servlet_version" value="j2ee1.3"/> - </antcall> - </target> - - <target name="test_java_15" depends="clean"> - <antcall target="do_test"> - <param name="jdk_version" value="1.5"/> - <param name="servlet_version" value="j2ee1.3"/> - </antcall> - <antcall target="do_test"> - <param name="jdk_version" value="1.5"/> - <param name="servlet_version" value="j2ee1.4"/> - </antcall> - <antcall target="do_test"> - <param name="jdk_version" value="1.5"/> - <param name="servlet_version" value="jee5"/> - </antcall> - </target> - - <target name="test_java_16" depends="clean"> - <antcall target="do_test"> - <param name="jdk_version" value="1.6"/> - <param name="servlet_version" value="j2ee1.3"/> - </antcall> - <antcall target="do_test"> - <param name="jdk_version" value="1.6"/> - <param name="servlet_version" value="j2ee1.4"/> - </antcall> - <antcall target="do_test"> - <param name="jdk_version" value="1.6"/> - <param name="servlet_version" value="jee5"/> - </antcall> - </target> - -</project> - +<project name="modjy" default="test"> + + <description>Modjy test build.xml</description> + + <!-- set global properties for this build --> + + <property name="test_src" location="java" /> + <property name="build" location="build" /> + + <!-- Import the environment --> + <property environment="env" /> + + <!-- Jython properties --> + + <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.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> + + <target name="clean" description="clean up"> + <!-- Delete the ${build} and ${dist} directory trees --> + <delete dir="${build}" /> + </target> + + <!-- Now testing related targets --> + + <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}" /> + + <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}" /> + + <path id="test.classpath"> + <pathelement path="${build}" /> + <pathelement path="${jython_jar_path}" /> + <fileset dir="${jython_home}/javalib" includes="**/*.jar" /> + <fileset dir="${mockrunner_jar}" includes="**/*.jar" /> + <fileset dir="${mockrunner_lib}" includes="**/*.jar" /> + </path> + + <javac srcdir="${test_src}" destdir="${build}" 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"> + <antcall target="do_test"> + <param name="jdk_version" value="1.5" /> + <param name="servlet_version" value="j2ee1.3" /> + </antcall> + </target> + + <target name="test_java_15" depends="clean"> + <antcall target="do_test"> + <param name="jdk_version" value="1.5" /> + <param name="servlet_version" value="j2ee1.3" /> + </antcall> + <antcall target="do_test"> + <param name="jdk_version" value="1.5" /> + <param name="servlet_version" value="j2ee1.4" /> + </antcall> + <antcall target="do_test"> + <param name="jdk_version" value="1.5" /> + <param name="servlet_version" value="jee5" /> + </antcall> + </target> + + <target name="test_java_16" depends="clean"> + <antcall target="do_test"> + <param name="jdk_version" value="1.6" /> + <param name="servlet_version" value="j2ee1.3" /> + </antcall> + <antcall target="do_test"> + <param name="jdk_version" value="1.6" /> + <param name="servlet_version" value="j2ee1.4" /> + </antcall> + <antcall target="do_test"> + <param name="jdk_version" value="1.6" /> + <param name="servlet_version" value="jee5" /> + </antcall> + </target> + +</project> + Modified: trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestAppInvocation.java =================================================================== --- trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestAppInvocation.java 2009-06-22 08:27:10 UTC (rev 6492) +++ trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestAppInvocation.java 2009-06-22 08:43:07 UTC (rev 6493) @@ -1,224 +1,186 @@ -/*### -# -# 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 org.python.core.PyDictionary; -import org.python.core.PyInteger; -import org.python.core.PyObject; -import org.python.core.PyString; -import org.python.core.PyTuple; - -public class ModjyTestAppInvocation extends ModjyTestBase -{ - - protected void appInvocationTestSetUp() - throws Exception - { - baseSetUp(); - setAppDir(""); - setAppFile(""); - setAppName(""); - setAppImportable(""); - } - - String[] importablepathElements = new String[] { - "mock_framework", - "web", - "handlers", - "wsgi_handlers", - }; - - public void testRelativeDirectory ( ) - throws Exception - { - baseSetUp(); - setRealPath("/test_apps_dir", "test_apps_dir"); - setAppDir("$/test_apps_dir"); - setAppFile("simple_app.py"); - createServlet(); - doGet(); - String result = getOutput(); - assertEquals("Hello World!", result); - } - - public String setupAppImport ( String appCallableName ) - throws Exception - { - StringBuffer filePathBuffer = new StringBuffer(); - StringBuffer importPath = new StringBuffer(); - for (int ix = 0 ; ix < importablepathElements.length ; ix++) - { - String resourcePath; - String filePath; - filePathBuffer.append(importablepathElements[ix]); - resourcePath = "/WEB-INF/"+LIB_PYTHON_DIR+"/"+filePathBuffer.toString(); - filePath = LIB_PYTHON_TEST_PATH+"/"+filePathBuffer.toString(); - setRealPath(resourcePath, filePath); - filePathBuffer.append("/"); - resourcePath = "/WEB-INF/"+LIB_PYTHON_DIR+"/"+filePathBuffer.toString()+"__init__.py"; - filePath = LIB_PYTHON_TEST_PATH+"/"+filePathBuffer.toString()+"__init__.py"; - setRealPath(resourcePath, filePath); - importPath.append(importablepathElements[ix]); - importPath.append("."); - } - importPath.append(appCallableName); - return importPath.toString(); - } - - public void testAppImportCallable ( ) - throws Exception - { - appInvocationTestSetUp(); - String importableName = setupAppImport("WSGIHandlerFunction"); - setAppImportable(importableName); - createServlet(); - doGet(); - String result = getOutput(); - assertEquals("WSGIHandlerFunction called.", result); - } - - public void testAppImportBadInstantiable ( ) - throws Exception - { - appInvocationTestSetUp(); - String importableName = setupAppImport("WSGIHandlerClass"); - setAppImportable(importableName); - createServlet(); - doGet(); - assertEquals("Status code != 500: ServerError, =='"+getStatus()+"'", 500, getStatus()); - } - - public void testAppImportInstantiable ( ) - throws Exception - { - appInvocationTestSetUp(); - String importableName = setupAppImport("WSGIHandlerClass()"); - setAppImportable(importableName); - createServlet(); - doGet(); - String result = getOutput(); - assertEquals("__call__ counter = 0", result); - } - - public void testAppImportInstantiableCached ( ) - throws Exception - { - appInvocationTestSetUp(); - setInitParameter("cache_callables", "1"); - String importableName = setupAppImport("WSGIHandlerClass()"); - setAppImportable(importableName); - createServlet(); - doGet(); - String result = getOutput(); - assertEquals("__call__ counter = 0", result); - clearOutput(); - doGet(); - result = getOutput(); - assertEquals("__call__ counter = 1", result); - } - - public void testAppImportInstantiableNotCached ( ) - throws Exception - { - appInvocationTestSetUp(); - setInitParameter("cache_callables", "0"); - String importableName = setupAppImport("WSGIHandlerClass()"); - setAppImportable(importableName); - createServlet(); - doGet(); - String result = getOutput(); - assertEquals("__call__ counter = 0", result); - clearOutput(); - doGet(); - result = getOutput(); - assertEquals("__call__ counter = 0", result); - } - - public void testAppImportInstantiableMethod ( ) - throws Exception - { - appInvocationTestSetUp(); - String importableName = setupAppImport("WSGIHandlerClass().handler_fn"); - setAppImportable(importableName); - createServlet(); - doGet(); - String result = getOutput(); - assertEquals("handler_fn counter = 0", result); - } - - public void testAppImportInstantiableBadMethod ( ) - throws Exception - { - appInvocationTestSetUp(); - String importableName = setupAppImport("WSGIHandlerClass().handler_fn.fn_attr"); - setAppImportable(importableName); - createServlet(); - doGet(); - assertEquals("Status code != 500: ServerError, =='"+getStatus()+"'", 500, getStatus()); - } - - public void testAppImportInstantiableMethodCached ( ) - throws Exception - { - appInvocationTestSetUp(); - setInitParameter("cache_callables", "1"); - String importableName = setupAppImport("WSGIHandlerClass().handler_fn"); - setAppImportable(importableName); - createServlet(); - doGet(); - String result = getOutput(); - assertEquals("handler_fn counter = 0", result); - clearOutput(); - doGet(); - result = getOutput(); - assertEquals("handler_fn counter = 1", result); - } - - public void testAppImportInstantiableMethodNotCached ( ) - throws Exception - { - appInvocationTestSetUp(); - setInitParameter("cache_callables", "0"); - String importableName = setupAppImport("WSGIHandlerClass().handler_fn"); - setAppImportable(importableName); - createServlet(); - doGet(); - String result = getOutput(); - assertEquals("handler_fn counter = 0", result); - clearOutput(); - doGet(); - result = getOutput(); - assertEquals("handler_fn counter = 0", result); - } - - public void testBadAppImport() - throws Exception - { - appInvocationTestSetUp(); - setAppImportable("never.existed"); - createServlet(); - doGet(); - assertEquals("Status code != 500: ServerError, =='"+getStatus()+"'", 500, getStatus()); - } - -} +/*### +# +# 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; + +public class ModjyTestAppInvocation extends ModjyTestBase { + + protected void appInvocationTestSetUp() throws Exception { + baseSetUp(); + setAppDir(""); + setAppFile(""); + setAppName(""); + setAppImportable(""); + } + + String[] importablepathElements = new String[] {"mock_framework", + "web", + "handlers", + "wsgi_handlers",}; + + public void testRelativeDirectory() throws Exception { + baseSetUp(); + setRealPath("/test_apps_dir", "test_apps_dir"); + setAppDir("$/test_apps_dir"); + setAppFile("simple_app.py"); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("Hello World!", result); + } + + public String setupAppImport(String appCallableName) throws Exception { + StringBuffer filePathBuffer = new StringBuffer(); + StringBuffer importPath = new StringBuffer(); + for (String importablepathElement : importablepathElements) { + String resourcePath; + String filePath; + filePathBuffer.append(importablepathElement); + resourcePath = "/WEB-INF/" + LIB_PYTHON_DIR + "/" + filePathBuffer.toString(); + filePath = LIB_PYTHON_TEST_PATH + "/" + filePathBuffer.toString(); + setRealPath(resourcePath, filePath); + filePathBuffer.append("/"); + resourcePath = "/WEB-INF/" + LIB_PYTHON_DIR + "/" + filePathBuffer.toString() + + "__init__.py"; + filePath = LIB_PYTHON_TEST_PATH + "/" + filePathBuffer.toString() + "__init__.py"; + setRealPath(resourcePath, filePath); + importPath.append(importablepathElement); + importPath.append("."); + } + importPath.append(appCallableName); + return importPath.toString(); + } + + public void testAppImportCallable() throws Exception { + appInvocationTestSetUp(); + String importableName = setupAppImport("WSGIHandlerFunction"); + setAppImportable(importableName); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("WSGIHandlerFunction called.", result); + } + + public void testAppImportBadInstantiable() throws Exception { + appInvocationTestSetUp(); + String importableName = setupAppImport("WSGIHandlerClass"); + setAppImportable(importableName); + createServlet(); + doGet(); + assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); + } + + public void testAppImportInstantiable() throws Exception { + appInvocationTestSetUp(); + String importableName = setupAppImport("WSGIHandlerClass()"); + setAppImportable(importableName); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("__call__ counter = 0", result); + } + + public void testAppImportInstantiableCached() throws Exception { + appInvocationTestSetUp(); + setInitParameter("cache_callables", "1"); + String importableName = setupAppImport("WSGIHandlerClass()"); + setAppImportable(importableName); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("__call__ counter = 0", result); + clearOutput(); + doGet(); + result = getOutput(); + assertEquals("__call__ counter = 1", result); + } + + public void testAppImportInstantiableNotCached() throws Exception { + appInvocationTestSetUp(); + setInitParameter("cache_callables", "0"); + String importableName = setupAppImport("WSGIHandlerClass()"); + setAppImportable(importableName); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("__call__ counter = 0", result); + clearOutput(); + doGet(); + result = getOutput(); + assertEquals("__call__ counter = 0", result); + } + + public void testAppImportInstantiableMethod() throws Exception { + appInvocationTestSetUp(); + String importableName = setupAppImport("WSGIHandlerClass().handler_fn"); + setAppImportable(importableName); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("handler_fn counter = 0", result); + } + + public void testAppImportInstantiableBadMethod() throws Exception { + appInvocationTestSetUp(); + String importableName = setupAppImport("WSGIHandlerClass().handler_fn.fn_attr"); + setAppImportable(importableName); + createServlet(); + doGet(); + assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); + } + + public void testAppImportInstantiableMethodCached() throws Exception { + appInvocationTestSetUp(); + setInitParameter("cache_callables", "1"); + String importableName = setupAppImport("WSGIHandlerClass().handler_fn"); + setAppImportable(importableName); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("handler_fn counter = 0", result); + clearOutput(); + doGet(); + result = getOutput(); + assertEquals("handler_fn counter = 1", result); + } + + public void testAppImportInstantiableMethodNotCached() throws Exception { + appInvocationTestSetUp(); + setInitParameter("cache_callables", "0"); + String importableName = setupAppImport("WSGIHandlerClass().handler_fn"); + setAppImportable(importableName); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("handler_fn counter = 0", result); + clearOutput(); + doGet(); + result = getOutput(); + assertEquals("handler_fn counter = 0", result); + } + + public void testBadAppImport() throws Exception { + appInvocationTestSetUp(); + setAppImportable("never.existed"); + createServlet(); + doGet(); + assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); + } +} Modified: trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java =================================================================== --- trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java 2009-06-22 08:27:10 UTC (rev 6492) +++ trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java 2009-06-22 08:43:07 UTC (rev 6493) @@ -1,279 +1,247 @@ -/*### -# -# 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 junit.framework.TestSuite; - -import org.jdom.output.XMLOutputter; -import org.python.core.PyObject; -import org.python.util.PyFilterTest; -import org.python.util.PyServletTest; -import org.python.util.PythonInterpreter; - -import com.mockrunner.mock.web.MockHttpServletRequest; -import com.mockrunner.mock.web.MockHttpServletResponse; -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 ModjyTestBase extends BasicServletTestCaseAdapter -{ - - final static String DEFAULT_APP_DIR = "test_apps_dir"; - final static String LIB_PYTHON_DIR = "lib-python"; - final static String LIB_PYTHON_TEST_PATH = "lib_python_folder"; - final static String DEFAULT_APP_FILE = "simple_app.py"; - final static String DEFAULT_APP_NAME = "simple_app"; - - public WebMockObjectFactory factory; - public MockServletConfig servletConfig; - public MockServletContext servletContext; - - public WebMockObjectFactory getFactory () - { - if (factory == null) - factory = getWebMockObjectFactory(); - return factory; - } - - public MockServletConfig getConfig () - { - if (servletConfig == null) - servletConfig = getFactory().getMockServletConfig(); - return servletConfig; - } - - public MockServletContext getContext () - { - if (servletContext == null) - servletContext = getFactory().getMockServletContext(); - return servletContext; - } - -// public void dumpContextRealPaths ( ) -// { -// Map pathMap = ((LoggingMockServletContext)getContext()).actualPaths; -// Iterator it = pathMap.keySet().iterator(); -// while (it.hasNext()) -// { -// String pathName = (String) it.next(); -// System.out.println("Path '"+pathName+"'-->'"+pathMap.get(pathName)+"'"); -// } -// } - - public void setInitParameter ( String name, String value ) - { - getConfig().setInitParameter(name, value); - } - - public void setRealPath ( String source, String target ) - { - getContext().setRealPath(source, target); - } - - public void addHeader(String headerName, String headerValue) - { - MockHttpServletRequest request = (MockHttpServletRequest) getFactory().getWrappedRequest(); - request.addHeader(headerName, headerValue); - getFactory().addRequestWrapper(request); - } - - public void setBodyContent(String content) - { - MockHttpServletRequest request = (MockHttpServletRequest) getFactory().getWrappedRequest(); - request.setBodyContent(content); - getFactory().addRequestWrapper(request); - } - - public void setServletContextPath(String path) - { - MockHttpServletRequest request = (MockHttpServletRequest) getFactory().getWrappedRequest(); - request.setContextPath(path); - getFactory().addRequestWrapper(request); - } - - public void setServletPath(String path) - { - MockHttpServletRequest request = (MockHttpServletRequest) getFactory().getWrappedRequest(); - request.setServletPath(path); - getFactory().addRequestWrapper(request); - } - - public void setRequestURI(String uri) - { - MockHttpServletRequest request = (MockHttpServletRequest) getFactory().getWrappedRequest(); - request.setRequestURI(uri); - getFactory().addRequestWrapper(request); - } - - public void setScheme(String scheme) - { - MockHttpServletRequest request = (MockHttpServletRequest) getFactory().getWrappedRequest(); - request.setScheme(scheme); - getFactory().addRequestWrapper(request); - } - - public void setPathInfo(String pathInfo) - { - MockHttpServletRequest request = (MockHttpServletRequest) getFactory().getWrappedRequest(); - request.setPathInfo(pathInfo); - getFactory().addRequestWrapper(request); - } - - public void setQueryString(String qString) - { - MockHttpServletRequest request = (MockHttpServletRequest) getFactory().getWrappedRequest(); - request.setQueryString(qString); - getFactory().addRequestWrapper(request); - } - - public void setProtocol(String protocol) - { - MockHttpServletRequest request = (MockHttpServletRequest) getFactory().getWrappedRequest(); - request.setProtocol(protocol); - getFactory().addRequestWrapper(request); - } - - public void setServerName(String name) - { - MockHttpServletRequest request = (MockHttpServletRequest) getFactory().getWrappedRequest(); - // Using setLocalName() here: See here for more: http://docs.sun.com/source/819-0077/J2EE.html - request.setLocalName(name); - getFactory().addRequestWrapper(request); - } - - public void setServerPort(int port) - { - MockHttpServletRequest request = (MockHttpServletRequest) getFactory().getWrappedRequest(); - request.setLocalPort(port); - getFactory().addRequestWrapper(request); - } - - public void setPythonHome(String app_dir) - { - setInitParameter("python.home", app_dir); - } - - public void setAppDir(String app_dir) - { - setInitParameter("app_directory", app_dir); - } - - public void setAppFile(String app_file) - { - setInitParameter("app_filename", app_file); - } - - public void setAppName(String app_name) - { - setInitParameter("app_callable_name", app_name); - } - - public void setAppImportable(String app_path) - { - setAppDir(""); - setAppFile(""); - setAppName(""); - setInitParameter("app_import_name", app_path); - } - - public MockHttpServletResponse getResponse() - { - MockHttpServletResponse response = (MockHttpServletResponse) getFactory().getWrappedResponse(); - return response; - } - - public int getStatus() - { - MockHttpServletResponse response = (MockHttpServletResponse) getFactory().getWrappedResponse(); - return response.getStatusCode(); - } - - protected void baseSetUp() - throws Exception - { - super.setUp(); - 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"); - setPythonHome(jythonHome); - setAppDir(DEFAULT_APP_DIR); - setAppFile(DEFAULT_APP_FILE); - setAppName(DEFAULT_APP_NAME); - setInitParameter("exc_handler", "testing"); -// dumpContextRealPaths(); - } - - protected PyObject evalPythonString(String pyString) - { - // Efficiency be damned: it's a testing phase - PythonInterpreter interp = new PythonInterpreter(); - try - { - return interp.eval(pyString); - } - catch (Exception x) - { - System.err.println("Exception evaling '"+pyString+"': " + x); - return null; - } - } - - protected void createServlet() - { - createServlet(ModjyJServlet.class); - // Set zero content: this can be overridden later - setBodyContent(""); - clearOutput(); - } - - // Leave this here as a simple template for a test - public void testHelloWorld() throws Exception - { - baseSetUp(); - createServlet(); - doGet(); - new XMLOutputter().outputString(getOutputAsJDOMDocument()); - } - - public static void main(String args[]) - { - TestSuite suite = new TestSuite(); - suite.addTestSuite(ModjyTestBase.class); - suite.addTestSuite(ModjyTestAppInvocation.class); - suite.addTestSuite(ModjyTestEnviron.class); - suite.addTestSuite(ModjyTestHeaders.class); - suite.addTestSuite(ModjyTestContentHeaders.class); - suite.addTestSuite(ModjyTestReturnIterable.class); - suite.addTestSuite(ModjyTestWebInf.class); - suite.addTestSuite(ModjyTestWSGIStreams.class); - suite.addTestSuite(PyServletTest.class); - suite.addTestSuite(PyFilterTest.class); - junit.textui.TestRunner.run(suite); - } - -} +/*### +# +# 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 junit.framework.TestSuite; + +import org.jdom.output.XMLOutputter; +import org.python.core.PyObject; +import org.python.util.PyFilterTest; +import org.python.util.PyServletTest; +import org.python.util.PythonInterpreter; + +import com.mockrunner.mock.web.MockHttpServletRequest; +import com.mockrunner.mock.web.MockHttpServletResponse; +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 ModjyTestBase extends BasicServletTestCaseAdapter { + + final static String DEFAULT_APP_DIR = "test_apps_dir"; + + final static String LIB_PYTHON_DIR = "lib-python"; + + final static String LIB_PYTHON_TEST_PATH = "lib_python_folder"; + + final static String DEFAULT_APP_FILE = "simple_app.py"; + + final static String DEFAULT_APP_NAME = "simple_app"; + + public WebMockObjectFactory factory; + + public MockServletConfig servletConfig; + + public MockServletContext servletContext; + + public WebMockObjectFactory getFactory() { + if (factory == null) + factory = getWebMockObjectFactory(); + return factory; + } + + public MockServletConfig getConfig() { + if (servletConfig == null) + servletConfig = getFactory().getMockServletConfig(); + return servletConfig; + } + + public MockServletContext getContext() { + if (servletContext == null) + servletContext = getFactory().getMockServletContext(); + return servletContext; + } + +// public void dumpContextRealPaths ( ) +// { +// Map pathMap = ((LoggingMockServletContext)getContext()).actualPaths; +// Iterator it = pathMap.keySet().iterator(); +// while (it.hasNext()) +// { +// String pathName = (String) it.next(); +// System.out.println("Path '"+pathName+"'-->'"+pathMap.get(pathName)+"'"); +// } +// } + public void setInitParameter(String name, String value) { + getConfig().setInitParameter(name, value); + } + + public void setRealPath(String source, String target) { + getContext().setRealPath(source, target); + } + + public void addHeader(String headerName, String headerValue) { + MockHttpServletRequest request = (MockHttpServletRequest)getFactory().getWrappedRequest(); + request.addHeader(headerName, headerValue); + getFactory().addRequestWrapper(request); + } + + public void setBodyContent(String content) { + MockHttpServletRequest request = (MockHttpServletRequest)getFactory().getWrappedRequest(); + request.setBodyContent(content); + getFactory().addRequestWrapper(request); + } + + public void setServletContextPath(String path) { + MockHttpServletRequest request = (MockHttpServletRequest)getFactory().getWrappedRequest(); + request.setContextPath(path); + getFactory().addRequestWrapper(request); + } + + public void setServletPath(String path) { + MockHttpServletRequest request = (MockHttpServletRequest)getFactory().getWrappedRequest(); + request.setServletPath(path); + getFactory().addRequestWrapper(request); + } + + public void setRequestURI(String uri) { + MockHttpServletRequest request = (MockHttpServletRequest)getFactory().getWrappedRequest(); + request.setRequestURI(uri); + getFactory().addRequestWrapper(request); + } + + public void setScheme(String scheme) { + MockHttpServletRequest request = (MockHttpServletRequest)getFactory().getWrappedRequest(); + request.setScheme(scheme); + getFactory().addRequestWrapper(request); + } + + public void setPathInfo(String pathInfo) { + MockHttpServletRequest request = (MockHttpServletRequest)getFactory().getWrappedRequest(); + request.setPathInfo(pathInfo); + getFactory().addRequestWrapper(request); + } + + public void setQueryString(String qString) { + MockHttpServletRequest request = (MockHttpServletRequest)getFactory().getWrappedRequest(); + request.setQueryString(qString); + getFactory().addRequestWrapper(request); + } + + public void setProtocol(String protocol) { + MockHttpServletRequest request = (MockHttpServletRequest)getFactory().getWrappedRequest(); + request.setProtocol(protocol); + getFactory().addRequestWrapper(request); + } + + public void setServerName(String name) { + MockHttpServletRequest request = (MockHttpServletRequest)getFactory().getWrappedRequest(); + // Using setLocalName() here: See here for more: + // http://docs.sun.com/source/819-0077/J2EE.html + request.setLocalName(name); + getFactory().addRequestWrapper(request); + } + + public void setServerPort(int port) { + MockHttpServletRequest request = (MockHttpServletRequest)getFactory().getWrappedRequest(); + request.setLocalPort(port); + getFactory().addRequestWrapper(request); + } + + public void setPythonHome(String app_dir) { + setInitParameter("python.home", app_dir); + } + + public void setAppDir(String app_dir) { + setInitParameter("app_directory", app_dir); + } + + public void setAppFile(String app_file) { + setInitParameter("app_filename", app_file); + } + + public void setAppName(String app_name) { + setInitParameter("app_callable_name", app_name); + } + + public void setAppImportable(String app_path) { + setAppDir(""); + setAppFile(""); + setAppName(""); + setInitParameter("app_import_name", app_path); + } + + public MockHttpServletResponse getResponse() { + MockHttpServletResponse response = (MockHttpServletResponse)getFactory().getWrappedResponse(); + return response; + } + + public int getStatus() { + MockHttpServletResponse response = (MockHttpServletResponse)getFactory().getWrappedResponse(); + return response.getStatusCode(); + } + + protected void baseSetUp() throws Exception { + super.setUp(); + 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"); + setPythonHome(jythonHome); + setAppDir(DEFAULT_APP_DIR); + setAppFile(DEFAULT_APP_FILE); + setAppName(DEFAULT_APP_NAME); + setInitParameter("exc_handler", "testing"); +// dumpContextRealPaths(); + } + + protected PyObject evalPythonString(String pyString) { + // Efficiency be damned: it's a testing phase + PythonInterpreter interp = new PythonInterpreter(); + try { + return interp.eval(pyString); + } catch (Exception x) { + System.err.println("Exception evaling '" + pyString + "': " + x); + return null; + } + } + + protected void createServlet() { + createServlet(ModjyJServlet.class); + // Set zero content: this can be overridden later + setBodyContent(""); + clearOutput(); + } + + // Leave this here as a simple template for a test + public void testHelloWorld() throws Exception { + baseSetUp(); + createServlet(); + doGet(); + new XMLOutputter().outputString(getOutputAsJDOMDocument()); + } + + public static void main(String args[]) { + TestSuite suite = new TestSuite(); + suite.addTestSuite(ModjyTestBase.class); + suite.addTestSuite(ModjyTestAppInvocation.class); + suite.addTestSuite(ModjyTestEnviron.class); + suite.addTestSuite(ModjyTestHeaders.class); + suite.addTestSuite(ModjyTestContentHeaders.class); + suite.addTestSuite(ModjyTestReturnIterable.class); + suite.addTestSuite(ModjyTestWebInf.class); + suite.addTestSuite(ModjyTestWSGIStreams.class); + suite.addTestSuite(PyServletTest.class); + suite.addTestSuite(PyFilterTest.class); + junit.textui.TestRunner.run(suite); + } +} Modified: trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestContentHeaders.java =================================================================== --- trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestContentHeaders.java 2009-06-22 08:27:10 UTC (rev 6492) +++ trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestContentHeaders.java 2009-06-22 08:43:07 UTC (rev 6493) @@ -1,81 +1,65 @@ /*### # -# 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 com.mockrunner.base.NestedApplicationException; -import org.python.core.PyException; +public class ModjyTestContentHeaders extends ModjyTestBase { -public class ModjyTestContentHeaders extends ModjyTestBase -{ + // From: http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.5.1 + protected void contentHeaderTestSetUp() throws Exception { + baseSetUp(); + setAppFile("content_header_tests.py"); + } - // From: http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.5.1 + public void doHeaderTest(String appName, String queryString) throws Exception { + contentHeaderTestSetUp(); + setAppName(appName); + createServlet(); + if (queryString != null) + setQueryString(queryString); + doGet(); + } - protected void contentHeaderTestSetUp() - throws Exception - { - baseSetUp(); - setAppFile("content_header_tests.py"); - } + public void doHeaderTest(String appName) throws Exception { + doHeaderTest(appName, null); + } - public void doHeaderTest(String appName, String queryString) - throws Exception - { - contentHeaderTestSetUp(); - setAppName(appName); - createServlet(); - if (queryString != null) - setQueryString(queryString); - doGet(); - } + public void testSetContentLengthHeader() throws Exception { + doHeaderTest("test_set_content_length"); + assertEquals("Status code != 200: ServerError, =='" + getStatus() + "'", 200, getStatus()); + } - public void doHeaderTest(String appName) - throws Exception - { - doHeaderTest(appName, null); - } + public void testSetBadContentLengthHeader() throws Exception { + doHeaderTest("test_set_bad_content_length"); + assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); + assertTrue("Could not find exception 'BadArgument' in output", + getOutput().indexOf("BadArgument") != -1); + } - public void testSetContentLengthHeader ( ) - throws Exception - { - doHeaderTest("test_set_content_length"); - assertEquals("Status code != 200: ServerError, =='"+getStatus()+"'", 200, getStatus()); - } - - public void testSetBadContentLengthHeader ( ) - throws Exception - { - doHeaderTest("test_set_bad_content_length"); - assertEquals("Status code != 500: ServerError, =='"+getStatus()+"'", 500, getStatus()); - assertTrue("Could not find exception 'BadArgument' in output", - getOutput().indexOf("BadArgument")!=-1); - } - - public void testInferredContentLength ( ) - throws Exception - { - String appReturn = "Hello World!"; - doHeaderTest("test_inferred_content_length", appReturn); - assertEquals("Status code != 200: ServerError, =='"+getStatus()+"'", 200, getStatus()); - assertEquals("Content-length != '"+appReturn.length()+"', == '"+getResponse().getHeader("content-length")+"' ", - Integer.toString(appReturn.length()), getResponse().getHeader("content-length")); - } - + public void testInferredContentLength() throws Exception { + String appReturn = "Hello World!"; + doHeaderTest("test_inferred_content_length", appReturn); + assertEquals("Status code != 200: ServerError, =='" + getStatus() + "'", 200, getStatus()); + assertEquals("Content-length != '" + appReturn.length() + "', == '" + + getResponse().getHeader("content-length") + "' ", + Integer.toString(appReturn.length()), + getResponse().getHeader("content-length")); + } } Modified: trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestEnviron.java =================================================================== --- trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestEnviron.java 2009-06-22 08:27:10 UTC (rev 6492) +++ trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestEnviron.java 2009-06-22 08:43:07 UTC (rev 6493) @@ -1,328 +1,293 @@ -/*### -# -# 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 org.python.core.PyDictionary; -import org.python.core.PyInteger; -import org.python.core.PyObject; -import org.python.core.PyString; -import org.python.core.PyTuple; - -public class ModjyTestEnviron extends ModjyTestBase -{ - - protected void environTestS... [truncated message content] |