[jbpm-commits] JBoss JBPM SVN: r6530 - in jbpm4/trunk/modules/pvm/src: main/java/org/jbpm/pvm/internal/script and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Sat Jul 24 03:27:57 EDT 2010


Author: rebody
Date: 2010-07-24 03:27:56 -0400 (Sat, 24 Jul 2010)
New Revision: 6530

Added:
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/BshExpressionTest.java
Modified:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/BasicEnvironment.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/EnvironmentBindings.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/JuelScriptEngine.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/GroovyExpressionTest.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/JuelExpressionTest.java
Log:
JBPM-1768 fix groovy, juel and bsh expression textcase

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/BasicEnvironment.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/BasicEnvironment.java	2010-07-24 02:20:57 UTC (rev 6529)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/BasicEnvironment.java	2010-07-24 07:27:56 UTC (rev 6530)
@@ -33,9 +33,9 @@
 public class BasicEnvironment extends EnvironmentImpl {
 
   private static final long serialVersionUID = 1L;
-  
-  private static final Log log = Log.getLog(BasicEnvironment.class.getName()); 
 
+  private static final Log log = Log.getLog(BasicEnvironment.class.getName());
+
   protected String authenticatedUserId;
   protected Map<String, Context> contexts = new LinkedHashMap<String, Context>();
   protected Throwable exception;
@@ -55,7 +55,7 @@
   public Context removeContext(Context context) {
     return removeContext(context.getName());
   }
-  
+
   public Context removeContext(String contextName) {
     return contexts.remove(contextName);
   }
@@ -69,11 +69,11 @@
   }
 
   // authenticatedUserId //////////////////////////////////////////////////////
-  
+
   public String getAuthenticatedUserId() {
     return authenticatedUserId;
   }
-  
+
   public void setAuthenticatedUserId(String authenticatedUserId) {
     this.authenticatedUserId = authenticatedUserId;
   }
@@ -83,11 +83,11 @@
   public ClassLoader getClassLoader() {
     return classLoader;
   }
-  
+
   public void setClassLoader(ClassLoader classLoader) {
     this.classLoader = classLoader;
   }
-  
+
   // search methods ///////////////////////////////////////////////////////////
 
   public Object get(String name) {
@@ -104,14 +104,14 @@
 
   public Object get(String name, String[] searchOrder, boolean nullIfNotFound) {
     if (searchOrder == null) {
-	  searchOrder = getDefaultSearchOrder();
-	}
-	for (String contextName : searchOrder) {
-	  Context context = contexts.get(contextName);
-	  if (context.has(name)) {
-		return context.get(name);
-	  }
-	}
+      searchOrder = getDefaultSearchOrder();
+    }
+    for (String contextName : searchOrder) {
+      Context context = contexts.get(contextName);
+      if (context.has(name)) {
+        return context.get(name);
+      }
+    }
     if (nullIfNotFound) {
       return null;
     } else {
@@ -134,7 +134,7 @@
     }
     return null;
   }
-  
+
   /**
    * searches an object based on type in the default search order.
    * if this environment contains the given context, the search skips
@@ -167,7 +167,7 @@
       throw new JbpmException("environment nesting problem");
     }
   }
-  
+
   // private methods //////////////////////////////////////////////////////////
 
   protected String[] getDefaultSearchOrder() {

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/EnvironmentBindings.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/EnvironmentBindings.java	2010-07-24 02:20:57 UTC (rev 6529)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/EnvironmentBindings.java	2010-07-24 07:27:56 UTC (rev 6530)
@@ -28,6 +28,7 @@
 
 import javax.script.Bindings;
 
+import org.jbpm.api.JbpmException;
 import org.jbpm.pvm.internal.env.EnvironmentImpl;
 
 /**
@@ -47,7 +48,13 @@
   }
 
   public boolean containsKey(Object key) {
-    return get(key) != null;
+    try {
+      environment.get((String) key, false);
+      return true;
+    } catch(JbpmException ex) {
+      // if cannot find property in environment, will cause a JbpmException
+      return false;
+    }
   }
 
   public Object put(String key, Object value) {

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/JuelScriptEngine.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/JuelScriptEngine.java	2010-07-24 02:20:57 UTC (rev 6529)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/JuelScriptEngine.java	2010-07-24 07:27:56 UTC (rev 6530)
@@ -49,7 +49,6 @@
 import javax.script.ScriptException;
 import javax.script.SimpleBindings;
 
-import org.jbpm.pvm.internal.env.ExecutionContext;
 import org.jbpm.pvm.internal.util.ReflectUtil;
 
 import de.odysseus.el.util.SimpleResolver;
@@ -393,15 +392,6 @@
 
         return exprFactory.createValueExpression(
             value, Object.class);
-      } else {
-        // to support null value for existing variables
-        Bindings b = this.ctx.getBindings(ScriptContext.ENGINE_SCOPE);
-        ExecutionContext execContext = (ExecutionContext) ((EnvironmentBindings) b).environment.getContext("execution");
-        // if variable name exist then set value expression as null
-        // since it was not discovered by attribute scope method
-        if (execContext.getExecution().getVariables().containsKey(variable)) {
-          return exprFactory.createValueExpression(null, Object.class);
-        }
       }
       return null;
     }

Added: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/BshExpressionTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/BshExpressionTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/BshExpressionTest.java	2010-07-24 07:27:56 UTC (rev 6530)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.expr;
+
+import org.jbpm.pvm.activities.WaitState;
+import org.jbpm.pvm.internal.builder.ProcessDefinitionBuilder;
+import org.jbpm.pvm.internal.client.ClientExecution;
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.pvm.internal.env.EnvironmentFactory;
+import org.jbpm.pvm.internal.env.ExecutionContext;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.processengine.ProcessEngineImpl;
+import org.jbpm.pvm.internal.script.ScriptManager;
+import org.jbpm.test.BaseJbpmTestCase;
+
+
+/**
+ * @author Huisheng Xu
+ */
+public class BshExpressionTest extends BaseJbpmTestCase {
+  public static final String XML =
+        "<jbpm-configuration>" +
+        "  <process-engine-context>" +
+        "    <script-manager default-expression-language='juel'" +
+        "                    default-script-language='juel'>" +
+        "      <script-language name='groovy' factory='org.jbpm.pvm.internal.script.BshScriptEngineFactory' />" +
+        "    </script-manager>" +
+        "  </process-engine-context>" +
+        "</jbpm-configuration>";
+
+  public void testGroovyExpression() {
+    EnvironmentFactory environmentFactory = ProcessEngineImpl.parseXmlString(XML);
+
+    ScriptManager scriptManager = environmentFactory.get(ScriptManager.class);
+
+    ClientExecution execution = ProcessDefinitionBuilder
+    .startProcess()
+      .startActivity("initial", new WaitState())
+        .initial()
+      .endActivity()
+    .endProcess()
+    .startProcessInstance();
+
+    execution.setVariable("pv", "hello");
+
+    EnvironmentImpl environment = environmentFactory.openEnvironment();
+    try {
+      environment.setContext(new ExecutionContext((ExecutionImpl) execution));
+      assertEquals("hello", scriptManager.evaluateExpression("pv", "bsh"));
+    } finally {
+      environment.close();
+    }
+  }
+
+  public void testGroovyExpressionWithNull() {
+    EnvironmentFactory environmentFactory = ProcessEngineImpl.parseXmlString(XML);
+
+    ScriptManager scriptManager = environmentFactory.get(ScriptManager.class);
+
+    ClientExecution execution = ProcessDefinitionBuilder
+    .startProcess()
+      .startActivity("initial", new WaitState())
+        .initial()
+      .endActivity()
+    .endProcess()
+    .startProcessInstance();
+
+    execution.setVariable("pv", null);
+
+    EnvironmentImpl environment = environmentFactory.openEnvironment();
+    try {
+      environment.setContext(new ExecutionContext((ExecutionImpl) execution));
+      assertNull(scriptManager.evaluateExpression("pv", "bsh"));
+    } finally {
+      environment.close();
+    }
+  }
+}

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/GroovyExpressionTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/GroovyExpressionTest.java	2010-07-24 02:20:57 UTC (rev 6529)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/GroovyExpressionTest.java	2010-07-24 07:27:56 UTC (rev 6530)
@@ -1,75 +1,98 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jbpm.pvm.internal.expr;
-
-import org.jbpm.pvm.activities.WaitState;
-import org.jbpm.pvm.internal.builder.ProcessDefinitionBuilder;
-import org.jbpm.pvm.internal.client.ClientExecution;
-import org.jbpm.pvm.internal.env.EnvironmentImpl;
-import org.jbpm.pvm.internal.env.EnvironmentFactory;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
-import org.jbpm.pvm.internal.processengine.ProcessEngineImpl;
-import org.jbpm.pvm.internal.script.ScriptManager;
-import org.jbpm.test.BaseJbpmTestCase;
-
-
-/**
- * @author Tom Baeyens
- */
-public class GroovyExpressionTest extends BaseJbpmTestCase {
-
-  public void testGroovyExpression() {
-    System.out.println("FIXME: JBPM-1768 Fix groovy support");
-  }
-
-  public void dontTestGroovyExpression() {
-    EnvironmentFactory environmentFactory = ProcessEngineImpl.parseXmlString(
-        "<jbpm-configuration>" +
-        "  <process-engine-context>" +
-        "    <script-manager default-expression-language='juel'" +
-        "                    default-script-language='juel'>" +
-        "      <script-language name='groovy' factory='com.sun.script.groovy.GroovyScriptEngineFactory' />" +
-        "    </script-manager>" +
-        "  </process-engine-context>" +
-        "</jbpm-configuration>"
-    );
-
-    ScriptManager scriptManager = environmentFactory.get(ScriptManager.class);
-    
-    ClientExecution execution = ProcessDefinitionBuilder
-    .startProcess()
-      .startActivity("initial", new WaitState())
-        .initial()
-      .endActivity()
-    .endProcess()
-    .startProcessInstance();
-    
-    execution.setVariable("pv", "hello");
-    
-    EnvironmentImpl environment = environmentFactory.openEnvironment();
-    try {
-      assertEquals("hello", scriptManager.evaluateExpression("pv", "groovy"));
-    } finally {
-      environment.close();
-    }
-  }
-}
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.expr;
+
+import org.jbpm.pvm.activities.WaitState;
+import org.jbpm.pvm.internal.builder.ProcessDefinitionBuilder;
+import org.jbpm.pvm.internal.client.ClientExecution;
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.pvm.internal.env.EnvironmentFactory;
+import org.jbpm.pvm.internal.env.ExecutionContext;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.processengine.ProcessEngineImpl;
+import org.jbpm.pvm.internal.script.ScriptManager;
+import org.jbpm.test.BaseJbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ * @author Huisheng Xu
+ */
+public class GroovyExpressionTest extends BaseJbpmTestCase {
+  public static final String XML =
+        "<jbpm-configuration>" +
+        "  <process-engine-context>" +
+        "    <script-manager default-expression-language='juel'" +
+        "                    default-script-language='juel'>" +
+        "      <script-language name='groovy' factory='org.jbpm.pvm.internal.script.GroovyScriptEngineFactory' />" +
+        "    </script-manager>" +
+        "  </process-engine-context>" +
+        "</jbpm-configuration>";
+
+  public void testGroovyExpression() {
+    EnvironmentFactory environmentFactory = ProcessEngineImpl.parseXmlString(XML);
+
+    ScriptManager scriptManager = environmentFactory.get(ScriptManager.class);
+
+    ClientExecution execution = ProcessDefinitionBuilder
+    .startProcess()
+      .startActivity("initial", new WaitState())
+        .initial()
+      .endActivity()
+    .endProcess()
+    .startProcessInstance();
+
+    execution.setVariable("pv", "hello");
+
+    EnvironmentImpl environment = environmentFactory.openEnvironment();
+    try {
+      environment.setContext(new ExecutionContext((ExecutionImpl) execution));
+      assertEquals("hello", scriptManager.evaluateExpression("pv", "groovy"));
+    } finally {
+      environment.close();
+    }
+  }
+
+  public void testGroovyExpressionWithNull() {
+    EnvironmentFactory environmentFactory = ProcessEngineImpl.parseXmlString(XML);
+
+    ScriptManager scriptManager = environmentFactory.get(ScriptManager.class);
+
+    ClientExecution execution = ProcessDefinitionBuilder
+    .startProcess()
+      .startActivity("initial", new WaitState())
+        .initial()
+      .endActivity()
+    .endProcess()
+    .startProcessInstance();
+
+    execution.setVariable("pv", null);
+
+    EnvironmentImpl environment = environmentFactory.openEnvironment();
+    try {
+      environment.setContext(new ExecutionContext((ExecutionImpl) execution));
+      assertNull(scriptManager.evaluateExpression("pv", "groovy"));
+    } finally {
+      environment.close();
+    }
+  }
+}

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/JuelExpressionTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/JuelExpressionTest.java	2010-07-24 02:20:57 UTC (rev 6529)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/JuelExpressionTest.java	2010-07-24 07:27:56 UTC (rev 6530)
@@ -33,11 +33,10 @@
 
 /**
  * @author Tom Baeyens
+ * @author Huisheng Xu
  */
 public class JuelExpressionTest extends BaseJbpmTestCase {
-  
-  public void testJuelExpression() {
-    EnvironmentFactory environmentFactory = ProcessEngineImpl.parseXmlString(
+  public static final String XML =
         "<jbpm-configuration>" +
         "  <process-engine-context>" +
         "    <script-manager default-expression-language='juel'" +
@@ -45,11 +44,13 @@
         "      <script-language name='juel' factory='com.sun.script.juel.JuelScriptEngineFactory' />" +
         "    </script-manager>" +
         "  </process-engine-context>" +
-        "</jbpm-configuration>"
-    );
+        "</jbpm-configuration>";
 
+  public void testJuelExpression() {
+    EnvironmentFactory environmentFactory = ProcessEngineImpl.parseXmlString(XML);
+
     ScriptManager scriptManager = environmentFactory.get(ScriptManager.class);
-    
+
     ExecutionImpl execution = (ExecutionImpl) ProcessDefinitionBuilder
     .startProcess()
       .startActivity("initial", new WaitState())
@@ -57,9 +58,9 @@
       .endActivity()
     .endProcess()
     .startProcessInstance();
-    
+
     execution.setVariable("pv", "hello");
-    
+
     EnvironmentImpl environment = environmentFactory.openEnvironment();
     environment.setContext(new ExecutionContext(execution));
     try {
@@ -68,4 +69,28 @@
       environment.close();
     }
   }
+
+  public void testJuelExpressionWithNull() {
+    EnvironmentFactory environmentFactory = ProcessEngineImpl.parseXmlString(XML);
+
+    ScriptManager scriptManager = environmentFactory.get(ScriptManager.class);
+
+    ExecutionImpl execution = (ExecutionImpl) ProcessDefinitionBuilder
+    .startProcess()
+      .startActivity("initial", new WaitState())
+        .initial()
+      .endActivity()
+    .endProcess()
+    .startProcessInstance();
+
+    execution.setVariable("pv", null);
+
+    EnvironmentImpl environment = environmentFactory.openEnvironment();
+    environment.setContext(new ExecutionContext(execution));
+    try {
+      assertNull(scriptManager.evaluateExpression("#{pv}", null));
+    } finally {
+      environment.close();
+    }
+  }
 }



More information about the jbpm-commits mailing list