Search in sources :

Example 1 with Address

use of org.drools.testcoverage.common.model.Address in project drools by kiegroup.

the class OOPathLogicalBranchesTest method populateKieSession.

private void populateKieSession() {
    final Employee bruno = this.createEmployee("Bruno", new Address("Elm", 10, "Small City"));
    this.kieSession.insert(bruno);
    final Employee alice = this.createEmployee("Alice", new Address("Elm", 10, "Big City"));
    this.kieSession.insert(alice);
}
Also used : Employee(org.drools.testcoverage.common.model.Employee) Address(org.drools.testcoverage.common.model.Address)

Example 2 with Address

use of org.drools.testcoverage.common.model.Address in project drools by kiegroup.

the class OOPathLogicalBranchesTest method testAndConditionalElementWithNot.

@Test
public void testAndConditionalElementWithNot() {
    final String drl = "import org.drools.testcoverage.common.model.Employee;\n" + "import org.drools.testcoverage.common.model.Address;\n" + "global java.util.List list\n" + "\n" + "rule R when\n" + "  $employee: Employee( /address[ street == 'Elm', city == 'Big City' ] )\n" + " and " + "  not Employee( /address[ street == 'Elm', city == 'Small City' ] )\n" + "then\n" + "  list.add( $employee.getName() );\n" + "end\n";
    final KieBase kieBase = KieBaseUtil.getKieBaseFromDRLResources(kieBaseTestConfiguration, KIE_SERVICES.getResources().newByteArrayResource(drl.getBytes()));
    this.createKieSession(kieBase);
    final Employee bruno = this.createEmployee("Bruno", new Address("Elm", 10, "Small City"));
    final FactHandle brunoFactHandle = this.kieSession.insert(bruno);
    final Employee alice = this.createEmployee("Alice", new Address("Elm", 10, "Big City"));
    this.kieSession.insert(alice);
    this.kieSession.fireAllRules();
    Assertions.assertThat(this.results).isEmpty();
    this.kieSession.delete(brunoFactHandle);
    this.kieSession.fireAllRules();
    Assertions.assertThat(this.results).containsExactlyInAnyOrder("Alice");
}
Also used : Employee(org.drools.testcoverage.common.model.Employee) Address(org.drools.testcoverage.common.model.Address) FactHandle(org.kie.api.runtime.rule.FactHandle) KieBase(org.kie.api.KieBase) Test(org.junit.Test)

Example 3 with Address

use of org.drools.testcoverage.common.model.Address in project drools by kiegroup.

the class OOPathSmokeTest method testFireRule.

@Test
public void testFireRule() {
    final KieBase kieBase = KieBaseUtil.getKieBaseFromClasspathResources(this.getClass(), kieBaseTestConfiguration, "oopath.drl");
    this.kieSession = kieBase.newKieSession();
    final Person person = new Person("Bruno", 21);
    person.setAddress(new Address("Some Street", 10, "Beautiful City"));
    this.kieSession.insert(person);
    Assertions.assertThat(this.kieSession.fireAllRules()).isEqualTo(1);
}
Also used : Address(org.drools.testcoverage.common.model.Address) KieBase(org.kie.api.KieBase) Person(org.drools.testcoverage.common.model.Person) Test(org.junit.Test)

Example 4 with Address

use of org.drools.testcoverage.common.model.Address in project drools by kiegroup.

the class GuidedDecisionTableTest method producePeopleInCity.

private Address producePeopleInCity(final String city, final int countOfPeople) {
    final Address address = new Address();
    address.setCity(city);
    kSession.insert(address);
    for (int i = 0; i < countOfPeople; i++) {
        final Person person = new Person();
        person.setName("Inhabitant " + i);
        person.setAddress(address);
        kSession.insert(person);
    }
    return address;
}
Also used : Address(org.drools.testcoverage.common.model.Address) Person(org.drools.testcoverage.common.model.Person)

Example 5 with Address

use of org.drools.testcoverage.common.model.Address in project drools by kiegroup.

the class GuidedDecisionTableTest method testMoveToBiggerCitiesTooBigGapBetweenCitySizes.

@Test
public void testMoveToBiggerCitiesTooBigGapBetweenCitySizes() throws Exception {
    initKieSession("moveToBiggerCities.gdst");
    final Address brno = producePeopleInCity("Brno", 7000);
    producePeopleInCity("London", 60000);
    william25Years.setAddress(brno);
    william25Years.setLikes("big city");
    kSession.insert(william25Years);
    Assertions.assertThat(kSession.fireAllRules()).isEqualTo(0);
    kSession.dispose();
}
Also used : Address(org.drools.testcoverage.common.model.Address) Test(org.junit.Test)

Aggregations

Address (org.drools.testcoverage.common.model.Address)10 Test (org.junit.Test)6 Person (org.drools.testcoverage.common.model.Person)4 FactHandle (org.kie.api.runtime.rule.FactHandle)3 Employee (org.drools.testcoverage.common.model.Employee)2 KieBase (org.kie.api.KieBase)2 InternationalAddress (org.drools.testcoverage.common.model.InternationalAddress)1 Before (org.junit.Before)1