spiff-arena/tests/SpiffWorkflow/bpmn/CollaborationTest.py
burnettk 38ff7e08da Squashed 'SpiffWorkflow/' changes from 01a25fc3..0adfc8cb
0adfc8cb update spiff signal event
52d65dfc Merge pull request #346 from sartography/bugfix/update-split-task-inputs
23ca808c make sure tasks with boundary events are connected properly
de427431 remove pointless parser attribute and variable
3236b5b9 change subprocess start event validation error message text
a5ad0672 Merge pull request #344 from sartography/bugfix/gateway-in-loop
6b22a195 allow event definitions without refs
bb843873 clean up inclusive gateway a little
a7d81c02 prevent parallel gateways from waiting on descendants
802352a2 move test to proper location
ebcdde95 Merge pull request #343 from sartography/feature/event-payloads
87636472 add an additional test for boundary event parent removal
41423168 add escalation event test
26c5a9bb fix message event catch check
9bd018e5 Add test case for call activities in sub processes, fixed bug (#342)
546923b4 add serialization migration for boundary events
46d41e20 add spiff payload extensions + base spec improvements
a0f5fc2a remove boundary event parent
56277ff1 add event class
6de6fb2b reorganize event definitions
7db65566 fix subprocess cancel
442535ae do not allow the task trace to infinitely loop to get the trace w/ burnettk
dbe41c8e Merge pull request #339 from sartography/improvement/better-subworkflow-management
6c61f20a update parent attribute name
ea0a7bf4 update correlations when catching external messages
f511e2dd remove unneeded method from tests
953fa63c clean up workflow methods
efcdcf54 Merge pull request #338 from sartography/bugfix/triggered-multiinstance-tasks
11b78ce7 prevent errors synching children of MI tasks
bbb79e05 miscellaneous improvements
3f8e8d84 split bpmn workflow into two classes
61e01201 clean up workflow attributes & methods

git-subtree-dir: SpiffWorkflow
git-subtree-split: 0adfc8cbaec80d36f98a4136434e960f666fcfe2
2023-08-09 16:14:27 -04:00

153 lines
7.0 KiB
Python

from SpiffWorkflow.bpmn.specs.mixins.subworkflow_task import CallActivity
from SpiffWorkflow.bpmn.workflow import BpmnWorkflow
from SpiffWorkflow.bpmn.event import BpmnEvent
from SpiffWorkflow.task import TaskState
from .BpmnWorkflowTestCase import BpmnWorkflowTestCase
class CollaborationTest(BpmnWorkflowTestCase):
def testParserProvidesInfoOnMessagesAndCorrelations(self):
parser = self.get_parser('collaboration.bpmn')
self.assertEqual(list(parser.messages.keys()), ['love_letter', 'love_letter_response'])
self.assertEqual(parser.correlations,
{'lover_name': {'name': "Lover's Name",
'retrieval_expressions': [
{'expression': 'lover_name',
'messageRef': 'love_letter'},
{'expression': 'from_name',
'messageRef': 'love_letter_response'}]}}
)
def testCollaboration(self):
spec, subprocesses = self.load_collaboration('collaboration.bpmn', 'my_collaboration')
# Only executable processes should be started
self.assertIn('process_buddy', subprocesses)
self.assertNotIn('random_person_process', subprocesses)
self.workflow = BpmnWorkflow(spec, subprocesses)
start = self.workflow.get_tasks_from_spec_name('Start')[0]
# Set up some data to be evaluated so that the workflow can proceed
start.data['lover_name'] = 'Peggy'
self.workflow.do_engine_steps()
# Call activities should be created for executable processes and be reachable
buddy = self.workflow.get_tasks_from_spec_name('process_buddy')[0]
self.assertIsInstance(buddy.task_spec, CallActivity)
self.assertEqual(buddy.task_spec.spec, 'process_buddy')
self.assertEqual(buddy.state, TaskState.WAITING)
def testBpmnMessage(self):
spec, subprocesses = self.load_workflow_spec('collaboration.bpmn', 'process_buddy')
workflow = BpmnWorkflow(spec, subprocesses)
start = workflow.get_tasks_from_spec_name('Start')[0]
# Set up some data to be evaluated so that the workflow can proceed
start.data['lover_name'] = 'Peggy'
workflow.do_engine_steps()
# An external message should be created
messages = workflow.get_events()
self.assertEqual(len(messages), 1)
self.assertEqual(len(workflow.bpmn_events), 0)
receive = workflow.get_tasks_from_spec_name('EventReceiveLetter')[0]
# Waiting Events should contain details about what we are no waiting on.
events = workflow.waiting_events()
self.assertEqual(1, len(events))
self.assertEqual("MessageEventDefinition", events[0].event_type)
self.assertEqual("Love Letter Response", events[0].name)
self.assertEqual(['lover'], events[0].value[0].correlation_keys)
self.assertEqual('from_name', events[0].value[0].retrieval_expression)
self.assertEqual('lover_name', events[0].value[0].name)
message = BpmnEvent(
receive.task_spec.event_definition,
{'from_name': 'Peggy', 'other_nonsense': 1001}
)
workflow.send_event(message)
workflow.do_engine_steps()
self.assertEqual(receive.state, TaskState.COMPLETED)
self.assertEqual(workflow.last_task.data, {'from_name': 'Peggy', 'lover_name': 'Peggy', 'other_nonsense': 1001})
self.assertEqual(workflow.correlations, {'lover':{'lover_name':'Peggy'}})
self.assertEqual(workflow.is_completed(), True)
def testCorrelation(self):
specs = self.get_all_specs('correlation.bpmn')
proc_1 = specs['proc_1']
workflow = BpmnWorkflow(proc_1, specs)
workflow.do_engine_steps()
for idx, task in enumerate(workflow.get_ready_user_tasks()):
task.data['task_num'] = idx
task.run()
workflow.do_engine_steps()
ready_tasks = workflow.get_ready_user_tasks()
waiting = workflow.get_tasks_from_spec_name('get_response')
# Two processes should have been started and two corresponding catch events should be waiting
self.assertEqual(len(ready_tasks), 2)
self.assertEqual(len(waiting), 2)
for task in waiting:
self.assertEqual(task.state, TaskState.WAITING)
# Now copy the task_num that was sent into a new variable
for task in ready_tasks:
task.data.update(init_id=task.data['task_num'])
task.run()
workflow.do_engine_steps()
# If the messages were routed properly, the id should match
for task in workflow.get_tasks_from_spec_name('subprocess_end'):
self.assertEqual(task.data['task_num'], task.data['init_id'])
def testTwoCorrelationKeys(self):
specs = self.get_all_specs('correlation_two_conversations.bpmn')
proc_1 = specs['proc_1']
workflow = BpmnWorkflow(proc_1, specs)
workflow.do_engine_steps()
for idx, task in enumerate(workflow.get_ready_user_tasks()):
task.data['task_num'] = idx
task.run()
workflow.do_engine_steps()
# Two processes should have been started and two corresponding catch events should be waiting
ready_tasks = workflow.get_ready_user_tasks()
waiting = workflow.get_tasks_from_spec_name('get_response_one')
self.assertEqual(len(ready_tasks), 2)
self.assertEqual(len(waiting), 2)
for task in waiting:
self.assertEqual(task.state, TaskState.WAITING)
# Now copy the task_num that was sent into a new variable
for task in ready_tasks:
task.data.update(init_id=task.data['task_num'])
task.run()
workflow.do_engine_steps()
# Complete dummy tasks
for task in workflow.get_ready_user_tasks():
task.run()
workflow.do_engine_steps()
# Repeat for the other process, using a different mapped name
ready_tasks = workflow.get_ready_user_tasks()
waiting = workflow.get_tasks_from_spec_name('get_response_two')
self.assertEqual(len(ready_tasks), 2)
self.assertEqual(len(waiting), 2)
for task in ready_tasks:
task.data.update(subprocess=task.data['task_num'])
task.run()
workflow.do_engine_steps()
# If the messages were routed properly, the id should match
for task in workflow.get_tasks_from_spec_name('subprocess_end'):
self.assertEqual(task.data['task_num'], task.data['init_id'])
self.assertEqual(task.data['task_num'], task.data['subprocess'])
def testSerialization(self):
spec, subprocesses = self.load_collaboration('collaboration.bpmn', 'my_collaboration')
self.workflow = BpmnWorkflow(spec, subprocesses)
start = self.workflow.get_tasks_from_spec_name('Start')[0]
start.data['lover_name'] = 'Peggy'
self.workflow.do_engine_steps()
self.save_restore()