Skip to content

Commit

Permalink
refactoring junit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoika committed Jun 7, 2018
1 parent 4315ba8 commit 3ba8ca7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void testACLNoUpdate() throws ModelException {
public void testACLfromProcessEntity() throws ModelException {

documentActivity = workflowMockEnvironment.getModel().getEvent(300, 10);
documentContext.replaceItemValue("$processid", 300);
documentContext.setTaskID(300);

try {
accessPlugin.run(documentContext, documentActivity);
Expand Down Expand Up @@ -183,7 +183,7 @@ public void testACLfromProcessEntityAndActivityEntity() throws ModelException {
list.add("Kevin");
list.add("Julian");
documentContext.replaceItemValue("namOwner", list);
documentContext.replaceItemValue("$processid", 300);
documentContext.setTaskID(300);

documentActivity = workflowMockEnvironment.getModel().getEvent(300, 20);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testOwnerNoUpdate() throws ModelException {
list.add("Kevin");
list.add("Julian");
documentContext.replaceItemValue("namowner", list);
documentContext.replaceItemValue("$processid", 100);
documentContext.setTaskID(100);

documentActivity = workflowMockEnvironment.getModel().getEvent(100, 10);
try {
Expand Down Expand Up @@ -149,7 +149,7 @@ public void testOwnerfromActivityEntity() throws ModelException {
public void testOwnerfromProcessEntity() throws ModelException {

documentActivity = workflowMockEnvironment.getModel().getEvent(300, 10);
documentContext.replaceItemValue("$processid", 300);
documentContext.setTaskID(300);

try {
ownerPlugin.run(documentContext, documentActivity);
Expand Down Expand Up @@ -184,7 +184,7 @@ public void testOwnerfromProcessEntityAndActivityEntity() throws ModelException
list.add("Kevin");
list.add("Julian");
documentContext.replaceItemValue("namOwner", list);
documentContext.replaceItemValue("$processid", 300);
documentContext.setTaskID(300);

documentActivity = workflowMockEnvironment.getModel().getEvent(300, 20);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,32 @@ public void testSimpleWorkitemScript() throws ScriptException, PluginException {

ItemCollection adocumentContext = new ItemCollection();
adocumentContext.replaceItemValue("txtName", "Anna");
adocumentContext.replaceItemValue("$ProcessID", 1000);
adocumentContext.setTaskID(1000);
// simulate an activity
ItemCollection adocumentActivity = new ItemCollection();
adocumentActivity.replaceItemValue("keyMailEnabled", "1");

// set a business rule
String script = "var isValid = 1000==workitem.get('$taskid')[0];";

System.out.println("Script=" + script);
adocumentActivity.replaceItemValue("txtBusinessRUle", script);

// run plugin
adocumentContext = rulePlugin.run(adocumentContext, adocumentActivity);
Assert.assertNotNull(adocumentContext);

}

/**
* Same test as before but using the deprected item $processid
*/
@Test
public void testSimpleWorkitemScriptWithDeprecatedField() throws ScriptException, PluginException {

ItemCollection adocumentContext = new ItemCollection();
adocumentContext.replaceItemValue("txtName", "Anna");
adocumentContext.setTaskID(1000);
// simulate an activity
ItemCollection adocumentActivity = new ItemCollection();
adocumentActivity.replaceItemValue("keyMailEnabled", "1");
Expand Down Expand Up @@ -899,14 +924,14 @@ public void testUpdateActivityByScript() throws ScriptException, PluginException

ItemCollection adocumentContext = new ItemCollection();
adocumentContext.replaceItemValue("txtName", "Anna");
adocumentContext.replaceItemValue("$ProcessID", 1000);
adocumentContext.setTaskID(1000);
// simulate an activity
ItemCollection adocumentActivity = new ItemCollection();
adocumentActivity.replaceItemValue("keyMailEnabled", "1");

// set a business rule
String script = "";
script += "var isValid = 1000==workitem['$processid'][0];";
script += "var isValid = 1000==workitem['$taskid'][0];";
// now add a manipulation!
script += " event.keymailenabled='0';";

Expand All @@ -919,7 +944,7 @@ public void testUpdateActivityByScript() throws ScriptException, PluginException
adocumentContext = rulePlugin.run(adocumentContext, adocumentActivity);
Assert.assertNotNull(adocumentContext);

Assert.assertEquals(1000, adocumentContext.getItemValueInteger("$ProcessID"));
Assert.assertEquals(1000, adocumentContext.getTaskID());

// test manipulation of activity
Assert.assertEquals("0", adocumentActivity.getItemValueString("keyMailEnabled"));
Expand Down

0 comments on commit 3ba8ca7

Please sign in to comment.