-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[incubator-kie-drools-6010] Date Between Dates with globals Not Trigg…
…ering for Executable Model
- Loading branch information
Showing
3 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...del-codegen/src/test/java/org/drools/model/codegen/execmodel/domain/SimpleDateHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* 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.domain; | ||
|
||
import java.util.Date; | ||
|
||
public class SimpleDateHolder { | ||
|
||
private String id; | ||
private final Date date; | ||
|
||
public SimpleDateHolder(String id, Date date) { | ||
this.id = id; | ||
this.date = date; | ||
} | ||
|
||
public Date getDate() { | ||
return date; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/DateOperatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
String str = | ||
"import " + SimpleDateHolder.class.getCanonicalName() + ";" + | ||
"rule R when\n" + | ||
" SimpleDateHolder(id == \"A\", $startDate : date)\n" + | ||
" SimpleDateHolder(id == \"B\", $endDate : date)\n" + | ||
" SimpleDateHolder(id == \"C\", date > $startDate && date < $endDate)\n" + | ||
"then\n" + | ||
"end"; | ||
|
||
KieSession ksession = getKieSession(str); | ||
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); | ||
|
||
SimpleDateHolder holderA = new SimpleDateHolder("A", sdf.parse("04/01/2019")); | ||
SimpleDateHolder holderB = new SimpleDateHolder("B", sdf.parse("05/01/2019")); | ||
SimpleDateHolder holderC = new SimpleDateHolder("C", sdf.parse("04/15/2019")); | ||
|
||
ksession.insert(holderA); | ||
ksession.insert(holderB); | ||
ksession.insert(holderC); | ||
int fired = ksession.fireAllRules(); | ||
|
||
assertThat(fired).isEqualTo(1); | ||
} | ||
} |