Copilot commented on code in PR #6553:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6553#discussion_r2681278480


##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/impl/DMNRuntimeEventManagerUtilsTest.java:
##########
@@ -117,12 +125,77 @@ void testConditionalEvent() {
         
assertThat(dmnResult.getDecisionResultByName(decisionName).getResult()).isEqualTo(List.of("pos"));
 
         ArgumentCaptor<AfterConditionalEvaluationEvent> 
conditionalEvaluationEventArgumentCaptor = 
ArgumentCaptor.forClass(AfterConditionalEvaluationEvent.class);
-        verify(spiedListener).afterConditionalEvaluation 
(conditionalEvaluationEventArgumentCaptor.capture());
+        
verify(spiedListener).afterConditionalEvaluation(conditionalEvaluationEventArgumentCaptor.capture());
         AfterConditionalEvaluationEvent evaluateConditionalEvent = 
conditionalEvaluationEventArgumentCaptor.getValue();
         assertThat(evaluateConditionalEvent).isNotNull();
         
assertThat(evaluateConditionalEvent.getDecisionName()).isEqualTo(decisionName);
         EvaluatorResult retrieved = 
evaluateConditionalEvent.getEvaluatorResultResult();
         assertThat(retrieved).isNotNull();
         
assertThat(evaluateConditionalEvent.getExecutedId()).isEqualTo(executedId);
     }
+
+    @Test
+    void testEvaluateDecisionTableEvent() {
+        String decisionName = "New Decision";
+        String bkmName = "New BKM";
+        String dtId = "_46B46F91-5810-452F-B1D4-A0B0304737B1";
+        Resource resource = 
ResourceFactory.newClassPathResource("valid_models/DMNv1_6/decisionsInBKMWithNameInput.dmn");
+        DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults()
+                .buildConfiguration()
+                .fromResources(Collections.singletonList(resource))
+                .getOrElseThrow(RuntimeException::new);
+        dmnRuntime.addListener(spiedListener);
+        assertThat(dmnRuntime).isNotNull();
+        String nameSpace = 
"https://kie.org/dmn/_8010864B-CC05-4DB2-A6CB-B19968FD56BC";;
+
+        final DMNModel dmnModel = dmnRuntime.getModel(nameSpace, 
"DMN_DE9C9FE9-DF27-43B7-917C-96765C61467F");
+        assertThat(dmnModel).isNotNull();
+        DMNContext context = DMNFactory.newContext();
+        context.set("name", "2");
+        DMNResult dmnResult = dmnRuntime.evaluateAll(dmnModel, context);
+        
assertThat(dmnResult.getDecisionResultByName(decisionName)).isNotNull();
+        
assertThat(dmnResult.getDecisionResultByName(decisionName).getResult()).isEqualTo("bb");
+
+        ArgumentCaptor<AfterEvaluateDecisionTableEvent> 
evaluateDecisionTableEventCaptor = 
ArgumentCaptor.forClass(AfterEvaluateDecisionTableEvent.class);
+        verify(spiedListener, 
times(5)).afterEvaluateDecisionTable(evaluateDecisionTableEventCaptor.capture());
+        
+        AfterEvaluateDecisionTableEvent evaluateDecisionTableEvent = 
evaluateDecisionTableEventCaptor.getAllValues().stream()
+                .filter(event -> decisionName.equals(event.getDecisionName()))
+                .findFirst()
+                .orElseThrow(() -> new IllegalArgumentException("No event 
found for decision: " + decisionName));
+
+        assertThat(evaluateDecisionTableEvent).isNotNull();
+        
assertThat(evaluateDecisionTableEvent.getDecisionName()).isEqualTo(decisionName);
+        
assertThat(evaluateDecisionTableEvent.getNodeName()).isEqualTo(bkmName);
+        
assertThat(evaluateDecisionTableEvent.getDecisionTableName()).isEqualTo(bkmName);
+        
assertThat(evaluateDecisionTableEvent.getDecisionTableId()).isEqualTo(dtId);
+        assertThat(evaluateDecisionTableEvent.getSelected()).isNotEmpty();
+        
assertThat(evaluateDecisionTableEvent.getSelectedIds()).contains("_4FCA6937-8E97-4513-8D43-460E6B7D5686");
+    }
+
+    @Test
+    void testThreadLocalValue() throws Exception {
+        DMNRuntimeEventManagerImpl eventManager = new 
DMNRuntimeEventManagerImpl();
+        int elements = 6;
+        Set<Thread> threads = new HashSet<>();
+        Map<Integer, AtomicReference<String>> mappedThreadValues = new 
HashMap<>();
+        CountDownLatch latch = new CountDownLatch(elements);
+
+        IntStream.range(0, elements).forEach(i -> {
+            AtomicReference<String> threadValue = new AtomicReference<>();
+            Thread thread = new Thread(() -> {
+                eventManager.setCurrentEvaluatingDecisionName("New Decision " 
+ i);
+                
threadValue.set(eventManager.getCurrentEvaluatingDecisionName());
+                latch.countDown();
+            });
+            mappedThreadValues.put(i, threadValue);
+            threads.add(thread);
+        });
+
+        threads.forEach(Thread::start);
+        latch.await();
+
+        mappedThreadValues.forEach((i, threadValue) -> 
assertThat(threadValue.get()).isEqualTo("New Decision " + i));
+    }

Review Comment:
   The test for thread-local functionality doesn't verify the cleanup behavior 
(clearCurrentEvaluatingDecisionName). The test should also verify that after 
cleanup, getCurrentEvaluatingDecisionName returns null and that ThreadLocal 
values are properly removed to prevent memory leaks. Consider adding assertions 
that call clearCurrentEvaluatingDecisionName and verify the value is cleared.



-- 
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