Skip to content
This repository was archived by the owner on Nov 9, 2022. It is now read-only.

Commit 022d70b

Browse files
committed
Merge branch 'develop' into develop-9.0 - fixes for #54 and process deletion
2 parents 96e0751 + 8dc382b commit 022d70b

File tree

16 files changed

+718
-18
lines changed

16 files changed

+718
-18
lines changed

rest-api/ext/process.xqy

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,8 @@ declare
270270
%roxy:params("")
271271
function ext:delete(
272272
$context as map:map,
273-
$params as map:map,
274-
$input as document-node()*
275-
) as document-node()* {
273+
$params as map:map
274+
) as document-node()? {
276275

277276
let $preftype := if ("application/xml" = map:get($context,"accept-types")) then "application/xml" else "application/json"
278277

@@ -283,7 +282,7 @@ function ext:delete(
283282
return
284283
(
285284
map:put($context, "output-types", $preftype),
286-
xdmp:set-response-code(200, "OK"),
285+
map:put($context,"output-status",(200, "OK")),
287286
document {()}
288287
)
289288
};

rest-api/ext/processsubscription.xqy

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,22 @@ function ext:get(
8888

8989
let $_ := xdmp:log($params)
9090
let $_ := xdmp:log($context)
91-
91+
let $subscription-name := map:get($params,"name")
9292
let $out :=
93-
if (fn:empty(map:get($params,"name"))) then
93+
if (fn:empty($subscription-name)) then
9494
<ext:readResponse><ext:outcome>FAILURE</ext:outcome><ext:details>name parameter is required</ext:details></ext:readResponse>
9595
else
96-
<ext:readResponse><ext:outcome>SUCCESS</ext:outcome>
96+
let $subscription := wfu:getSubscription($subscription-name)
97+
return
98+
if(fn:empty($subscription)) then
99+
<ext:readResponse><ext:outcome>NOT FOUND</ext:outcome></ext:readResponse>
100+
else
101+
<ext:readResponse>
102+
<ext:outcome>SUCCESS</ext:outcome>
97103
<ext:subscription>
98-
{wfu:getSubscription(map:get($params,"name"))}
104+
{$subscription}
99105
</ext:subscription>
100106
</ext:readResponse>
101-
102107
return
103108
(
104109
xdmp:set-response-code(200, "OK"),
@@ -114,3 +119,27 @@ function ext:get(
114119
}
115120
)
116121
};
122+
123+
124+
declare
125+
%roxy:params("")
126+
function ext:delete(
127+
$context as map:map,
128+
$params as map:map
129+
) as document-node()? {
130+
131+
let $preftype := if ("application/xml" = map:get($context,"accept-types")) then "application/xml" else "application/json"
132+
133+
let $subscription-name := map:get($params,"name")
134+
let $_ := xdmp:log("REST Subscription name: " || $subscription-name)
135+
let $_ := wfu:removeSubscription($subscription-name)
136+
137+
return
138+
(
139+
map:put($context,"output-types", $preftype),
140+
map:put($context,"output-status",(204, "NOT FOUND")),
141+
document {()}
142+
)
143+
144+
};
145+

src/test/suites/inclusive-gateway/suite-teardown.xqy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ return
1414
(: Delete processes generated by these tests :)
1515
/wf:process[wf:process-definition-name = $process-model-name] ! xdmp:document-delete(fn:base-uri(.)),
1616
(: Remove children of these processes :)
17-
let $test-pid := fn:doc(test-constants:test-pid-uri($test-constants:TEST-01-MODEL-NAME))/test-constants:pid/text()
17+
let $test-pid := fn:doc(test-constants:test-pid-uri($process-model-name))/test-constants:pid/text()
1818
return
1919
/wf:process[fn:matches(wf:process-definition-name,$process-model-name)] ! xdmp:document-delete(fn:base-uri(.)),
2020
(: Delete test pid document :)
21-
xdmp:document-delete(test-constants:test-pid-uri($test-constants:TEST-01-MODEL-NAME)),
21+
xdmp:document-delete(test-constants:test-pid-uri($process-model-name)),
2222
(: Delete model files :)
23-
cts:uris()[fn:matches(.,test-constants:file-name-for-model($test-constants:TEST-01-MODEL-NAME))] ! xdmp:document-delete(.),
23+
cts:uris()[fn:matches(.,test-constants:file-name-for-model($process-model-name))] ! xdmp:document-delete(.),
2424
(: Delete associated pipelines :)
25-
//p:pipeline-name[fn:matches(.,$test-constants:TEST-01-MODEL-NAME)] ! xdmp:document-delete(fn:base-uri(.))
25+
//p:pipeline-name[fn:matches(.,$process-model-name)] ! xdmp:document-delete(fn:base-uri(.))
2626
)
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
(:
2+
In this test we check that we can successfully delete a subscription
3+
4+
Prep) Set up process model
5+
6+
1) Set up the subscription to the model
7+
2) Check the subscription exists using the API
8+
3) Verify that we have alert documents and a domain - white box testing
9+
4) Delete the subscription using the API and check the response
10+
5) Verify that we have NO alert documents and NO domain - white box testing
11+
12+
:)
13+
import module namespace test-config = "http://marklogic.com/roxy/test-config" at "/test/test-config.xqy";
14+
import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";
15+
import module namespace test-constants = "http://marklogic.com/workflow/test-constants/inclusive-gateway" at "/test/suites/inclusive-gateway/lib/constants.xqy";
16+
17+
import module namespace wrt="http://marklogic.com/workflow/rest-tests" at "/test/workflow-rest-tests.xqy";
18+
import module namespace const="http://marklogic.com/roxy/workflow-constants" at "/test/workflow-constants.xqy";
19+
20+
declare namespace model = "http://marklogic.com/rest-api/resource/processmodel";
21+
22+
declare variable $MODEL-INPUT-FILE-NAME := test-constants:file-name-for-model($test-constants:TEST-02-MODEL-NAME);
23+
24+
declare option xdmp:mapping "false";
25+
26+
let $model-response := wrt:processmodel-create ($const:xml-options, $MODEL-INPUT-FILE-NAME)[2]
27+
return
28+
(
29+
test:assert-equal(xs:string($model-response/model:createResponse/model:outcome/text()),"SUCCESS"),
30+
test:assert-equal(xs:string($model-response/model:createResponse/model:modelId/text()),test-constants:expected-model-id($test-constants:TEST-02-MODEL-NAME))
31+
)
32+
;
33+
34+
import module namespace test-constants = "http://marklogic.com/workflow/test-constants/inclusive-gateway" at "/test/suites/process-subscription/lib/constants.xqy";
35+
import module namespace wrt="http://marklogic.com/workflow/rest-tests" at "/test/workflow-rest-tests.xqy";
36+
import module namespace const="http://marklogic.com/roxy/workflow-constants" at "/test/workflow-constants.xqy";
37+
import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";
38+
39+
declare namespace ext="http://marklogic.com/rest-api/resource/processsubscription";
40+
41+
let $test-payload :=
42+
<ext:createRequest xmlns:ext="http://marklogic.com/rest-api/resource/processsubscription">
43+
<ext:processName>{test-constants:expected-model-id($test-constants:TEST-02-MODEL-NAME)}</ext:processName>
44+
<ext:name>{$test-constants:SUBSCRIPTION-NAME}</ext:name>
45+
<ext:domain>
46+
<ext:name>{$test-constants:DOMAIN-NAME}</ext:name>
47+
<ext:type>directory</ext:type>
48+
<ext:path>{$test-constants:MONITORED-DIRECTORY}</ext:path>
49+
<ext:depth>0</ext:depth>
50+
</ext:domain>
51+
<ext:query>
52+
<cts:and-query xmlns:cts="http://marklogic.com/cts"></cts:and-query>
53+
</ext:query>
54+
</ext:createRequest>
55+
let $create-response := wrt:test-processsubscription-create($const:xml-options,$test-payload)[2]
56+
return
57+
(
58+
test:assert-equal($create-response/ext:createResponse/ext:subscriptionId/fn:string(),test-constants:expected-subscription-id($test-constants:SUBSCRIPTION-NAME)),
59+
test:assert-equal($create-response/ext:createResponse/ext:outcome/fn:string(),"SUCCESS")
60+
)
61+
;
62+
import module namespace test-constants = "http://marklogic.com/workflow/test-constants/inclusive-gateway" at "/test/suites/process-subscription/lib/constants.xqy";
63+
import module namespace wrt="http://marklogic.com/workflow/rest-tests" at "/test/workflow-rest-tests.xqy";
64+
import module namespace const="http://marklogic.com/roxy/workflow-constants" at "/test/workflow-constants.xqy";
65+
import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";
66+
67+
declare namespace alert="http://marklogic.com/xdmp/alert";
68+
declare namespace ext="http://marklogic.com/rest-api/resource/processsubscription";
69+
70+
let $read-response := wrt:test-processsubscription-read($const:xml-options,$test-constants:SUBSCRIPTION-NAME)
71+
return
72+
(
73+
test:assert-equal($read-response/ext:readResponse/ext:subscription/alert:config/alert:config-uri/fn:string(),test-constants:expected-subscription-id($test-constants:SUBSCRIPTION-NAME)),
74+
test:assert-equal($read-response/ext:readResponse/ext:outcome/fn:string(),"SUCCESS")
75+
)
76+
;
77+
(: Internally verify that we have a cpf domain with the expected name :)
78+
import module namespace test-constants = "http://marklogic.com/workflow/test-constants/inclusive-gateway" at "/test/suites/process-subscription/lib/constants.xqy";
79+
import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";
80+
81+
declare namespace dom = "http://marklogic.com/cpf/domains";
82+
83+
test:assert-true(
84+
xdmp:invoke-function(function(){
85+
fn:exists(//dom:domain-name/text()[fn:matches(.,$test-constants:DOMAIN-NAME)])},<options xmlns="xdmp:eval"><database>{xdmp:triggers-database()}</database></options>))
86+
;
87+
(: And that we have three alert documents :)
88+
import module namespace test-constants = "http://marklogic.com/workflow/test-constants/inclusive-gateway" at "/test/suites/process-subscription/lib/constants.xqy";
89+
import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";
90+
91+
test:assert-equal(fn:count(fn:collection(test-constants:expected-subscription-id($test-constants:SUBSCRIPTION-NAME))),3)
92+
;
93+
(: Delete should return a 204 :)
94+
import module namespace test-constants = "http://marklogic.com/workflow/test-constants/inclusive-gateway" at "/test/suites/process-subscription/lib/constants.xqy";
95+
import module namespace wrt="http://marklogic.com/workflow/rest-tests" at "/test/workflow-rest-tests.xqy";
96+
import module namespace const="http://marklogic.com/roxy/workflow-constants" at "/test/workflow-constants.xqy";
97+
import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";
98+
99+
declare namespace http = "xdmp:http";
100+
101+
let $delete-response := wrt:test-processsubscription-delete($const:xml-options,$test-constants:SUBSCRIPTION-NAME)
102+
return
103+
test:assert-equal($delete-response/http:code/fn:data(),204)
104+
;
105+
import module namespace test-constants = "http://marklogic.com/workflow/test-constants/inclusive-gateway" at "/test/suites/process-subscription/lib/constants.xqy";
106+
import module namespace wrt="http://marklogic.com/workflow/rest-tests" at "/test/workflow-rest-tests.xqy";
107+
import module namespace const="http://marklogic.com/roxy/workflow-constants" at "/test/workflow-constants.xqy";
108+
import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";
109+
110+
declare namespace alert="http://marklogic.com/xdmp/alert";
111+
declare namespace ext="http://marklogic.com/rest-api/resource/processsubscription";
112+
113+
let $read-response := wrt:test-processsubscription-read($const:xml-options,$test-constants:SUBSCRIPTION-NAME)
114+
return
115+
test:assert-equal($read-response/ext:readResponse/ext:outcome/fn:string(),"NOT FOUND")
116+
;
117+
(: Internally verify that we NO LONGER have a cpf domain with the expected name :)
118+
import module namespace test-constants = "http://marklogic.com/workflow/test-constants/inclusive-gateway" at "/test/suites/process-subscription/lib/constants.xqy";
119+
import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";
120+
121+
declare namespace dom = "http://marklogic.com/cpf/domains";
122+
123+
test:assert-false(
124+
xdmp:invoke-function(function(){
125+
fn:exists(//dom:domain-name/text()[fn:matches(.,$test-constants:DOMAIN-NAME)])},<options xmlns="xdmp:eval"><database>{xdmp:triggers-database()}</database></options>))
126+
;
127+
(: And that we have NO alert documents :)
128+
import module namespace test-constants = "http://marklogic.com/workflow/test-constants/inclusive-gateway" at "/test/suites/process-subscription/lib/constants.xqy";
129+
import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";
130+
131+
test:assert-equal(fn:count(fn:collection(test-constants:expected-subscription-id($test-constants:SUBSCRIPTION-NAME))),0)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module namespace test-constants = "http://marklogic.com/workflow/test-constants/inclusive-gateway";
2+
3+
declare option xdmp:mapping "false";
4+
5+
declare variable $TEST-02-MODEL-NAME := "InclusiveGatewayTest-02";
6+
declare variable $TEST-MODEL-NAMES := ($TEST-02-MODEL-NAME);
7+
declare variable $TEST-FILES := $TEST-MODEL-NAMES ! file-name-for-model(.);
8+
declare variable $TEST-PID-DIR := "/test/pid/";
9+
declare variable $DOMAIN-NAME := "process-subscription-test-domain";
10+
declare variable $SUBSCRIPTION-NAME := "process-subscription-test-subscription";
11+
declare variable $MONITORED-DIRECTORY := "/test/process-subscription/monitored-directory/";
12+
13+
14+
declare function file-name-for-model($model-name as xs:string){
15+
$model-name||".bpmn"
16+
};
17+
18+
declare function expected-model-id($model-name) as xs:string{
19+
$model-name||"__1__0"
20+
};
21+
22+
declare function test-pid-uri($model-name as xs:string) as xs:string{
23+
$TEST-PID-DIR||$model-name||".xml"
24+
};
25+
26+
declare function save-pid($pid,$model-name){
27+
let $pid-content := element test-constants:pid{$pid}
28+
return
29+
xdmp:document-insert(test-pid-uri($model-name),$pid-content)
30+
};
31+
32+
declare function expected-subscription-id($subscription-name as xs:string) as xs:string{"/config/alerts/"||$subscription-name};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
xquery version "1.0-ml";
2+
3+
import module namespace test-config = "http://marklogic.com/roxy/test-config" at "/test/test-config.xqy";
4+
import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";
5+
import module namespace test-constants = "http://marklogic.com/workflow/test-constants/inclusive-gateway" at "lib/constants.xqy";
6+
7+
8+
for $test-file in $test-constants:TEST-FILES
9+
let $target-uri := test-config:local-uri-for-test-file($test-file)
10+
return
11+
test:load-test-file($test-file, xdmp:database(), $target-uri)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import module namespace test-constants = "http://marklogic.com/workflow/test-constants/inclusive-gateway" at "lib/constants.xqy";
2+
import module namespace const="http://marklogic.com/roxy/workflow-constants" at "/test/workflow-constants.xqy";
3+
import module namespace wrt="http://marklogic.com/workflow/rest-tests" at "/test/workflow-rest-tests.xqy";
4+
import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";
5+
6+
declare namespace ext = "http://marklogic.com/rest-api/resource/process";
7+
declare namespace wf = "http://marklogic.com/workflow";
8+
declare namespace p = "http://marklogic.com/cpf/pipelines";
9+
10+
11+
for $process-model-name in $test-constants:TEST-MODEL-NAMES
12+
return
13+
(
14+
(: Delete model files :)
15+
cts:uris()[fn:matches(.,test-constants:file-name-for-model($process-model-name))] ! xdmp:document-delete(.),
16+
(: Delete associated pipelines :)
17+
//p:pipeline-name[fn:matches(.,$process-model-name)] ! xdmp:document-delete(fn:base-uri(.))
18+
)

0 commit comments

Comments
 (0)