mirror of
https://github.com/sartography/spiff-arena.git
synced 2025-02-28 17:10:42 +00:00
Squashed 'SpiffWorkflow/' changes from 46f410a28..46d3de27f
46d3de27f Merge pull request #267 from sartography/feature/dmn_collect_policy 2d5ca32d5 Support for the "COLLECT" hit policy. * DecisionTable constructor now expects a third argument (the HitPolicy) * DMNParser now checks for a hitPolicy attribute, but defaults ot "UNIQUE" as Camunda doesn't put another in there if Unique is selected. * DecisionTable deserializer will default to a hitPolicy of "UNIQUE" if not value is in the Json. git-subtree-dir: SpiffWorkflow git-subtree-split: 46d3de27ffbcaf60025f09d1cf04fcc7ee98658a
This commit is contained in:
parent
1bed0fb3ee
commit
a3e8bcbd65
@ -41,11 +41,17 @@ class DecisionRunner:
|
||||
'Exactly one decision table should exist! (%s)' \
|
||||
% (len(decision.decisionTables))
|
||||
|
||||
self.dmnEngine = DMNEngine(decision.decisionTables[0])
|
||||
self.decision_table = decision.decisionTables[0]
|
||||
self.dmnEngine = DMNEngine(self.decision_table)
|
||||
|
||||
def decide(self, context):
|
||||
|
||||
"""Makes the rather ugly assumption that there is only one
|
||||
rule match for a decision - which was previously the case"""
|
||||
if not isinstance(context, dict):
|
||||
context = {'input': context}
|
||||
task = Task(self.script_engine, context)
|
||||
return self.dmnEngine.decide(task)
|
||||
return self.dmnEngine.decide(task)[0]
|
||||
|
||||
def result(self, context):
|
||||
task = Task(self.script_engine, context)
|
||||
return self.dmnEngine.result(task)
|
||||
|
37
tests/SpiffWorkflow/dmn/HitPolicyTest.py
Normal file
37
tests/SpiffWorkflow/dmn/HitPolicyTest.py
Normal file
@ -0,0 +1,37 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from SpiffWorkflow.dmn.engine.DMNEngine import DMNEngine
|
||||
from SpiffWorkflow.dmn.parser.BpmnDmnParser import BpmnDmnParser
|
||||
from tests.SpiffWorkflow.bpmn.BpmnWorkflowTestCase import BpmnWorkflowTestCase
|
||||
from tests.SpiffWorkflow.dmn.DecisionRunner import DecisionRunner
|
||||
from tests.SpiffWorkflow.dmn.python_engine.PythonDecisionRunner import \
|
||||
PythonDecisionRunner
|
||||
|
||||
|
||||
class HitPolicyTest(BpmnWorkflowTestCase):
|
||||
PARSER_CLASS = BpmnDmnParser
|
||||
|
||||
def testHitPolicyUnique(self):
|
||||
file_name = os.path.join(os.path.dirname(__file__), 'data', 'unique_hit.dmn')
|
||||
runner = PythonDecisionRunner(file_name)
|
||||
decision_table = runner.decision_table
|
||||
self.assertEqual('UNIQUE', decision_table.hit_policy)
|
||||
res = runner.result({'name': 'Larry'})
|
||||
self.assertEqual(1, res['result'])
|
||||
|
||||
def testHitPolicyCollect(self):
|
||||
file_name = os.path.join(os.path.dirname(__file__), 'data', 'collect_hit.dmn')
|
||||
runner = PythonDecisionRunner(file_name)
|
||||
decision_table = runner.decision_table
|
||||
self.assertEqual('COLLECT', decision_table.hit_policy)
|
||||
res = runner.result({'type': 'stooge'})
|
||||
self.assertEqual(4, len(res['name']))
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(HitPolicyTest)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.TextTestRunner(verbosity=2).run(suite())
|
78
tests/SpiffWorkflow/dmn/data/collect_hit.dmn
Normal file
78
tests/SpiffWorkflow/dmn/data/collect_hit.dmn
Normal file
@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" id="Definitions_06veek1" name="DRD" namespace="http://camunda.org/schema/1.0/dmn" exporter="Camunda Modeler" exporterVersion="5.0.0">
|
||||
<decision id="Decision_ExclusiveAMCheck" name="UniqueHit">
|
||||
<decisionTable id="decisionTable_1" hitPolicy="COLLECT">
|
||||
<input id="InputClause_1ley07z" label="Input "type"">
|
||||
<inputExpression id="LiteralExpression_0yhfcz3" typeRef="string" expressionLanguage="python">
|
||||
<text>type</text>
|
||||
</inputExpression>
|
||||
</input>
|
||||
<output id="output_1" label="Output "result"" name="result" typeRef="integer" />
|
||||
<output id="OutputClause_1yrcvgl" label="Output "name"" name="name" typeRef="string" />
|
||||
<rule id="DecisionRule_07162mr">
|
||||
<description></description>
|
||||
<inputEntry id="UnaryTests_079zee3">
|
||||
<text>"stooge"</text>
|
||||
</inputEntry>
|
||||
<outputEntry id="LiteralExpression_16l50ps">
|
||||
<text>1</text>
|
||||
</outputEntry>
|
||||
<outputEntry id="LiteralExpression_1lgpxjl">
|
||||
<text>"Larry"</text>
|
||||
</outputEntry>
|
||||
</rule>
|
||||
<rule id="DecisionRule_0ifa4wu">
|
||||
<description></description>
|
||||
<inputEntry id="UnaryTests_1fj8ed0">
|
||||
<text>"stooge"</text>
|
||||
</inputEntry>
|
||||
<outputEntry id="LiteralExpression_0td8sa6">
|
||||
<text>2</text>
|
||||
</outputEntry>
|
||||
<outputEntry id="LiteralExpression_13y7kcx">
|
||||
<text>"Mo"</text>
|
||||
</outputEntry>
|
||||
</rule>
|
||||
<rule id="DecisionRule_0x9z2jm">
|
||||
<inputEntry id="UnaryTests_1nsph49">
|
||||
<text>"stooge"</text>
|
||||
</inputEntry>
|
||||
<outputEntry id="LiteralExpression_04v8i8e">
|
||||
<text>3</text>
|
||||
</outputEntry>
|
||||
<outputEntry id="LiteralExpression_1f70eo7">
|
||||
<text>"Curly"</text>
|
||||
</outputEntry>
|
||||
</rule>
|
||||
<rule id="DecisionRule_16ur1y7">
|
||||
<inputEntry id="UnaryTests_0etcimx">
|
||||
<text>"stooge"</text>
|
||||
</inputEntry>
|
||||
<outputEntry id="LiteralExpression_0yc7vs6">
|
||||
<text>4</text>
|
||||
</outputEntry>
|
||||
<outputEntry id="LiteralExpression_1k2kclw">
|
||||
<text>"Shemp"</text>
|
||||
</outputEntry>
|
||||
</rule>
|
||||
<rule id="DecisionRule_0fzx40q">
|
||||
<inputEntry id="UnaryTests_1gzu54o">
|
||||
<text>"farmer"</text>
|
||||
</inputEntry>
|
||||
<outputEntry id="LiteralExpression_11h0epz">
|
||||
<text>5</text>
|
||||
</outputEntry>
|
||||
<outputEntry id="LiteralExpression_031adn2">
|
||||
<text>"Elmer Fudd"</text>
|
||||
</outputEntry>
|
||||
</rule>
|
||||
</decisionTable>
|
||||
</decision>
|
||||
<dmndi:DMNDI>
|
||||
<dmndi:DMNDiagram id="DMNDiagram_1vu8ul5">
|
||||
<dmndi:DMNShape id="DMNShape_0sl8kie" dmnElementRef="Decision_ExclusiveAMCheck">
|
||||
<dc:Bounds height="80" width="180" x="150" y="150" />
|
||||
</dmndi:DMNShape>
|
||||
</dmndi:DMNDiagram>
|
||||
</dmndi:DMNDI>
|
||||
</definitions>
|
54
tests/SpiffWorkflow/dmn/data/unique_hit.dmn
Normal file
54
tests/SpiffWorkflow/dmn/data/unique_hit.dmn
Normal file
@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:biodi="http://bpmn.io/schema/dmn/biodi/2.0" xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" id="Definitions_06veek1" name="DRD" namespace="http://camunda.org/schema/1.0/dmn" exporter="Camunda Modeler" exporterVersion="5.0.0">
|
||||
<decision id="Decision_ExclusiveAMCheck" name="UniqueHit">
|
||||
<decisionTable id="decisionTable_1">
|
||||
<input id="input_1" label="Input "name"" biodi:width="192">
|
||||
<inputExpression id="inputExpression_1" typeRef="string" expressionLanguage="python">
|
||||
<text>name</text>
|
||||
</inputExpression>
|
||||
</input>
|
||||
<output id="output_1" label="Output "result"" name="result" typeRef="integer" />
|
||||
<rule id="DecisionRule_07162mr">
|
||||
<description></description>
|
||||
<inputEntry id="UnaryTests_1jqxc3u">
|
||||
<text>"Larry"</text>
|
||||
</inputEntry>
|
||||
<outputEntry id="LiteralExpression_16l50ps">
|
||||
<text>1</text>
|
||||
</outputEntry>
|
||||
</rule>
|
||||
<rule id="DecisionRule_0ifa4wu">
|
||||
<description></description>
|
||||
<inputEntry id="UnaryTests_0szbwxc">
|
||||
<text>"Mo"</text>
|
||||
</inputEntry>
|
||||
<outputEntry id="LiteralExpression_0td8sa6">
|
||||
<text>2</text>
|
||||
</outputEntry>
|
||||
</rule>
|
||||
<rule id="DecisionRule_0x9z2jm">
|
||||
<inputEntry id="UnaryTests_1ul57lx">
|
||||
<text>"Curly"</text>
|
||||
</inputEntry>
|
||||
<outputEntry id="LiteralExpression_04v8i8e">
|
||||
<text>3</text>
|
||||
</outputEntry>
|
||||
</rule>
|
||||
<rule id="DecisionRule_16ur1y7">
|
||||
<inputEntry id="UnaryTests_09q92u9">
|
||||
<text>"Shemp"</text>
|
||||
</inputEntry>
|
||||
<outputEntry id="LiteralExpression_0yc7vs6">
|
||||
<text>4</text>
|
||||
</outputEntry>
|
||||
</rule>
|
||||
</decisionTable>
|
||||
</decision>
|
||||
<dmndi:DMNDI>
|
||||
<dmndi:DMNDiagram id="DMNDiagram_1vu8ul5">
|
||||
<dmndi:DMNShape id="DMNShape_0sl8kie" dmnElementRef="Decision_ExclusiveAMCheck">
|
||||
<dc:Bounds height="80" width="180" x="150" y="150" />
|
||||
</dmndi:DMNShape>
|
||||
</dmndi:DMNDiagram>
|
||||
</dmndi:DMNDI>
|
||||
</definitions>
|
Loading…
x
Reference in New Issue
Block a user