pibizza commented on code in PR #6447:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6447#discussion_r2335771178


##########
drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/FiringOrderTest.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.drools.model.codegen.execmodel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.api.event.rule.AgendaEventListener;
+import org.kie.api.event.rule.BeforeMatchFiredEvent;
+import org.kie.api.event.rule.DefaultAgendaEventListener;
+import org.kie.api.runtime.KieSession;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class FiringOrderTest extends BaseModelTest {
+
+    private static final org.slf4j.Logger log = 
org.slf4j.LoggerFactory.getLogger(FiringOrderTest.class);
+
+    public static class State {
+
+        private int value;
+        private boolean aFired;
+
+        public State(int value, boolean aFired) {
+            this.value = value;
+            this.aFired = aFired;
+        }
+
+        public int getValue() {
+            return value;
+        }
+
+        public void setValue(int value) {
+            this.value = value;
+        }
+
+        public boolean isAFired() {
+            return aFired;
+        }
+
+        public void setAFired(boolean aFired) {
+            this.aFired = aFired;
+        }
+    }
+
+    private static final String DRL_INSERT_FACT = """
+                                      package com.example.drools
+                                      
+                                      import %s.State;
+                                      
+                                      global java.util.List firingOrder;
+                                      
+                                      // Rule A: in ruleflow-group XGroup. It 
modifies State so that B and C become eligible.
+                                      rule "A"
+                                          ruleflow-group "XGroup"
+                                      when
+                                          $s : State(aFired == false, value == 
0)
+                                      then
+                                          // Mark A as fired and set value to 
1 so that B condition is met
+                                          modify($s) { setAFired(true), 
setValue(1) };
+                                      
+                                          // Insert new fact to make C 
eligible (modification of existing fact does not necessarily trigger auto-focus)
+                                          insert(new State(2, false));
+                                      end
+                                      
+                                      // Rule B: in ruleflow-group XGroup 
(same as A).
+                                      rule "B"
+                                          ruleflow-group "XGroup"
+                                      when
+                                          State(value == 1, aFired == true)
+                                      then
+                                      end
+                                      
+                                      // Rule C: in ruleflow-group YGroup with 
auto-focus true.
+                                      // When this rule becomes active, it 
will push its ruleflow group to the focus stack.
+                                      rule "C"
+                                          ruleflow-group "YGroup"
+                                          auto-focus true
+                                      when
+                                          State(value == 2, aFired == false)
+                                      then
+                                      end
+                                      
""".formatted(FiringOrderTest.class.getName());
+
+    @ParameterizedTest
+    @MethodSource("parameters")
+    void ruleCActivatesBeforeRuleBInsertTest(RUN_TYPE runType) {
+        final KieSession kieSession = getKieSession(runType, DRL_INSERT_FACT);
+
+        try {
+            final List<String> firingOrder = new ArrayList<>();
+
+            // Listener to capture firing order for B and C
+            final AgendaEventListener listener = new 
DefaultAgendaEventListener() {
+                @Override
+                public void beforeMatchFired(BeforeMatchFiredEvent event) {
+                    firingOrder.add(event.getMatch().getRule().getName());
+                }
+            };

Review Comment:
   I think we can make a general test oriented listener for collecting these 
events and perform these assertions. I will open a ticket for this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to