1+ /* Licensed under the Apache License, Version 2.0 (the "License");
2+ * you may not use this file except in compliance with the License.
3+ * You may obtain a copy of the License at
4+ *
5+ * http://www.apache.org/licenses/LICENSE-2.0
6+ *
7+ * Unless required by applicable law or agreed to in writing, software
8+ * distributed under the License is distributed on an "AS IS" BASIS,
9+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+ * See the License for the specific language governing permissions and
11+ * limitations under the License.
12+ */
13+ package org .flowable .dmn .engine .test .history ;
14+
15+ import static org .assertj .core .api .Assertions .assertThat ;
16+ import static org .assertj .core .api .Assertions .entry ;
17+
18+ import java .util .List ;
19+ import java .util .Map ;
20+ import java .util .stream .IntStream ;
21+
22+ import org .flowable .dmn .api .DecisionExecutionAuditContainer ;
23+ import org .flowable .dmn .api .DecisionServiceExecutionAuditContainer ;
24+ import org .flowable .dmn .engine .test .BaseFlowableDmnTest ;
25+ import org .flowable .dmn .engine .test .DmnDeployment ;
26+ import org .junit .jupiter .api .Test ;
27+
28+ /**
29+ * @author Roman Saratz
30+ */
31+ class HistoryDisabledTest extends BaseFlowableDmnTest {
32+
33+ @ Test
34+ @ DmnDeployment
35+ public void testExecuteDecision () {
36+ List <Map <String , Object >> result = ruleService .createExecuteDecisionBuilder ()
37+ .decisionKey ("decision1" )
38+ .variable ("inputVariable1" , 11 )
39+ .disableHistory ()
40+ .executeDecision ();
41+
42+ assertThat (result ).hasSize (1 );
43+ assertThat (result .get (0 )).containsExactly (
44+ entry ("outputVariable1" , "gt 10" ),
45+ entry ("outputVariable2" , "result2" )
46+ );
47+
48+ assertThat (historyService .createHistoricDecisionExecutionQuery ().count ()).isEqualTo (0 );
49+ }
50+
51+ @ Test
52+ @ DmnDeployment
53+ public void testExecuteDecisionService () {
54+ Map <String , List <Map <String , Object >>> result = ruleService .createExecuteDecisionBuilder ()
55+ .decisionKey ("expandedDecisionService" )
56+ .variable ("input1" , "test1" )
57+ .variable ("input2" , "test2" )
58+ .variable ("input3" , "test3" )
59+ .variable ("input4" , "test4" )
60+ .disableHistory ()
61+ .executeDecisionService ();
62+
63+ assertThat (result ).hasSize (2 );
64+ List <Map <String , Object >> decision1 = result .get ("decision1" );
65+ assertThat (decision1 ).hasSize (3 );
66+ IntStream .range (0 , 3 ).forEach (i ->
67+ assertThat (decision1 .get (i )).containsExactly (entry ("output1" , "NOT EMPTY " + (i + 1 )))
68+ );
69+
70+ List <Map <String , Object >> decision2 = result .get ("decision2" );
71+ assertThat (decision2 ).hasSize (3 );
72+ IntStream .range (0 , 3 ).forEach (i ->
73+ assertThat (decision2 .get (i )).containsExactly (entry ("output2" , "NOT EMPTY " + (i + 1 )))
74+ );
75+
76+ assertThat (historyService .createHistoricDecisionExecutionQuery ().count ()).isEqualTo (0 );
77+ }
78+
79+ @ Test
80+ @ DmnDeployment
81+ public void testExecuteWithSingleResult () {
82+ Map <String , Object > result = ruleService .createExecuteDecisionBuilder ()
83+ .decisionKey ("decision1" )
84+ .variable ("inputVariable1" , 11 )
85+ .disableHistory ()
86+ .executeWithSingleResult ();
87+
88+ assertThat (result ).hasSize (2 );
89+ assertThat (result ).containsExactly (
90+ entry ("outputVariable1" , "gt 10" ),
91+ entry ("outputVariable2" , "result2" )
92+ );
93+ assertThat (historyService .createHistoricDecisionExecutionQuery ().count ()).isEqualTo (0 );
94+ }
95+
96+ @ Test
97+ @ DmnDeployment
98+ public void testExecuteDecisionWithSingleResult () {
99+ Map <String , Object > result = ruleService .createExecuteDecisionBuilder ()
100+ .decisionKey ("decision1" )
101+ .variable ("inputVariable1" , 11 )
102+ .disableHistory ()
103+ .executeDecisionWithSingleResult ();
104+
105+ assertThat (result ).hasSize (2 );
106+ assertThat (result ).containsExactly (
107+ entry ("outputVariable1" , "gt 10" ),
108+ entry ("outputVariable2" , "result2" )
109+ );
110+
111+ assertThat (historyService .createHistoricDecisionExecutionQuery ().count ()).isEqualTo (0 );
112+ }
113+
114+ @ Test
115+ @ DmnDeployment
116+ public void testExecuteDecisionServiceWithSingleResult () {
117+ Map <String , Object > result = ruleService .createExecuteDecisionBuilder ()
118+ .decisionKey ("expandedDecisionService" )
119+ .variable ("input1" , "test1" )
120+ .variable ("input2" , "test2" )
121+ .variable ("input3" , "test3" )
122+ .variable ("input4" , "test4" )
123+ .disableHistory ()
124+ .executeDecisionServiceWithSingleResult ();
125+
126+ assertThat (result ).hasSize (2 );
127+ assertThat (result ).containsExactly (
128+ entry ("output1" , "NOT EMPTY 1" ),
129+ entry ("output2" , "NOT EMPTY 1" )
130+ );
131+
132+ assertThat (historyService .createHistoricDecisionExecutionQuery ().count ()).isEqualTo (0 );
133+ }
134+
135+ @ Test
136+ @ DmnDeployment
137+ public void testExecuteWithAuditTrail () {
138+ DecisionExecutionAuditContainer auditContainer = ruleService .createExecuteDecisionBuilder ()
139+ .decisionKey ("decision1" )
140+ .variable ("inputVariable1" , 11 )
141+ .disableHistory ()
142+ .executeWithAuditTrail ();
143+
144+ assertThat (auditContainer ).isNotNull ();
145+ assertThat (auditContainer .getStartTime ()).isNotNull ();
146+ assertThat (auditContainer .getEndTime ()).isNotNull ();
147+ assertThat (auditContainer .getInputVariables ().get ("inputVariable1" )).isEqualTo (11 );
148+ assertThat (auditContainer .getDecisionResult ()).hasSize (1 );
149+ assertThat (auditContainer .getDecisionResult ().get (0 )).containsExactly (
150+ entry ("outputVariable1" , "gt 10" ),
151+ entry ("outputVariable2" , "result2" )
152+ );
153+
154+ assertThat (historyService .createHistoricDecisionExecutionQuery ().count ()).isEqualTo (0 );
155+ }
156+
157+ @ Test
158+ @ DmnDeployment
159+ public void testExecuteDecisionWithAuditTrail () {
160+ DecisionExecutionAuditContainer auditContainer = ruleService .createExecuteDecisionBuilder ()
161+ .decisionKey ("decision1" )
162+ .variable ("inputVariable1" , 11 )
163+ .disableHistory ()
164+ .executeDecisionWithAuditTrail ();
165+
166+ assertThat (auditContainer ).isNotNull ();
167+ assertThat (auditContainer .getStartTime ()).isNotNull ();
168+ assertThat (auditContainer .getEndTime ()).isNotNull ();
169+ assertThat (auditContainer .getInputVariables ().get ("inputVariable1" )).isEqualTo (11 );
170+ assertThat (auditContainer .getDecisionResult ()).hasSize (1 );
171+ assertThat (auditContainer .getDecisionResult ().get (0 )).containsExactly (
172+ entry ("outputVariable1" , "gt 10" ),
173+ entry ("outputVariable2" , "result2" )
174+ );
175+
176+ assertThat (historyService .createHistoricDecisionExecutionQuery ().count ()).isEqualTo (0 );
177+ }
178+
179+ @ Test
180+ @ DmnDeployment
181+ public void testExecuteDecisionServiceWithAuditTrail () {
182+ DecisionServiceExecutionAuditContainer auditContainer = ruleService .createExecuteDecisionBuilder ()
183+ .decisionKey ("expandedDecisionService" )
184+ .variable ("input1" , "test1" )
185+ .variable ("input2" , "test2" )
186+ .variable ("input3" , "test3" )
187+ .variable ("input4" , "test4" )
188+ .disableHistory ()
189+ .executeDecisionServiceWithAuditTrail ();
190+
191+ assertThat (auditContainer ).isNotNull ();
192+ assertThat (auditContainer .getStartTime ()).isNotNull ();
193+ assertThat (auditContainer .getEndTime ()).isNotNull ();
194+ assertThat (auditContainer .getInputVariables ()).containsExactlyInAnyOrderEntriesOf (
195+ Map .of ("input1" , "test1" ,
196+ "input2" , "test2" ,
197+ "input3" , "test3" ,
198+ "input4" , "test4" )
199+ );
200+
201+ Map <String , List <Map <String , Object >>> result = auditContainer .getDecisionServiceResult ();
202+ assertThat (result ).hasSize (2 );
203+ assertThat (result ).hasSize (2 );
204+ List <Map <String , Object >> decision1 = result .get ("decision1" );
205+ assertThat (decision1 ).hasSize (3 );
206+ IntStream .range (0 , 3 ).forEach (i ->
207+ assertThat (decision1 .get (i )).containsExactly (entry ("output1" , "NOT EMPTY " + (i + 1 )))
208+ );
209+
210+ List <Map <String , Object >> decision2 = result .get ("decision2" );
211+ assertThat (decision2 ).hasSize (3 );
212+ IntStream .range (0 , 3 ).forEach (i ->
213+ assertThat (decision2 .get (i )).containsExactly (entry ("output2" , "NOT EMPTY " + (i + 1 )))
214+ );
215+
216+ assertThat (historyService .createHistoricDecisionExecutionQuery ().count ()).isEqualTo (0 );
217+ }
218+
219+ @ Test
220+ @ DmnDeployment
221+ public void testExecute () {
222+ List <Map <String , Object >> result = ruleService .createExecuteDecisionBuilder ()
223+ .decisionKey ("decision1" )
224+ .variable ("inputVariable1" , 11 )
225+ .disableHistory ()
226+ .execute ();
227+
228+ assertThat (result ).hasSize (1 );
229+ assertThat (result .get (0 )).containsExactly (
230+ entry ("outputVariable1" , "gt 10" ),
231+ entry ("outputVariable2" , "result2" )
232+ );
233+
234+ assertThat (historyService .createHistoricDecisionExecutionQuery ().count ()).isEqualTo (0 );
235+ }
236+ }
0 commit comments