Search in sources :

Example 6 with Employee

use of org.drools.modelcompiler.domain.Employee in project drools by kiegroup.

the class OOPathTest method testOrConditionalElement.

@Test
public void testOrConditionalElement() {
    final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "global java.util.List list\n" + "\n" + "rule R when\n" + "  Employee( $address: /address[ city == 'Big City' ] )\n" + " or " + "  Employee( $address: /address[ city == 'Small City' ] )\n" + "then\n" + "  list.add( $address.getCity() );\n" + "end\n";
    KieSession kieSession = getKieSession(drl);
    List<String> results = new ArrayList<>();
    kieSession.setGlobal("list", results);
    final Employee bruno = createEmployee("Bruno", new Address("Elm", 10, "Small City"));
    kieSession.insert(bruno);
    final Employee alice = createEmployee("Alice", new Address("Elm", 10, "Big City"));
    kieSession.insert(alice);
    kieSession.fireAllRules();
    Assertions.assertThat(results).containsExactlyInAnyOrder("Big City", "Small City");
}
Also used : Employee.createEmployee(org.drools.modelcompiler.domain.Employee.createEmployee) Employee(org.drools.modelcompiler.domain.Employee) Address(org.drools.modelcompiler.domain.Address) InternationalAddress(org.drools.modelcompiler.domain.InternationalAddress) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 7 with Employee

use of org.drools.modelcompiler.domain.Employee in project drools by kiegroup.

the class OOPathTest method testOrConstraintNoBinding.

@Test
public void testOrConstraintNoBinding() {
    final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "global java.util.List list\n" + "\n" + "rule R when\n" + "  $emp: Employee( /address[ street == 'Elm' || city == 'Big City' ] )\n" + "        Employee( this != $emp, /address[ street == 'Elm' || city == 'Big City' ] )\n" + "then\n" + "  list.add( $emp.getName() );\n" + "end\n";
    KieSession kieSession = getKieSession(drl);
    List<String> results = new ArrayList<>();
    kieSession.setGlobal("list", results);
    final Employee bruno = createEmployee("Bruno", new Address("Elm", 10, "Small City"));
    kieSession.insert(bruno);
    final Employee alice = createEmployee("Alice", new Address("Elm", 10, "Big City"));
    kieSession.insert(alice);
    kieSession.fireAllRules();
    Assertions.assertThat(results).containsExactlyInAnyOrder("Bruno", "Alice");
}
Also used : Employee.createEmployee(org.drools.modelcompiler.domain.Employee.createEmployee) Employee(org.drools.modelcompiler.domain.Employee) Address(org.drools.modelcompiler.domain.Address) InternationalAddress(org.drools.modelcompiler.domain.InternationalAddress) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 8 with Employee

use of org.drools.modelcompiler.domain.Employee in project drools by kiegroup.

the class OOPathTest method testOrConstraintWithJoin.

@Test
public void testOrConstraintWithJoin() {
    final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "global java.util.List list\n" + "\n" + "rule R when\n" + "  $emp: Employee( $address: /address[ street == 'Elm' || city == 'Big City' ] )\n" + "        Employee( this != $emp, /address[ street == $address.street || city == 'Big City' ] )\n" + "then\n" + "  list.add( $address.getCity() );\n" + "end\n";
    KieSession kieSession = getKieSession(drl);
    List<String> results = new ArrayList<>();
    kieSession.setGlobal("list", results);
    final Employee bruno = createEmployee("Bruno", new Address("Elm", 10, "Small City"));
    kieSession.insert(bruno);
    final Employee alice = createEmployee("Alice", new Address("Elm", 10, "Big City"));
    kieSession.insert(alice);
    kieSession.fireAllRules();
    Assertions.assertThat(results).containsExactlyInAnyOrder("Big City", "Small City");
}
Also used : Employee.createEmployee(org.drools.modelcompiler.domain.Employee.createEmployee) Employee(org.drools.modelcompiler.domain.Employee) Address(org.drools.modelcompiler.domain.Address) InternationalAddress(org.drools.modelcompiler.domain.InternationalAddress) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 9 with Employee

use of org.drools.modelcompiler.domain.Employee in project drools by kiegroup.

the class OrTest method testOrConstraint.

@Test
public void testOrConstraint() {
    final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "global java.util.List list\n" + "\n" + "rule R when\n" + "  Employee( $address: address, ( address.city == 'Big City' || address.city == 'Small City' ) )\n" + "then\n" + "  list.add( $address.getCity() );\n" + "end\n";
    KieSession kieSession = getKieSession(drl);
    List<String> results = new ArrayList<>();
    kieSession.setGlobal("list", results);
    final Employee bruno = createEmployee("Bruno", new Address("Elm", 10, "Small City"));
    kieSession.insert(bruno);
    final Employee alice = createEmployee("Alice", new Address("Elm", 10, "Big City"));
    kieSession.insert(alice);
    kieSession.fireAllRules();
    Assertions.assertThat(results).containsExactlyInAnyOrder("Big City", "Small City");
}
Also used : Employee(org.drools.modelcompiler.domain.Employee) Employee.createEmployee(org.drools.modelcompiler.domain.Employee.createEmployee) Address(org.drools.modelcompiler.domain.Address) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 10 with Employee

use of org.drools.modelcompiler.domain.Employee in project drools by kiegroup.

the class OrTest method testOrConditional.

@Test
public void testOrConditional() {
    final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "global java.util.List list\n" + "\n" + "rule R when\n" + "  Employee( $address: address, address.city == 'Big City' )\n" + " or " + "  Employee( $address: address, address.city == 'Small City' )\n" + "then\n" + "  list.add( $address.getCity() );\n" + "end\n";
    KieSession kieSession = getKieSession(drl);
    List<String> results = new ArrayList<>();
    kieSession.setGlobal("list", results);
    final Employee bruno = createEmployee("Bruno", new Address("Elm", 10, "Small City"));
    kieSession.insert(bruno);
    final Employee alice = createEmployee("Alice", new Address("Elm", 10, "Big City"));
    kieSession.insert(alice);
    kieSession.fireAllRules();
    Assertions.assertThat(results).containsExactlyInAnyOrder("Big City", "Small City");
}
Also used : Employee(org.drools.modelcompiler.domain.Employee) Employee.createEmployee(org.drools.modelcompiler.domain.Employee.createEmployee) Address(org.drools.modelcompiler.domain.Address) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)10 Address (org.drools.modelcompiler.domain.Address)10 Employee (org.drools.modelcompiler.domain.Employee)10 Employee.createEmployee (org.drools.modelcompiler.domain.Employee.createEmployee)10 Test (org.junit.Test)10 KieSession (org.kie.api.runtime.KieSession)10 InternationalAddress (org.drools.modelcompiler.domain.InternationalAddress)7 IOException (java.io.IOException)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1 Serializable (java.io.Serializable)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 Assertions (org.assertj.core.api.Assertions)1 ClockType (org.drools.core.ClockType)1 KnowledgeBaseFactory (org.drools.core.impl.KnowledgeBaseFactory)1