tkobayas commented on code in PR #6011:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6011#discussion_r1667850868


##########
drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/DateOperatorTest.java:
##########
@@ -0,0 +1,87 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.operators;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+import org.drools.model.codegen.execmodel.BaseModelTest;
+import org.drools.model.codegen.execmodel.domain.Person;
+import org.drools.model.codegen.execmodel.domain.SimpleDateHolder;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.kie.api.runtime.KieSession;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DateOperatorTest extends BaseModelTest {
+
+    public DateOperatorTest(RUN_TYPE testRunType) {
+        super(testRunType);
+    }
+
+    @Test
+    public void dateBetweenGlobals() throws ParseException {
+        String str =
+                "import " + SimpleDateHolder.class.getCanonicalName() + ";" +
+                        "global java.util.Date $startDate;\n" +
+                        "global java.util.Date $endDate;\n" +
+                        "rule R when\n" +
+                        "  SimpleDateHolder(date > $startDate && date < 
$endDate)\n" +
+                        "then\n" +
+                        "end";
+
+        KieSession ksession = getKieSession(str);
+        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
+        ksession.setGlobal("$startDate", sdf.parse("04/01/2019"));
+        ksession.setGlobal("$endDate", sdf.parse("05/01/2019"));
+
+        SimpleDateHolder holder = new SimpleDateHolder("A", 
sdf.parse("04/15/2019"));
+        ksession.insert(holder);
+        int fired = ksession.fireAllRules();
+
+        assertThat(fired).isEqualTo(1);
+    }
+
+    @Test
+    public void dateBetweenVariables() throws ParseException {

Review Comment:
   This test doesn't have the issue, because `resolver.getDeclaration()` 
returns the same Declaration object, so `replaceDeclaration()` is not called.
   
   
https://github.com/apache/incubator-kie-drools/blob/main/drools-base/src/main/java/org/drools/base/rule/LogicTransformer.java#L253-L270
   
   ```java
       private void replaceDeclarations( DeclarationScopeResolver resolver, 
Pattern pattern, Constraint constraint ) {
           Declaration[] decl = constraint.getRequiredDeclarations();
           for ( Declaration aDecl : decl ) {
               Declaration resolved = resolver.getDeclaration( 
aDecl.getIdentifier() );
   
               if ( constraint instanceof IndexableConstraint && ( 
(IndexableConstraint) constraint ).isUnification() ) {
                   if ( 
ClassObjectType.DroolsQuery_ObjectType.isAssignableFrom( 
resolved.getPattern().getObjectType() ) ) {
                       Declaration redeclaredDeclr = new Declaration( 
resolved.getIdentifier(), ( (IndexableConstraint) constraint 
).getFieldExtractor(), pattern, false );
                       pattern.addDeclaration( redeclaredDeclr );
                   } else if ( resolved.getPattern() != pattern ) {
                       ( (IndexableConstraint ) constraint ).unsetUnification();
                   }
               }
   
               if ( resolved != null && resolved != aDecl && 
resolved.getPattern() != pattern ) {
                   constraint.replaceDeclaration( aDecl,
                                                  resolved );
               } else if ( resolved == null ) {
   ```
   



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