Skip to content

Commit

Permalink
issue imixs#115
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoika committed Mar 5, 2016
1 parent 48017ed commit 54dfbba
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 49 deletions.
18 changes: 9 additions & 9 deletions imixs-workflow-core/src/test/resources/bpmn/message_example.bpmn
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<bpmn2:incoming>SequenceFlow_2</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_3</bpmn2:outgoing>
</bpmn2:task>
<bpmn2:intermediateThrowEvent id="IntermediateThrowEvent_1" imixs:activityid="10" name="submit">
<bpmn2:intermediateCatchEvent id="IntermediateCatchEvent_1" imixs:activityid="10" name="submit">
<bpmn2:extensionElements>
<imixs:item name="txtmailsubject" type="xs:string">
<imixs:value><![CDATA[Some Message<bpmn2:message>Message-2</bpmn2:message>]]></imixs:value>
Expand All @@ -36,16 +36,16 @@ This is some message
</bpmn2:extensionElements>
<bpmn2:incoming>SequenceFlow_3</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_4</bpmn2:outgoing>
</bpmn2:intermediateThrowEvent>
</bpmn2:intermediateCatchEvent>
<bpmn2:sequenceFlow id="SequenceFlow_2" sourceRef="StartEvent_1" targetRef="Task_1"/>
<bpmn2:sequenceFlow id="SequenceFlow_3" sourceRef="Task_1" targetRef="IntermediateThrowEvent_1"/>
<bpmn2:sequenceFlow id="SequenceFlow_4" sourceRef="IntermediateThrowEvent_1" targetRef="Task_3"/>
<bpmn2:sequenceFlow id="SequenceFlow_3" sourceRef="Task_1" targetRef="IntermediateCatchEvent_1"/>
<bpmn2:sequenceFlow id="SequenceFlow_4" sourceRef="IntermediateCatchEvent_1" targetRef="Task_3"/>
<bpmn2:task id="Task_3" imixs:processid="1100" name="Task 2">
<bpmn2:incoming>SequenceFlow_4</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
</bpmn2:task>
<bpmn2:sequenceFlow id="SequenceFlow_1" sourceRef="Task_3" targetRef="EndEvent_1"/>
<bpmn2:association id="Association_1" sourceRef="Message_2" targetRef="IntermediateThrowEvent_1"/>
<bpmn2:association id="Association_1" sourceRef="Message_2" targetRef="IntermediateCatchEvent_1"/>
<bpmn2:association id="Association_2" sourceRef="Message_1" targetRef="Message_2"/>
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1" name="Default Process Diagram">
Expand All @@ -68,7 +68,7 @@ This is some message
<dc:Bounds height="14.0" width="36.0" x="257.0" y="111.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_IntermediateThrowEvent_1" bpmnElement="IntermediateThrowEvent_1">
<bpmndi:BPMNShape id="BPMNShape_IntermediateCatchEvent_1" bpmnElement="IntermediateCatchEvent_1">
<dc:Bounds height="36.0" width="36.0" x="392.0" y="100.0"/>
<bpmndi:BPMNLabel id="BPMNLabel_7">
<dc:Bounds height="14.0" width="38.0" x="391.0" y="136.0"/>
Expand Down Expand Up @@ -98,20 +98,20 @@ This is some message
<di:waypoint xsi:type="dc:Point" x="220.0" y="118.0"/>
<bpmndi:BPMNLabel id="BPMNLabel_8"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_3" bpmnElement="SequenceFlow_3" sourceElement="BPMNShape_Task_1" targetElement="BPMNShape_IntermediateThrowEvent_1">
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_3" bpmnElement="SequenceFlow_3" sourceElement="BPMNShape_Task_1" targetElement="BPMNShape_IntermediateCatchEvent_1">
<di:waypoint xsi:type="dc:Point" x="330.0" y="118.0"/>
<di:waypoint xsi:type="dc:Point" x="361.0" y="118.0"/>
<di:waypoint xsi:type="dc:Point" x="361.0" y="118.0"/>
<di:waypoint xsi:type="dc:Point" x="392.0" y="118.0"/>
<bpmndi:BPMNLabel id="BPMNLabel_9"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_4" bpmnElement="SequenceFlow_4" sourceElement="BPMNShape_IntermediateThrowEvent_1" targetElement="BPMNShape_Task_2">
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_4" bpmnElement="SequenceFlow_4" sourceElement="BPMNShape_IntermediateCatchEvent_1" targetElement="BPMNShape_Task_2">
<di:waypoint xsi:type="dc:Point" x="428.0" y="118.0"/>
<di:waypoint xsi:type="dc:Point" x="445.0" y="118.0"/>
<di:waypoint xsi:type="dc:Point" x="463.0" y="118.0"/>
<bpmndi:BPMNLabel id="BPMNLabel_10"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_Association_1" bpmnElement="Association_1" sourceElement="BPMNShape_Message_2" targetElement="BPMNShape_IntermediateThrowEvent_1">
<bpmndi:BPMNEdge id="BPMNEdge_Association_1" bpmnElement="Association_1" sourceElement="BPMNShape_Message_2" targetElement="BPMNShape_IntermediateCatchEvent_1">
<di:waypoint xsi:type="dc:Point" x="410.0" y="31.0"/>
<di:waypoint xsi:type="dc:Point" x="410.0" y="65.0"/>
<di:waypoint xsi:type="dc:Point" x="410.0" y="100.0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public abstract class AbstractPlugin implements Plugin {

public WorkflowContext ctx;

private static Logger logger = Logger.getLogger(AbstractPlugin.class.getName());

public static final String INVALID_ITEMVALUE_FORMAT = "INVALID_ITEMVALUE_FORMAT";
public void init(WorkflowContext actx) throws PluginException {
ctx = actx;
}
Expand Down Expand Up @@ -94,7 +94,7 @@ public void init(WorkflowContext actx) throws PluginException {
*
*
*/
public String replaceDynamicValues(String aString, ItemCollection documentContext) {
public String replaceDynamicValues(String aString, ItemCollection documentContext) throws PluginException {
int iTagStartPos;
int iTagEndPos;
int iContentStartPos;
Expand All @@ -114,8 +114,10 @@ public String replaceDynamicValues(String aString, ItemCollection documentContex

// if no end tag found return string unchanged...
if (iTagEndPos == -1) {
logger.warning("[AbstractPlugin] invalid text string format: " + aString);
break;
throw new PluginException(
this.getClass().getSimpleName(),
INVALID_ITEMVALUE_FORMAT,
"[AbstractPlugin] invalid itemvalue format: "+aString);
}

// reset pos vars
Expand All @@ -133,8 +135,10 @@ public String replaceDynamicValues(String aString, ItemCollection documentContex

// if no end tag found return string unchanged...
if (iContentStartPos >= iContentEndPos) {
logger.warning("[AbstractPlugin] invalid text string format: " + aString);
break;
throw new PluginException(
this.getClass().getSimpleName(),
INVALID_ITEMVALUE_FORMAT,
"[AbstractPlugin] invalid itemvalue format: "+aString);
}

iTagEndPos = iTagEndPos + "</itemvalue>".length();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public abstract class AbstractPlugin extends
org.imixs.workflow.plugins.AbstractPlugin {
javax.ejb.SessionContext ejbSessionContext;

public static final String INVALID_PROPERTYVALUE_FORMAT = "INVALID_PROPERTYVALUE_FORMAT";

PropertyService propertyService = null;
private static Logger logger = Logger.getLogger(AbstractPlugin.class
.getName());
Expand Down Expand Up @@ -131,12 +133,13 @@ public void setEjbSessionContext(javax.ejb.SessionContext ejbSessionContext) {
* <code>
* hello <propertyvalue>myCustomKey</propertyvalue>
* </code>
* @throws PluginException
*
*
*/
@Override
public String replaceDynamicValues(String aString,
ItemCollection documentContext) {
ItemCollection documentContext) throws PluginException {

int iTagStartPos;
int iTagEndPos;
Expand All @@ -159,9 +162,10 @@ public String replaceDynamicValues(String aString,

// if no end tag found return string unchanged...
if (iTagEndPos == -1) {
logger.warning("[AbstractPlugin] invalid text string format: "
+ aString);
break;
throw new PluginException(
this.getClass().getSimpleName(),
INVALID_PROPERTYVALUE_FORMAT,
"[AbstractPlugin] invalid propertyvalue format: "+aString);
}

// reset pos vars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,10 @@ public String getReplyTo(ItemCollection documentContext,
* @param documentContext
* @param documentActivity
* @return String - mail subject
* @throws PluginException
*/
public String getSubject(ItemCollection documentContext,
ItemCollection documentActivity) {
ItemCollection documentActivity) throws PluginException {

String subject = replaceDynamicValues(
documentActivity.getItemValueString("txtMailSubject"),
Expand Down Expand Up @@ -438,9 +439,10 @@ public List<String> getRecipientsBCC(ItemCollection documentContext,
* @param documentContext
* @param documentActivity
* @return String - mail subject
* @throws PluginException
*/
public String getBody(ItemCollection documentContext,
ItemCollection documentActivity) {
ItemCollection documentActivity) throws PluginException {
// build mail body and replace dynamic values...
String aBodyText = replaceDynamicValues(
documentActivity.getItemValueString("rtfMailBody"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,88 @@
import java.util.Vector;
import java.util.logging.Logger;

import junit.framework.Assert;

import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.Plugin;
import org.imixs.workflow.exceptions.PluginException;
import org.junit.Before;
import org.junit.Test;

import junit.framework.Assert;

/**
* Test the replaceDynamicValues method of abstractPugin
*
* @author rsoika
*
*/
public class TestAbstractPlugin extends AbstractPlugin {
public class TestAbstractPlugin {
public ItemCollection documentContext;
public ItemCollection documentActivity;
private final static Logger logger = Logger
.getLogger(TestAbstractPlugin.class.getName());
private final static Logger logger = Logger.getLogger(TestAbstractPlugin.class.getName());

@Before
public void setup() throws PluginException {

}

/**
* Test replacement of dynamic item values
*
* <itemvalue>xxx</itemvalue>
* @throws PluginException
*
*/
@Test
public void testReplaceDynamicValues() throws PluginException {

String testString = "Hello <itemvalue>txtname</itemvalue>!";
String expectedString = "Hello Anna!";

TestPlugin applicationPlugin = new TestPlugin();

// prepare data
logger.info("[TestAbstractPlugin] setup test data...");
documentContext = new ItemCollection();
documentContext.replaceItemValue("txtName", "Anna");

String resultString = applicationPlugin.replaceDynamicValues(testString, documentContext);

Assert.assertEquals(expectedString, resultString);

}

/**
* Test replacement of dynamic item values with a format error
*
* @see issue #115
*/
@SuppressWarnings("unused")
@Test
public void testReplaceDynamicValuesFormatError() {

String testString = "Hello <itemvalue>txtname!";
String expectedString = "Hello Anna!";

TestPlugin applicationPlugin = new TestPlugin();

// prepare data
logger.info("[TestAbstractPlugin] setup test data...");
documentContext = new ItemCollection();
documentContext.replaceItemValue("txtName", "Anna");

String resultString=null;
try {
resultString = applicationPlugin.replaceDynamicValues(testString, documentContext);
Assert.fail();
} catch (PluginException e) {
// expected
Assert.assertNull(resultString);
}

// test wrong embeded tags...

}


/**
* Test format string:
*
Expand All @@ -37,15 +94,16 @@ public void setup() throws PluginException {
* <itemvalue format="EEEE, d. MMMM yyyy">datdate</itemvalue>
*
* </code>
* @throws PluginException
*
*/
@Test
public void testDateFormat() {
public void testDateFormat() throws PluginException {

String testString = "The Date is: <itemvalue format=\"EEEE, d. MMMM yyyy\" locale=\"de_DE\">datdate</itemvalue>.";
String expectedString = "The Date is: Sonntag, 27. April 2014.";

ApplicationPlugin applicationPlugin = new ApplicationPlugin();
TestPlugin applicationPlugin = new TestPlugin();

// prepare data
documentContext = new ItemCollection();
Expand All @@ -58,20 +116,19 @@ public void testDateFormat() {

documentContext.replaceItemValue("datDate", cal.getTime());

String resultString = applicationPlugin.replaceDynamicValues(
testString, documentContext);
String resultString = applicationPlugin.replaceDynamicValues(testString, documentContext);

Assert.assertEquals(expectedString, resultString);

}

@Test
public void testDateFormatEN() {
public void testDateFormatEN() throws PluginException {

String testString = "The Date is: <itemvalue locale=\"en_EN\" format=\"EEEE, d. MMMM yyyy\">datdate</itemvalue>.";
String expectedString = "The Date is: Sunday, 27. April 2014.";

ApplicationPlugin applicationPlugin = new ApplicationPlugin();
TestPlugin applicationPlugin = new TestPlugin();

// prepare data
documentContext = new ItemCollection();
Expand All @@ -84,8 +141,7 @@ public void testDateFormatEN() {

documentContext.replaceItemValue("datDate", cal.getTime());

String resultString = applicationPlugin.replaceDynamicValues(
testString, documentContext);
String resultString = applicationPlugin.replaceDynamicValues(testString, documentContext);

Assert.assertEquals(expectedString, resultString);

Expand All @@ -99,15 +155,16 @@ public void testDateFormatEN() {
* <itemvalue separator="/">_numbers</itemvalue>
*
* </code>
* @throws PluginException
*
*/
@Test
public void testMultiValueFormat() {
public void testMultiValueFormat() throws PluginException {

String testString = "The Valuelist is: <itemvalue separator=\"/\">_numbers</itemvalue>.";
String expectedString = "The Valuelist is: 1/20/300.";

ApplicationPlugin applicationPlugin = new ApplicationPlugin();
TestPlugin applicationPlugin = new TestPlugin();

// prepare data
documentContext = new ItemCollection();
Expand All @@ -119,23 +176,30 @@ public void testMultiValueFormat() {
value.add(300);
documentContext.replaceItemValue("_numbers", value);

String resultString = applicationPlugin.replaceDynamicValues(
testString, documentContext);
String resultString = applicationPlugin.replaceDynamicValues(testString, documentContext);

Assert.assertEquals(expectedString, resultString);

}

@Override
public int run(ItemCollection documentContext,
ItemCollection documentActivity) throws PluginException {
/**
* This is a test plugin extending the AbstractPlugion to be used for
* several tests in this jUnit test only
*
* @author rsoika
*
*/
class TestPlugin extends AbstractPlugin {

return Plugin.PLUGIN_OK;
}
@Override
public int run(ItemCollection documentContext, ItemCollection documentActivity) throws PluginException {
return PLUGIN_OK;
}

@Override
public void close(int status) throws PluginException {
@Override
public void close(int status) throws PluginException {
// no op
}

}

}
Loading

0 comments on commit 54dfbba

Please sign in to comment.