Author: olamy
Date: Tue Nov  1 17:44:32 2011
New Revision: 1196160

URL: http://svn.apache.org/viewvc?rev=1196160&view=rev
Log:
add unit tests for ScriptRunner class.

Added:
    
maven/shared/trunk/maven-script-interpreter/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java
   (with props)
    maven/shared/trunk/maven-script-interpreter/src/test/resources/
    maven/shared/trunk/maven-script-interpreter/src/test/resources/bsh-test/
    
maven/shared/trunk/maven-script-interpreter/src/test/resources/bsh-test/verify.bsh
   (with props)
    maven/shared/trunk/maven-script-interpreter/src/test/resources/groovy-test/
    
maven/shared/trunk/maven-script-interpreter/src/test/resources/groovy-test/verify.groovy
   (with props)
Modified:
    maven/shared/trunk/maven-script-interpreter/pom.xml

Modified: maven/shared/trunk/maven-script-interpreter/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-script-interpreter/pom.xml?rev=1196160&r1=1196159&r2=1196160&view=diff
==============================================================================
--- maven/shared/trunk/maven-script-interpreter/pom.xml (original)
+++ maven/shared/trunk/maven-script-interpreter/pom.xml Tue Nov  1 17:44:32 2011
@@ -75,9 +75,10 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>4.8.2</version>
+      <version>4.10</version>
       <scope>test</scope>
     </dependency>
+
   </dependencies>
 
   <build>

Added: 
maven/shared/trunk/maven-script-interpreter/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-script-interpreter/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java?rev=1196160&view=auto
==============================================================================
--- 
maven/shared/trunk/maven-script-interpreter/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java
 (added)
+++ 
maven/shared/trunk/maven-script-interpreter/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java
 Tue Nov  1 17:44:32 2011
@@ -0,0 +1,82 @@
+package org.apache.maven.shared.scriptinterpreter;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+import org.apache.maven.plugin.logging.SystemStreamLog;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Olivier Lamy
+ */
+public class ScriptRunnerTest
+    extends TestCase
+{
+    public void testBeanshell()
+        throws Exception
+    {
+        File logFile = new File( "target/build.log" );
+        if ( logFile.exists() )
+        {
+            logFile.delete();
+        }
+        SystemStreamLog systemStreamLog = new SystemStreamLog();
+
+        ScriptRunner scriptRunner = new ScriptRunner( systemStreamLog );
+        scriptRunner.run( "test", new File( "src/test/resources/bsh-test" ), 
"verify", buildContext(),
+                          new FileLogger( logFile ), "foo", true );
+
+        String logContent = FileUtils.fileRead( logFile );
+        assertTrue( logContent.contains( 
"src/test/resources/bsh-test/verify.bsh" ) );
+        assertTrue( logContent.contains( "foo=bar" ) );
+
+    }
+
+    public void testGroovy()
+        throws Exception
+    {
+        File logFile = new File( "target/build.log" );
+        if ( logFile.exists() )
+        {
+            logFile.delete();
+        }
+        SystemStreamLog systemStreamLog = new SystemStreamLog();
+
+        ScriptRunner scriptRunner = new ScriptRunner( systemStreamLog );
+        scriptRunner.run( "test", new File( "src/test/resources/groovy-test" 
), "verify", buildContext(),
+                          new FileLogger( logFile ), "foo", true );
+
+        String logContent = FileUtils.fileRead( logFile );
+        assertTrue( logContent.contains( 
"src/test/resources/groovy-test/verify.groovy" ) );
+        assertTrue( logContent.contains( "foo=bar" ) );
+
+    }
+
+    private Map<String, ? extends Object> buildContext()
+    {
+        Map<String, Object> context = new HashMap<String, Object>();
+        context.put( "foo", "bar" );
+        return context;
+    }
+
+}

Propchange: 
maven/shared/trunk/maven-script-interpreter/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/shared/trunk/maven-script-interpreter/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/shared/trunk/maven-script-interpreter/src/test/resources/bsh-test/verify.bsh
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-script-interpreter/src/test/resources/bsh-test/verify.bsh?rev=1196160&view=auto
==============================================================================
--- 
maven/shared/trunk/maven-script-interpreter/src/test/resources/bsh-test/verify.bsh
 (added)
+++ 
maven/shared/trunk/maven-script-interpreter/src/test/resources/bsh-test/verify.bsh
 Tue Nov  1 17:44:32 2011
@@ -0,0 +1,13 @@
+import java.io.*;
+
+File file = new File( basedir, "verify.bsh");
+if ( !file.exists())
+{
+  throw new FileNotFoundException("verify.bsh not found in " + basedir);
+}
+
+String value = context.get( "foo" );
+System.out.println("foo="+value);
+
+System.out.print("Test");
+return true;

Propchange: 
maven/shared/trunk/maven-script-interpreter/src/test/resources/bsh-test/verify.bsh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/shared/trunk/maven-script-interpreter/src/test/resources/bsh-test/verify.bsh
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/shared/trunk/maven-script-interpreter/src/test/resources/groovy-test/verify.groovy
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-script-interpreter/src/test/resources/groovy-test/verify.groovy?rev=1196160&view=auto
==============================================================================
--- 
maven/shared/trunk/maven-script-interpreter/src/test/resources/groovy-test/verify.groovy
 (added)
+++ 
maven/shared/trunk/maven-script-interpreter/src/test/resources/groovy-test/verify.groovy
 Tue Nov  1 17:44:32 2011
@@ -0,0 +1,3 @@
+assert (new File( basedir, "verify.groovy" ).exists())
+System.out.println("foo="+context.get("foo"));
+return true

Propchange: 
maven/shared/trunk/maven-script-interpreter/src/test/resources/groovy-test/verify.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/shared/trunk/maven-script-interpreter/src/test/resources/groovy-test/verify.groovy
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision


Reply via email to