Author: manaRH
Date: 2010-06-03 08:54:16 -0400 (Thu, 03 Jun 2010)
New Revision: 13012
Added:
branches/enterprise/JBPAPP_5_0/src/test/unit/org/jboss/seam/test/unit/bpm/JbpmTest.java
Modified:
branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/bpm/Jbpm.java
branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/util/Resources.java
branches/enterprise/JBPAPP_5_0/src/test/unit/org/jboss/seam/test/unit/testng.xml
Log:
JBPAPP-4415 backporting JBSEAM-4474
Modified: branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/bpm/Jbpm.java
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/bpm/Jbpm.java 2010-06-03
12:31:43 UTC (rev 13011)
+++ branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/bpm/Jbpm.java 2010-06-03
12:54:16 UTC (rev 13012)
@@ -3,6 +3,7 @@
import static org.jboss.seam.annotations.Install.BUILT_IN;
import java.io.InputStream;
+import java.io.Reader;
import java.io.StringReader;
import java.util.Arrays;
import java.util.HashMap;
@@ -17,7 +18,6 @@
import org.dom4j.Element;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Environment;
-import org.hibernate.lob.ReaderInputStream;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
@@ -225,12 +225,13 @@
*/
public ProcessDefinition getPageflowDefinitionFromXml(String pageflowDefinition)
{
- InputStream stream = null;
+ Reader reader = null;
try {
- stream = new ReaderInputStream(new StringReader(pageflowDefinition));
- return Jbpm.parseInputSource(new InputSource(stream));
+ reader = new StringReader(pageflowDefinition);
+ //stream = new ReaderInputStream(new StringReader(pageflowDefinition));
+ return Jbpm.parseReaderSource(reader);
} finally {
- Resources.closeStream(stream);
+ Resources.closeReader(reader);
}
}
@@ -241,12 +242,14 @@
*/
public ProcessDefinition getProcessDefinitionFromXml(String processDefinition)
{
- InputStream stream = null;
+ //InputStream stream = null;
+ Reader reader = null;
try {
- stream = new ReaderInputStream(new StringReader(processDefinition));
- return ProcessDefinition.parseXmlInputStream(stream);
+ //stream = new ReaderInputStream(new StringReader(processDefinition));
+ reader = new StringReader(processDefinition);
+ return ProcessDefinition.parseXmlReader(reader);
} finally {
- Resources.closeStream(stream);
+ Resources.closeReader(reader);
}
}
@@ -363,6 +366,19 @@
jbpmContext.close();
}
}
+
+ public static ProcessDefinition parseReaderSource(Reader reader)
+ {
+ JbpmContext jbpmContext = createPageflowContext();
+ try
+ {
+ return new PageflowParser(reader).readProcessDefinition();
+ }
+ finally
+ {
+ jbpmContext.close();
+ }
+ }
private static final DbSubProcessResolver DB_SUB_PROCESS_RESOLVER = new
DbSubProcessResolver();
class SeamSubProcessResolver implements SubProcessResolver
Modified: branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/util/Resources.java
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/util/Resources.java 2010-06-03
12:31:43 UTC (rev 13011)
+++ branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/util/Resources.java 2010-06-03
12:54:16 UTC (rev 13012)
@@ -139,6 +139,18 @@
}
}
+ public static void closeReader(java.io.Reader reader) {
+ if (reader == null) {
+ return;
+ }
+
+ try {
+ reader.close();
+ } catch (IOException e) {
+ //
+ }
+ }
+
public static File getRealFile(ServletContext servletContext, String path)
{
String realPath = servletContext.getRealPath(path);
Added:
branches/enterprise/JBPAPP_5_0/src/test/unit/org/jboss/seam/test/unit/bpm/JbpmTest.java
===================================================================
---
branches/enterprise/JBPAPP_5_0/src/test/unit/org/jboss/seam/test/unit/bpm/JbpmTest.java
(rev 0)
+++
branches/enterprise/JBPAPP_5_0/src/test/unit/org/jboss/seam/test/unit/bpm/JbpmTest.java 2010-06-03
12:54:16 UTC (rev 13012)
@@ -0,0 +1,57 @@
+package org.jboss.seam.test.unit.bpm;
+
+import org.jboss.seam.bpm.Jbpm;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.testng.annotations.Test;
+
+/**
+ * @author Marek Novotny
+ *
+ */
+public class JbpmTest
+{
+
+ private static final String PROCESS_DEFINITION = "<process-definition
name=\"test\"> " +
+ "<start-state
name=\"start\"> " +
+ " <transition
to=\"decision\" /> " +
+ "</start-state> " +
+ "<decision
name=\"decision\"> " +
+ " <transition
to=\"done\" name=\"true\" />" +
+ " <transition
to=\"done\" name=\"false\" /> " +
+ "</decision> " +
+ "<end-state
name=\"done\"/> " +
+ "</process-definition>";
+
+ private static final String PAGE_FLOW_DEFINITION = "<pageflow-definition
name=\"newuser\" >" +
+ "<start-state
name=\"start\">" +
+ " <transition
to=\"account\"/>" +
+
"</start-state>" +
+ "<page
name=\"account\" view-id=\"/newuser/account.xhtml\">" +
+ "
<redirect/>" +
+ " <transition
name=\"next\" to=\"checkPassword\" />" +
+ "</page>" +
+
"</pageflow-definition>" ;
+
+ @Test
+ public void testGetProcessDefinitionFromXml()
+ {
+
+ Jbpm jbpm = new Jbpm();
+ ProcessDefinition pd = jbpm.getProcessDefinitionFromXml(PROCESS_DEFINITION);
+ assert "start".equals(pd.getStartState().getName());
+ assert "test".equals(pd.getName());
+
+ }
+
+ @Test
+ public void testGetPageflowDefinitionFromXml()
+ {
+
+ Jbpm jbpm = new Jbpm();
+ ProcessDefinition pd = jbpm.getPageflowDefinitionFromXml(PAGE_FLOW_DEFINITION);
+ assert "start".equals(pd.getStartState().getName());
+ assert "newuser".equals(pd.getName());
+
+ }
+
+}
Modified:
branches/enterprise/JBPAPP_5_0/src/test/unit/org/jboss/seam/test/unit/testng.xml
===================================================================
---
branches/enterprise/JBPAPP_5_0/src/test/unit/org/jboss/seam/test/unit/testng.xml 2010-06-03
12:31:43 UTC (rev 13011)
+++
branches/enterprise/JBPAPP_5_0/src/test/unit/org/jboss/seam/test/unit/testng.xml 2010-06-03
12:54:16 UTC (rev 13012)
@@ -24,6 +24,7 @@
<class name="org.jboss.seam.test.unit.bpm.ActorTest" />
<class name="org.jboss.seam.test.unit.bpm.TaskListTest" />
<class name="org.jboss.seam.test.unit.PageflowTest"/>
+ <class name="org.jboss.seam.test.unit.bpm.JbpmTest"/>
</classes>
</test>
Show replies by date