From c2e3c269ec87d9e3d474fac75661ce788fb37d27 Mon Sep 17 00:00:00 2001 From: Luis Martinez Date: Thu, 29 Mar 2018 18:08:01 -0400 Subject: [PATCH 1/2] Included search for wf:user on Inbox and added test for dynamicUser and inbox --- .../inclusive-gateway-01.xqy | 41 ++++++++++++++++++- .../test-data/InclusiveGatewayTest-01.bpmn | 12 +++++- src/workflowengine/models/workflow-util.xqy | 2 +- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/test/suites/inclusive-gateway/inclusive-gateway-01.xqy b/src/test/suites/inclusive-gateway/inclusive-gateway-01.xqy index a491ecb..bcaa038 100644 --- a/src/test/suites/inclusive-gateway/inclusive-gateway-01.xqy +++ b/src/test/suites/inclusive-gateway/inclusive-gateway-01.xqy @@ -37,7 +37,7 @@ declare namespace ext = "http://marklogic.com/rest-api/resource/process"; declare variable $PROCESS-MODEL-NAME := test-constants:expected-model-id($test-constants:TEST-01-MODEL-NAME); -let $payload := element ext:createRequest{element ext:processName{$PROCESS-MODEL-NAME},element ext:data{element value{"A"}},element ext:attachments{}} +let $payload := element ext:createRequest{element ext:processName{$PROCESS-MODEL-NAME},element ext:data{element value{"A"}, element assignTo{"admin"}},element ext:attachments{}} let $process-response := wrt:process-create($const:xml-options, $payload)[2] let $pid := $process-response/ext:createResponse/ext:processId/text() return @@ -70,6 +70,44 @@ test:assert-equal(xs:string($process-state/ext:outcome/text()),"SUCCESS"), test:assert-equal("InclusiveGateway_1",fn:tokenize($current-state,"/")[fn:last()]) ) ; + +(: test inbox lists wf:user processinbox-read :) +import module namespace test-constants = "http://marklogic.com/workflow/test-constants/inclusive-gateway" at "/test/suites/inclusive-gateway/lib/constants.xqy"; +import module namespace const="http://marklogic.com/roxy/workflow-constants" at "/test/workflow-constants.xqy"; +import module namespace wrt="http://marklogic.com/workflow/rest-tests" at "/test/workflow-rest-tests.xqy"; +import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +declare namespace cpf = "http://marklogic.com/cpf"; +declare namespace ext = "http://marklogic.com/rest-api/resource/processinbox"; +declare namespace http = "xdmp:http"; +declare namespace prop = "http://marklogic.com/xdmp/property"; +declare namespace wf="http://marklogic.com/workflow"; + +let $_pause := xdmp:sleep(10000) +let $test-pid := fn:doc(test-constants:test-pid-uri($test-constants:TEST-01-MODEL-NAME))/test-constants:pid/text() +let $child-pid := /wf:process[fn:matches(wf:parent,$test-pid)]/@id/fn:string() +let $result := wrt:test-08-processinbox-read($const:xml-options) +return ( + test:assert-equal('200', xs:string($result[1]/http:code)), + test:assert-equal('SUCCESS', xs:string($result[2]/ext:readResponse/ext:outcome)), + test:assert-exists($result[2]/ext:readResponse/wf:inbox/wf:task[@processid=$child-pid]), + let $task := $result[2]/ext:readResponse/wf:inbox/wf:task[@processid=$child-pid] + return ( + test:assert-exists($task/wf:process-data/wf:process/wf:data), + test:assert-exists($task/wf:process-data/wf:process/wf:attachments), + test:assert-exists($task/wf:process-data/wf:process/wf:audit-trail), + test:assert-exists($task/wf:process-data/wf:process/wf:metrics), + test:assert-exists($task/wf:process-data/wf:process/wf:process-definition-name), + let $properties := $task/wf:process-properties/prop:properties + return ( + test:assert-equal('done', xs:string($properties/cpf:processing-status)), + test:assert-equal('dynamicUser', xs:string($properties/wf:currentStep/wf:type)), + test:assert-equal('admin', xs:string($properties/wf:currentStep/wf:user)), + test:assert-equal('userTask', xs:string($properties/wf:currentStep/wf:step-type)), + test:assert-equal('ENTERED', xs:string($properties/wf:currentStep/wf:step-status)) + ) + ) +); + (: Fork has not rendezvoused because there is a user task requiring completion. We therefore complete it :) @@ -90,6 +128,7 @@ test:assert-equal(xs:string($update-response/ext:outcome/text()),"SUCCESS") (: Need to sleep to ensure asynchronous behaviour has completed :) xdmp:sleep(2000) ; + (: Check process has rendezvoused and completed :) diff --git a/src/test/suites/inclusive-gateway/test-data/InclusiveGatewayTest-01.bpmn b/src/test/suites/inclusive-gateway/test-data/InclusiveGatewayTest-01.bpmn index 5897ed1..9176d17 100644 --- a/src/test/suites/inclusive-gateway/test-data/InclusiveGatewayTest-01.bpmn +++ b/src/test/suites/inclusive-gateway/test-data/InclusiveGatewayTest-01.bpmn @@ -2,6 +2,8 @@ + + SequenceFlow_6 @@ -22,6 +24,12 @@ SequenceFlow_1 SequenceFlow_3 + + Resource_1 + + $wf:process/wf:data//assignTo/text() + + SequenceFlow_2 @@ -55,13 +63,13 @@ - + - + diff --git a/src/workflowengine/models/workflow-util.xqy b/src/workflowengine/models/workflow-util.xqy index 811bba3..7ac3ae4 100644 --- a/src/workflowengine/models/workflow-util.xqy +++ b/src/workflowengine/models/workflow-util.xqy @@ -203,7 +203,7 @@ declare function m:inbox($username as xs:string?) as element(wf:inbox) { (: TODO add cpf-active check, wf:status running check, wf:locked-user blank :) cts:properties-query( cts:element-query(xs:QName("wf:currentStep"), - cts:element-value-query(xs:QName("wf:assignee"),($username,xdmp:get-current-user())[1]) + cts:element-value-query( ( xs:QName("wf:user"), xs:QName("wf:assignee")),($username,xdmp:get-current-user())[1]) ) ) ),("unfiltered") (: TODO ordering, prioritisation support, and so on :) From 8cbf5449d6ab7f38f0a24f346af152c9fa0ecfd5 Mon Sep 17 00:00:00 2001 From: eouthwaite Date: Sun, 10 Jun 2018 11:17:42 +0100 Subject: [PATCH 2/2] Alter import to pick up user rather than assignee; additional tests and fixes for tests --- .../015-processmodel-json.xqy | 2 +- .../015-processmodel-xml.xqy | 14 ++++----- .../inclusive-gateway-01.xqy | 20 ++++++++----- .../inclusive-gateway-02.xqy | 29 +++++++++---------- .../inclusive-gateway/lib/constants.xqy | 2 +- .../inclusive-gateway/suite-teardown.xqy | 29 +++---------------- src/test/test-config.xqy | 4 +-- src/workflowengine/models/workflow-import.xqy | 2 +- 8 files changed, 42 insertions(+), 60 deletions(-) diff --git a/src/test/suites/e2e-rest-process-json/015-processmodel-json.xqy b/src/test/suites/e2e-rest-process-json/015-processmodel-json.xqy index 9831730..e5087e8 100644 --- a/src/test/suites/e2e-rest-process-json/015-processmodel-json.xqy +++ b/src/test/suites/e2e-rest-process-json/015-processmodel-json.xqy @@ -123,7 +123,7 @@ return ( return ( test:assert-equal('done', xs:string($properties/processingStatus)), test:assert-equal('user', xs:string($properties/currentStep/type)), - test:assert-equal('admin', xs:string($properties/currentStep/assignee)), + test:assert-equal('admin', xs:string($properties/currentStep/user)), test:assert-equal('userTask', xs:string($properties/currentStep/stepType)), test:assert-equal('ENTERED', xs:string($properties/currentStep/stepStatus)) ) diff --git a/src/test/suites/e2e-rest-process-xml/015-processmodel-xml.xqy b/src/test/suites/e2e-rest-process-xml/015-processmodel-xml.xqy index 9d30049..4d5fa43 100644 --- a/src/test/suites/e2e-rest-process-xml/015-processmodel-xml.xqy +++ b/src/test/suites/e2e-rest-process-xml/015-processmodel-xml.xqy @@ -10,10 +10,10 @@ declare namespace http = "xdmp:http"; let $process := wrt:processmodel-create ($const:xml-options, "015-restapi-tests.bpmn") let $_testlog := xdmp:log("E2E XML TEST: 01-processmodel-create") -return ( +return ( test:assert-equal('200', xs:string($process[1]/http:code)), test:assert-equal('SUCCESS', xs:string($process[2]/ext:createResponse/ext:outcome)), - test:assert-equal('015-restapi-tests__1__0', xs:string($process[2]/ext:createResponse/ext:modelId)) + test:assert-equal('015-restapi-tests__1__0', xs:string($process[2]/ext:createResponse/ext:modelId)) ); (: @@ -46,10 +46,10 @@ declare namespace http = "xdmp:http"; let $result := wrt:test-03-processmodel-update($const:xml-options) let $_testlog := xdmp:log("E2E XML TEST: 03-processmodel-update") -return ( +return ( test:assert-equal('200', xs:string($result[1]/http:code)), test:assert-equal('SUCCESS', xs:string($result[2]/ext:createResponse/ext:outcome)), - test:assert-equal('015-restapi-tests__1__2', xs:string($result[2]/ext:createResponse/ext:modelId)) + test:assert-equal('015-restapi-tests__1__2', xs:string($result[2]/ext:createResponse/ext:modelId)) ); (: @@ -68,10 +68,10 @@ declare namespace http = "xdmp:http"; let $_testlog := xdmp:log("E2E XML TEST: 04-processmodel-publish") (: not working with XML ? :) let $result := wrt:processmodel-publish($const:xml-options, "015-restapi-tests__1__2") -return ( +return ( test:assert-equal('200', xs:string($result[1]/http:code)), test:assert-equal('SUCCESS', xs:string($result[2]/ext:updateResponse/ext:outcome)), - test:assert-exists(xs:string($result[2]/ext:updateResponse/ext:domainId)) + test:assert-exists(xs:string($result[2]/ext:updateResponse/ext:domainId)) ); (: @@ -153,7 +153,7 @@ return ( return ( test:assert-equal('done', xs:string($properties/cpf:processing-status)), test:assert-equal('user', xs:string($properties/wf:currentStep/wf:type)), - test:assert-equal('admin', xs:string($properties/wf:currentStep/wf:assignee)), + test:assert-equal('admin', xs:string($properties/wf:currentStep/wf:user)), test:assert-equal('userTask', xs:string($properties/wf:currentStep/wf:step-type)), test:assert-equal('ENTERED', xs:string($properties/wf:currentStep/wf:step-status)) ) diff --git a/src/test/suites/inclusive-gateway/inclusive-gateway-01.xqy b/src/test/suites/inclusive-gateway/inclusive-gateway-01.xqy index bcaa038..25ea504 100644 --- a/src/test/suites/inclusive-gateway/inclusive-gateway-01.xqy +++ b/src/test/suites/inclusive-gateway/inclusive-gateway-01.xqy @@ -1,7 +1,7 @@ (: - This test checks that for an inclusive gateway with two downstream routes, only one of which is activated, + This test checks that for an inclusive gateway with two downstream routes, only one of which is activated, rendezvousing is conditional only on the activated task being completed. -:) +:) (: Create process model for Inclusive Gateway Test 01, and check it has been created correctly :) @@ -23,7 +23,7 @@ return ( test:assert-equal(xs:string($model-response/model:createResponse/model:outcome/text()),"SUCCESS"), test:assert-equal(xs:string($model-response/model:createResponse/model:modelId/text()),test-constants:expected-model-id($test-constants:TEST-01-MODEL-NAME)) -) +) ; (: Create process for Inclusive Gateway Test 01. Check success. Check pid exists and save. @@ -48,7 +48,7 @@ return ) ; (: Need to sleep to ensure asynchronous behaviour has completed :) -xdmp:sleep(2000) +xdmp:sleep(5000) ; (: Check process has entered the first gateway ( and effectively stopped there ) @@ -66,10 +66,13 @@ let $process-state := wrt:process-read($const:xml-options,$test-pid)[2]/ext:read let $current-state := ($process-state/ext:document/wf:process/wf:audit-trail/wf:audit)[fn:last()]/wf:state/text() return ( -test:assert-equal(xs:string($process-state/ext:outcome/text()),"SUCCESS"), -test:assert-equal("InclusiveGateway_1",fn:tokenize($current-state,"/")[fn:last()]) + test:assert-equal(xs:string($process-state/ext:outcome/text()),"SUCCESS"), + test:assert-equal("InclusiveGateway_1",fn:tokenize($current-state,"/")[fn:last()]) ) ; +(: Need to sleep to ensure asynchronous behaviour has completed :) +xdmp:sleep(10000) +; (: test inbox lists wf:user processinbox-read :) import module namespace test-constants = "http://marklogic.com/workflow/test-constants/inclusive-gateway" at "/test/suites/inclusive-gateway/lib/constants.xqy"; @@ -82,8 +85,8 @@ declare namespace http = "xdmp:http"; declare namespace prop = "http://marklogic.com/xdmp/property"; declare namespace wf="http://marklogic.com/workflow"; -let $_pause := xdmp:sleep(10000) let $test-pid := fn:doc(test-constants:test-pid-uri($test-constants:TEST-01-MODEL-NAME))/test-constants:pid/text() +let $test-pid := fn:substring-before($test-pid, "+") (: some platforms not handling timezone well :) let $child-pid := /wf:process[fn:matches(wf:parent,$test-pid)]/@id/fn:string() let $result := wrt:test-08-processinbox-read($const:xml-options) return ( @@ -120,10 +123,11 @@ declare namespace wf = "http://marklogic.com/workflow"; declare namespace ext = "http://marklogic.com/rest-api/resource/process"; let $test-pid := fn:doc(test-constants:test-pid-uri($test-constants:TEST-01-MODEL-NAME))/test-constants:pid/text() +let $test-pid := fn:substring-before($test-pid, "+") (: some platforms not handling timezone well :) let $child-pid := /wf:process[fn:matches(wf:parent,$test-pid)]/@id/fn:string() let $update-response := wrt:call-complete-on-pid($const:xml-options,$child-pid)/ext:updateResponse return -test:assert-equal(xs:string($update-response/ext:outcome/text()),"SUCCESS") + test:assert-equal(xs:string($update-response/ext:outcome/text()),"SUCCESS") ; (: Need to sleep to ensure asynchronous behaviour has completed :) xdmp:sleep(2000) diff --git a/src/test/suites/inclusive-gateway/inclusive-gateway-02.xqy b/src/test/suites/inclusive-gateway/inclusive-gateway-02.xqy index 98cc4c2..9de34e3 100644 --- a/src/test/suites/inclusive-gateway/inclusive-gateway-02.xqy +++ b/src/test/suites/inclusive-gateway/inclusive-gateway-02.xqy @@ -22,7 +22,7 @@ return ( test:assert-equal(xs:string($model-response/model:createResponse/model:outcome/text()),"SUCCESS"), test:assert-equal(xs:string($model-response/model:createResponse/model:modelId/text()),test-constants:expected-model-id($test-constants:TEST-02-MODEL-NAME)) -) +) ; (: Create process for Inclusive Gateway Test 02. Check success. Check pid exists and save. @@ -47,9 +47,7 @@ return ) ; (: Need to sleep to ensure asynchronous behaviour has completed :) -import module namespace test-config = "http://marklogic.com/roxy/test-config" at "/test/test-config.xqy"; - -test-config:test-sleep() +xdmp:sleep(10000) ; (: Check process has entered the first gateway ( and effectively stopped there ) @@ -67,10 +65,9 @@ let $process-state := wrt:process-read($const:xml-options,$test-pid)[2]/ext:read let $current-state := ($process-state/ext:document/wf:process/wf:audit-trail/wf:audit)[fn:last()]/wf:state/text() return ( -test:assert-equal(xs:string($process-state/ext:outcome/text()),"SUCCESS"), -test:assert-equal("InclusiveGateway_1",fn:tokenize($current-state,"/")[fn:last()]) -) -; + test:assert-equal("SUCCESS", xs:string($process-state/ext:outcome/text())), + test:assert-equal("InclusiveGateway_1", fn:tokenize($current-state,"/")[fn:last()]) +); (: Fork has not rendezvoused because there are user tasks requiring completion. We complete the first one. :) @@ -83,10 +80,11 @@ declare namespace wf = "http://marklogic.com/workflow"; declare namespace ext = "http://marklogic.com/rest-api/resource/process"; let $test-pid := fn:doc(test-constants:test-pid-uri($test-constants:TEST-02-MODEL-NAME))/test-constants:pid/text() +let $test-pid := fn:substring-before($test-pid, "+") (: some platforms not handling timezone well :) let $child-pid := (/wf:process[fn:matches(wf:parent,$test-pid)]/@id/fn:string())[1] let $update-response := wrt:call-complete-on-pid($const:xml-options,$child-pid)/ext:updateResponse return -test:assert-equal(xs:string($update-response/ext:outcome/text()),"SUCCESS") + test:assert-equal(xs:string($update-response/ext:outcome/text()),"SUCCESS") ; (: Need to sleep to ensure asynchronous behaviour has completed :) import module namespace test-config = "http://marklogic.com/roxy/test-config" at "/test/test-config.xqy"; @@ -110,8 +108,8 @@ let $penultimate-state := ($process-state/ext:document/wf:process/wf:audit-trail let $current-state := ($process-state/ext:document/wf:process/wf:audit-trail/wf:audit)[fn:last()]/wf:state/text() return ( -test:assert-equal(xs:string($process-state/ext:outcome/text()),"SUCCESS"), -test:assert-equal("InclusiveGateway_1",fn:tokenize($current-state,"/")[fn:last()]) + test:assert-equal(xs:string($process-state/ext:outcome/text()),"SUCCESS"), + test:assert-equal("InclusiveGateway_1",fn:tokenize($current-state,"/")[fn:last()]) ) ; (: @@ -126,10 +124,11 @@ declare namespace wf = "http://marklogic.com/workflow"; declare namespace ext = "http://marklogic.com/rest-api/resource/process"; let $test-pid := fn:doc(test-constants:test-pid-uri($test-constants:TEST-02-MODEL-NAME))/test-constants:pid/text() +let $test-pid := fn:substring-before($test-pid, "+") (: some platforms not handling timezone well :) let $child-pid := (/wf:process[fn:matches(wf:parent,$test-pid)]/@id/fn:string())[2] let $update-response := wrt:call-complete-on-pid($const:xml-options,$child-pid)/ext:updateResponse return -test:assert-equal(xs:string($update-response/ext:outcome/text()),"SUCCESS") + test:assert-equal(xs:string($update-response/ext:outcome/text()),"SUCCESS") ; (: Need to sleep to ensure asynchronous behaviour has completed :) import module namespace test-config = "http://marklogic.com/roxy/test-config" at "/test/test-config.xqy"; @@ -153,8 +152,8 @@ let $penultimate-state := ($process-state/ext:document/wf:process/wf:audit-trail let $current-state := ($process-state/ext:document/wf:process/wf:audit-trail/wf:audit)[fn:last()]/wf:state/text() return ( -test:assert-equal(xs:string($process-state/ext:outcome/text()),"SUCCESS"), -test:assert-equal("EndEvent_1",fn:tokenize($current-state,"/")[fn:last()]), -test:assert-equal("InclusiveGateway_1__rv",fn:tokenize($penultimate-state,"/")[fn:last()]) + test:assert-equal(xs:string($process-state/ext:outcome/text()),"SUCCESS"), + test:assert-equal("EndEvent_1",fn:tokenize($current-state,"/")[fn:last()]), + test:assert-equal("InclusiveGateway_1__rv",fn:tokenize($penultimate-state,"/")[fn:last()]) ) ; diff --git a/src/test/suites/inclusive-gateway/lib/constants.xqy b/src/test/suites/inclusive-gateway/lib/constants.xqy index 4dc6fcb..f0b20cc 100644 --- a/src/test/suites/inclusive-gateway/lib/constants.xqy +++ b/src/test/suites/inclusive-gateway/lib/constants.xqy @@ -23,6 +23,6 @@ declare function test-pid-uri($model-name as xs:string) as xs:string{ declare function save-pid($pid,$model-name){ let $pid-content := element test-constants:pid{$pid} return - xdmp:document-insert(test-pid-uri($model-name),$pid-content) + xdmp:document-insert(test-pid-uri($model-name),$pid-content) }; diff --git a/src/test/suites/inclusive-gateway/suite-teardown.xqy b/src/test/suites/inclusive-gateway/suite-teardown.xqy index 95ddbff..7df5503 100644 --- a/src/test/suites/inclusive-gateway/suite-teardown.xqy +++ b/src/test/suites/inclusive-gateway/suite-teardown.xqy @@ -1,26 +1,5 @@ -import module namespace test-constants = "http://marklogic.com/workflow/test-constants/inclusive-gateway" at "/test/suites/inclusive-gateway/lib/constants.xqy"; -import module namespace const="http://marklogic.com/roxy/workflow-constants" at "/test/workflow-constants.xqy"; -import module namespace wrt="http://marklogic.com/workflow/rest-tests" at "/test/workflow-rest-tests.xqy"; -import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; - -declare namespace ext = "http://marklogic.com/rest-api/resource/process"; -declare namespace wf = "http://marklogic.com/workflow"; -declare namespace p = "http://marklogic.com/cpf/pipelines"; - - -for $process-model-name in $test-constants:TEST-MODEL-NAMES -return +xquery version "1.0-ml"; ( - (: Delete processes generated by these tests :) - /wf:process[wf:process-definition-name = $process-model-name] ! xdmp:document-delete(fn:base-uri(.)), - (: Remove children of these processes :) - let $test-pid := fn:doc(test-constants:test-pid-uri($process-model-name))/test-constants:pid/text() - return - /wf:process[fn:matches(wf:process-definition-name,$process-model-name)] ! xdmp:document-delete(fn:base-uri(.)), - (: Delete test pid document :) - xdmp:document-delete(test-constants:test-pid-uri($process-model-name)), - (: Delete model files :) - cts:uris()[fn:matches(.,test-constants:file-name-for-model($process-model-name))] ! xdmp:document-delete(.), - (: Delete associated pipelines :) - //p:pipeline-name[fn:matches(.,$process-model-name)] ! xdmp:document-delete(fn:base-uri(.)) -) \ No newline at end of file + xdmp:directory-delete("/"), + xdmp:collection-delete("http://marklogic.com/cpf/pipelines") +) diff --git a/src/test/test-config.xqy b/src/test/test-config.xqy index 3972d59..01ce958 100644 --- a/src/test/test-config.xqy +++ b/src/test/test-config.xqy @@ -26,9 +26,9 @@ declare variable $LOCAL-TEST-DATA-DIR := "/raw/bpmn/"; declare variable $SLEEP-FOR-ASYNC := 5; (: Sleep period required, in seconds, for async tasks :) declare function local-uri-for-test-file($test-file-name as xs:string){ - $LOCAL-TEST-DATA-DIR||$test-file-name + $LOCAL-TEST-DATA-DIR||$test-file-name }; declare function test-sleep(){ xdmp:sleep($SLEEP-FOR-ASYNC * 1000) -}; \ No newline at end of file +}; diff --git a/src/workflowengine/models/workflow-import.xqy b/src/workflowengine/models/workflow-import.xqy index ca3c27d..0ef8812 100644 --- a/src/workflowengine/models/workflow-import.xqy +++ b/src/workflowengine/models/workflow-import.xqy @@ -1070,7 +1070,7 @@ declare function m:b2userTask($rootName as xs:string,$parentStep as xs:string?,$ {$type} { - if (fn:not(fn:empty($user))) then {$user} else () + if (fn:not(fn:empty($user))) then {$user} else () } { if (fn:not(fn:empty($queue))) then {$queue} else ()