Author: kwall
Date: Sat Mar 23 15:52:28 2013
New Revision: 1460177

URL: http://svn.apache.org/r1460177
Log:
PROTON-276: JythonTest now uses system property to locate python testscript and 
test-root.

Modified:
    qpid/proton/trunk/tests/java/org/apache/qpid/proton/JythonTest.java
    qpid/proton/trunk/tests/pom.xml

Modified: qpid/proton/trunk/tests/java/org/apache/qpid/proton/JythonTest.java
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/tests/java/org/apache/qpid/proton/JythonTest.java?rev=1460177&r1=1460176&r2=1460177&view=diff
==============================================================================
--- qpid/proton/trunk/tests/java/org/apache/qpid/proton/JythonTest.java 
(original)
+++ qpid/proton/trunk/tests/java/org/apache/qpid/proton/JythonTest.java Sat Mar 
23 15:52:28 2013
@@ -23,8 +23,7 @@ package org.apache.qpid.proton;
 import static org.junit.Assert.fail;
 
 import java.io.File;
-import java.net.URISyntaxException;
-import java.net.URL;
+import java.io.FileNotFoundException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -40,37 +39,34 @@ import org.python.util.PythonInterpreter
  */
 public class JythonTest
 {
-
     private static final Logger LOGGER = 
Logger.getLogger(JythonTest.class.getName());
 
-    /** System property is defined in test/pom.xml */
-    private static final String PROTON_JYTHON_TESTS_XML_OUTPUT_DIRECTORY = 
"protonJythonTestsXmlOutputDirectory";
+    /* System properties expected to be defined in test/pom.xml */
+    private static final String PROTON_JYTHON_TEST_ROOT = 
"protonJythonTestRoot";
+    private static final String PROTON_JYTHON_TEST_SCRIPT = 
"protonJythonTestScript";
+    private static final String PROTON_JYTHON_TESTS_XML_OUTPUT_DIRECTORY = 
"protonJythonTestXmlOutputDirectory";
+
     /** Name of the junit style xml report to be written by the python test 
script */
     private static final String XML_REPORT_NAME = 
"TEST-jython-test-results.xml";
 
     private static final String TEST_PATTERN_SYSTEM_PROPERTY = 
"proton.pythontest.pattern";
-    private static final String PROTON_TEST_SCRIPT_CLASSPATH_LOCATION = 
"/proton-test";
 
     @Test
     public void test() throws Exception
     {
-        File protonScriptFile = getPythonTestScript();
-        String parentDirectory = protonScriptFile.getParent();
+        String testScript = getJythonTestScript();
+        String testRoot = getJythonTestRoot();
         String xmlReportFile = getOptionalXmlReportFilename();
 
         PythonInterpreter interp = createInterpreterWithArgs(xmlReportFile);
+        interp.getSystemState().path.insert(0, new PyString(testRoot));
 
-        LOGGER.info("About to call Jython test script: " + protonScriptFile + 
" with parent directory added to Jython path");
-
-        interp.exec(
-        "import sys\n"+
-        "sys.path.insert(0,\""+parentDirectory+"\")\n"
-        );
+        LOGGER.info("About to call Jython test script: '" + testScript
+                + "' with '" + testRoot + "' added to Jython path");
 
         try
         {
-            String protonTestPyPath = protonScriptFile.getAbsolutePath();
-            interp.execfile(protonTestPyPath);
+            interp.execfile(testScript);
         }
         catch (PyException e)
         {
@@ -112,11 +108,27 @@ public class JythonTest
         return interp;
     }
 
-    private File getPythonTestScript() throws URISyntaxException
+    private String getJythonTestScript() throws FileNotFoundException
+    {
+        String testScriptString = 
getNonNullSystemProperty(PROTON_JYTHON_TEST_SCRIPT, "System property '%s' must 
provide the location of the python test script");
+        File testScript = new File(testScriptString);
+        if (!testScript.canRead())
+        {
+            throw new FileNotFoundException("Can't read python test script " + 
testScript);
+        }
+        return testScript.getAbsolutePath();
+    }
+
+
+    private String getJythonTestRoot() throws FileNotFoundException
     {
-        URL protonScriptUrl = 
getClass().getResource(PROTON_TEST_SCRIPT_CLASSPATH_LOCATION);
-        File protonScriptFile = new File(protonScriptUrl.toURI());
-        return protonScriptFile;
+        String testRootString = 
getNonNullSystemProperty(PROTON_JYTHON_TEST_ROOT, "System property '%s' must 
provide the location of the python test root");
+        File testRoot = new File(testRootString);
+        if (!testRoot.isDirectory())
+        {
+            throw new FileNotFoundException("Test root '" + testRoot + "' 
should be a directory.");
+        }
+        return testRoot.getAbsolutePath();
     }
 
     private String getOptionalXmlReportFilename()
@@ -148,4 +160,15 @@ public class JythonTest
             }
         }
     }
+
+    private String getNonNullSystemProperty(String systemProperty, String 
messageWithStringFormatToken)
+    {
+        String testScriptString = System.getProperty(systemProperty);
+        if (testScriptString == null)
+        {
+            String message = messageWithStringFormatToken;
+            throw new IllegalStateException(String.format(message, 
systemProperty));
+        }
+        return testScriptString;
+    }
 }

Modified: qpid/proton/trunk/tests/pom.xml
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/tests/pom.xml?rev=1460177&r1=1460176&r2=1460177&view=diff
==============================================================================
--- qpid/proton/trunk/tests/pom.xml (original)
+++ qpid/proton/trunk/tests/pom.xml Sat Mar 23 15:52:28 2013
@@ -42,8 +42,6 @@ To override this, run Maven like so: &qu
     <!-- System tests are arranged by language, hence the non-default location 
of the JUnit tests. -->
     <testSourceDirectory>java</testSourceDirectory>
     <resources>
-      <resource><directory>python</directory></resource>
-      <resource><directory>interop</directory></resource>
       <resource><directory>resources</directory></resource>
     </resources>
     <plugins>
@@ -52,7 +50,9 @@ To override this, run Maven like so: &qu
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
           <systemPropertyVariables>
-            
<protonJythonTestsXmlOutputDirectory>${testReportOutputDirectory}</protonJythonTestsXmlOutputDirectory>
+            <protonJythonTestRoot>${basedir}/python</protonJythonTestRoot>
+            
<protonJythonTestScript>${basedir}/python/proton-test</protonJythonTestScript>
+            
<protonJythonTestXmlOutputDirectory>${testReportOutputDirectory}</protonJythonTestXmlOutputDirectory>
             
<java.util.logging.config.file>${build.outputDirectory}/logging.properties</java.util.logging.config.file>
           </systemPropertyVariables>
          <reportsDirectory>${testReportOutputDirectory}</reportsDirectory>



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to