[jboss-svn-commits] JBL Code SVN: r38391 - in labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5: src/test/java/org/jboss/soa/esb/services/jbpm5/actions and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jul 31 11:19:12 EDT 2013


Author: tcunning
Date: 2013-07-31 11:19:11 -0400 (Wed, 31 Jul 2013)
New Revision: 38391

Added:
   labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/src/test/java/org/jboss/soa/esb/services/jbpm5/actions/SubProcessesUnitTest.java
   labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/test/resources/BPMN2-CallActivity.bpmn2
   labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/test/resources/BPMN2-CallActivitySubProcess.bpmn2
Modified:
   labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/src/main/java/org/jboss/soa/esb/services/jbpm5/actions/AbstractBpm5Action.java
Log:
JBESB-3945
Change process-id to a comma delimited list of classpathresources.


Modified: labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/src/main/java/org/jboss/soa/esb/services/jbpm5/actions/AbstractBpm5Action.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/src/main/java/org/jboss/soa/esb/services/jbpm5/actions/AbstractBpm5Action.java	2013-07-31 05:49:07 UTC (rev 38390)
+++ labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/src/main/java/org/jboss/soa/esb/services/jbpm5/actions/AbstractBpm5Action.java	2013-07-31 15:19:11 UTC (rev 38391)
@@ -27,6 +27,7 @@
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.Properties;
+import java.util.StringTokenizer;
 import javax.naming.InitialContext;
 import javax.transaction.TransactionManager;
 import javax.transaction.UserTransaction;
@@ -120,8 +121,21 @@
         config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);
 
         KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
-        kbuilder.add(ResourceFactory.newClassPathResource(processDefName), ResourceType.BPMN2);
-		kbase = kbuilder.newKnowledgeBase();
+
+        // processDefName contains a list of comma separated process definition names 
+        if (processDefName.contains(",")) {
+            StringTokenizer tokenizer = new StringTokenizer(processDefName, ",");
+            while (tokenizer.hasMoreElements()) {
+                String nextProcessDef = tokenizer.nextToken();
+                kbuilder.add(ResourceFactory.newClassPathResource(nextProcessDef), ResourceType.BPMN2);
+            }
+            kbase = kbuilder.newKnowledgeBase();
+            logger.info("Knowledgebase built from multiple process definitions");
+        } else {
+            kbuilder.add(ResourceFactory.newClassPathResource(processDefName), ResourceType.BPMN2);
+            kbase = kbuilder.newKnowledgeBase();
+            logger.info("Knowledgebase built from single process definition");
+        } 
         
         // Create session
 		StatefulKnowledgeSession mySession = null;

Added: labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/src/test/java/org/jboss/soa/esb/services/jbpm5/actions/SubProcessesUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/src/test/java/org/jboss/soa/esb/services/jbpm5/actions/SubProcessesUnitTest.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/src/test/java/org/jboss/soa/esb/services/jbpm5/actions/SubProcessesUnitTest.java	2013-07-31 15:19:11 UTC (rev 38391)
@@ -0,0 +1,134 @@
+package org.jboss.soa.esb.services.jbpm5.actions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.KeyGenerator;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.SealedObject;
+import javax.crypto.SecretKey;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.soa.esb.services.jbpm5.MockDataSource;
+import org.jboss.soa.esb.services.jbpm5.MockTransactionManager;
+import org.jboss.soa.esb.services.jbpm5.MockUserTransaction;
+import org.jboss.soa.esb.services.jbpm5.actions.Bpm5Processor;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.services.security.SecurityContext;
+import org.jboss.soa.esb.services.security.SecurityService;
+import org.jboss.soa.esb.services.security.auth.AuthenticationRequestImpl;
+import org.junit.Before;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+/**
+ * Test the BPM5Process action's security context / auth request.
+ *  
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ */
+public class SubProcessesUnitTest {
+    private Bpm5Processor bpmProcessor;
+    private Message message;
+    private ConfigTree configTree;
+
+    @Test
+    public void verifyThatSecurityContextWasAddedToMesssageContext() throws ConfigurationException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, IOException
+    {
+        final SealedObject securityContext = createSealedObject("dummy string");
+        SecurityContext.setSecurityContext(securityContext);
+        bpmProcessor.addSecurityContext(message);
+
+        assertNotNull(message.getContext().getContext(SecurityService.CONTEXT));
+        assertEquals(securityContext, message.getContext().getContext(SecurityService.CONTEXT));
+    }
+
+    @Test
+    public void verifyThatNullSecurityContextCanBeAddedToMesssageContext() throws ConfigurationException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, IOException
+    {
+        SecurityContext.setSecurityContext(null);
+        bpmProcessor.addSecurityContext(message);
+
+        assertNull(message.getContext().getContext(SecurityService.CONTEXT));
+    }
+
+    @Test
+    public void verifyThatAuthenticationRequestWasAddedToMessageContext() throws ConfigurationException
+    {
+        //  Doesn't need to be encrypted as this is only passed along and never descrypted.
+        byte[] encryptedAuthRequest = new byte[100];
+        AuthenticationRequestImpl.setEncryptedAuthRequest(encryptedAuthRequest);
+        bpmProcessor.addAuthenticationRequest(message);
+
+        assertNotNull(message.getContext().getContext(SecurityService.AUTH_REQUEST));
+        assertEquals(encryptedAuthRequest, message.getContext().getContext(SecurityService.AUTH_REQUEST));
+    }
+
+    @Test
+    public void verifyThatNullAuthenticationRequestCanBeAddedToMessageContext() throws ConfigurationException
+    {
+        AuthenticationRequestImpl.setEncryptedAuthRequest(null);
+        bpmProcessor.addAuthenticationRequest(message);
+        assertNull(message.getContext().getContext(SecurityService.AUTH_REQUEST));
+    }
+
+    @Before
+    public void setup() throws ConfigurationException
+    {
+    	Context ctx = null;
+        try {
+            ctx = new InitialContext();
+            MockDataSource mds = new MockDataSource();
+            MockUserTransaction mut = new MockUserTransaction();
+            MockTransactionManager mtm = new MockTransactionManager();
+            ctx.rebind("UserTransaction", mut);
+            ctx.rebind("java:jboss/datasources/jbpm5DS", mds);
+            ctx.rebind("java:/TransactionManager", mtm);
+        } catch (Exception e) {
+            //fail(e.getMessage());
+        }
+    	
+    	try {
+    		configTree = ConfigTree.fromXml(
+        	 "<action action=\"jbpm5\" class=\"org.jboss.soa.esb.services.jbpm5.actions.Bpm5Processor\" process-action=\"startProcess\" "
+        	  + "process-definition-name=\"BPMN2-CallActivity.bpmn2,BPMN2-CallActivitySubProcess.bpmn2\" process-id=\"ParentProcess\">"
+              + "<mapping bpm=\"x\" esb=\"x\" value=\"oldvalue\"/>"
+              + "</action>");
+    	} catch (SAXException se){
+    		throw new ConfigurationException(se);
+    	}
+        bpmProcessor = new Bpm5Processor(configTree);
+        message = MessageFactory.getInstance().getMessage();
+    }
+
+    public static junit.framework.Test suite()
+    {
+        return new JUnit4TestAdapter(Bpm5ProcessorUnitTest.class);
+    }
+
+    private SealedObject createSealedObject(final Serializable ser) throws NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, IOException, InvalidKeyException
+    {
+        final KeyGenerator kpg = KeyGenerator.getInstance("TripleDES");
+        kpg.init(112);
+        final SecretKey secretKey = kpg.generateKey();
+        final Cipher cipher = Cipher.getInstance("TripleDES");
+        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
+
+        return new SealedObject(ser, cipher);
+    }
+
+}

Added: labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/test/resources/BPMN2-CallActivity.bpmn2
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/test/resources/BPMN2-CallActivity.bpmn2	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/test/resources/BPMN2-CallActivity.bpmn2	2013-07-31 15:19:11 UTC (rev 38391)
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+<definitions id="Definition"
+             targetNamespace="http://www.example.org/MinimalExample"
+             typeLanguage="http://www.java.com/javaTypes"
+             expressionLanguage="http://www.mvel.org/2.0"
+             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
+             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+             xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"
+             xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
+             xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
+             xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
+             xmlns:tns="http://www.jboss.org/drools">
+
+  <itemDefinition id="_xItem" />
+  <itemDefinition id="_yItem" />
+
+  <process processType="Private" isExecutable="true" id="ParentProcess" name="Parent Process" >
+
+    <!-- process variables -->
+    <property id="x" itemSubjectRef="_xItem"/>
+    <property id="y" itemSubjectRef="_yItem"/>
+
+    <!-- nodes -->
+    <startEvent id="_1" name="StartProcess" />
+    <callActivity id="_2" name="CallActivity" calledElement="SubProcess" >
+      <ioSpecification>
+        <dataInput id="_2_subXInput" name="subX" />
+        <dataOutput id="_2_subYOutput" name="subY" />
+        <inputSet>
+          <dataInputRefs>_2_subXInput</dataInputRefs>
+        </inputSet>
+        <outputSet>
+          <dataOutputRefs>_2_subYOutput</dataOutputRefs>
+        </outputSet>
+      </ioSpecification>
+      <dataInputAssociation>
+        <sourceRef>x</sourceRef>
+        <targetRef>_2_subXInput</targetRef>
+      </dataInputAssociation>
+      <dataOutputAssociation>
+        <sourceRef>_2_subYOutput</sourceRef>
+        <targetRef>y</targetRef>
+      </dataOutputAssociation>
+    </callActivity>
+    <endEvent id="_3" name="EndProcess" >
+        <terminateEventDefinition/>
+    </endEvent>
+
+    <!-- connections -->
+    <sequenceFlow id="_1-_2" sourceRef="_1" targetRef="_2" />
+    <sequenceFlow id="_2-_3" sourceRef="_2" targetRef="_3" />
+
+  </process>
+
+  <bpmndi:BPMNDiagram>
+    <bpmndi:BPMNPlane bpmnElement="ParentProcess" >
+      <bpmndi:BPMNShape bpmnElement="_1" >
+        <dc:Bounds x="16" y="16" width="48" height="48" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape bpmnElement="_2" >
+        <dc:Bounds x="96" y="16" width="110" height="48" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape bpmnElement="_3" >
+        <dc:Bounds x="238" y="16" width="48" height="48" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNEdge bpmnElement="_1-_2" >
+        <di:waypoint x="40" y="40" />
+        <di:waypoint x="151" y="40" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge bpmnElement="_2-_3" >
+        <di:waypoint x="151" y="40" />
+        <di:waypoint x="262" y="40" />
+      </bpmndi:BPMNEdge>
+    </bpmndi:BPMNPlane>
+  </bpmndi:BPMNDiagram>
+
+</definitions>
\ No newline at end of file

Added: labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/test/resources/BPMN2-CallActivitySubProcess.bpmn2
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/test/resources/BPMN2-CallActivitySubProcess.bpmn2	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_11_CP2/product/services/jbpm5/test/resources/BPMN2-CallActivitySubProcess.bpmn2	2013-07-31 15:19:11 UTC (rev 38391)
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+<definitions id="Definition"
+             targetNamespace="http://www.example.org/MinimalExample"
+             typeLanguage="http://www.java.com/javaTypes"
+             expressionLanguage="http://www.mvel.org/2.0"
+             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
+             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+             xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"
+             xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
+             xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
+             xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
+             xmlns:tns="http://www.jboss.org/drools">
+
+  <itemDefinition id="_subXItem" />
+  <itemDefinition id="_subYItem" />
+
+  <process processType="Private" isExecutable="true" id="SubProcess" name="Sub Process" tns:version="1" >
+
+    <!-- process variables -->
+    <property id="subX" itemSubjectRef="_subXItem"/>
+    <property id="subY" itemSubjectRef="_subYItem"/>
+
+    <!-- nodes -->
+    <startEvent id="_1" name="StartProcess" />
+    <scriptTask id="_2" name="Hello" >
+      <script>System.out.println("subX=" + subX);
+kcontext.setVariable("subY", "new value");</script>
+    </scriptTask>
+    <endEvent id="_3" name="EndProcess" >
+        <terminateEventDefinition/>
+    </endEvent>
+
+    <!-- connections -->
+    <sequenceFlow id="_1-_2" sourceRef="_1" targetRef="_2" />
+    <sequenceFlow id="_2-_3" sourceRef="_2" targetRef="_3" />
+
+  </process>
+
+  <bpmndi:BPMNDiagram>
+    <bpmndi:BPMNPlane bpmnElement="SubProcess" >
+      <bpmndi:BPMNShape bpmnElement="_1" >
+        <dc:Bounds x="16" y="16" width="48" height="48" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape bpmnElement="_2" >
+        <dc:Bounds x="96" y="16" width="80" height="48" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape bpmnElement="_3" >
+        <dc:Bounds x="208" y="16" width="48" height="48" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNEdge bpmnElement="_1-_2" >
+        <di:waypoint x="40" y="40" />
+        <di:waypoint x="136" y="40" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge bpmnElement="_2-_3" >
+        <di:waypoint x="136" y="40" />
+        <di:waypoint x="232" y="40" />
+      </bpmndi:BPMNEdge>
+    </bpmndi:BPMNPlane>
+  </bpmndi:BPMNDiagram>
+
+</definitions>
\ No newline at end of file



More information about the jboss-svn-commits mailing list