--- /dev/null
+/* Copyright (c) 2019 AT&T Intellectual Property. #\r
+# #\r
+# Licensed under the Apache License, Version 2.0 (the "License"); #\r
+# you may not use this file except in compliance with the License. #\r
+# You may obtain a copy of the License at #\r
+# #\r
+# http://www.apache.org/licenses/LICENSE-2.0 #\r
+# #\r
+# Unless required by applicable law or agreed to in writing, software #\r
+# distributed under the License is distributed on an "AS IS" BASIS, #\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #\r
+# See the License for the specific language governing permissions and #\r
+# limitations under the License. #\r
+##############################################################################*/\r
+\r
+\r
+module.exports = function (context) {\r
+ return async context => {\r
+ function hasDeployedBpmn(){\r
+ return context.app.services[context.app.get('base-path') + 'test-definitions']\r
+ .get(context.data.testDefinitionId, context.params)\r
+ .then(result => {\r
+ \r
+ if(!result.bpmnInstances){\r
+ return false;\r
+ }\r
+ \r
+ for(let i = 0; i < result.bpmnInstances.length; i++){\r
+ if(result.bpmnInstances[i].isDeployed){\r
+ return true;\r
+ }\r
+ }\r
+ return false;\r
+ })\r
+ .catch(err => {\r
+ console.log(err);\r
+ });\r
+ \r
+ }\r
+ \r
+ if(context.data.processDefinitionId === '' && !context.data.useLatestTestDefinition){\r
+ return false;\r
+ }\r
+ if(!hasDeployedBpmn()){\r
+ return false;\r
+ }\r
+ if(hasDeployedBpmn() && (context.data.useLatestTestDefinition || context.data.processDefinitionId !== '') ){\r
+ return true;\r
+ }\r
+ }\r
+}
\ No newline at end of file