Search in sources :

Example 6 with Address

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

the class GuidedDecisionTableTest method setUp.

@Before
public void setUp() throws Exception {
    barcelonaCityCenter = new Address("City Center", 1, "Barcelona");
    cottageInMountains = new Address("Mountains", 999, "Small Village");
    cottageInDesert = new Address("Sand Street", 1, "Desert Town");
    johnFromBarcelona = new Person("John", 18);
    peter70Years = new Person("Peter", 70);
    mary33Years = new Person("Mary", 33);
    johnFromBarcelona.setAddress(barcelonaCityCenter);
    elizabeth35Years = new Person("Elizabeth", 35);
    william25Years = new Person("William", 25);
}
Also used : Address(org.drools.testcoverage.common.model.Address) Person(org.drools.testcoverage.common.model.Person) Before(org.junit.Before)

Example 7 with Address

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

the class GuidedDecisionTableTest method testMoveToBiggerCities.

/**
 * The decision table assumes 3 groups of cities according to people living there
 * The test assert that people move to bigger city, if they like big cities
 */
@Test
public void testMoveToBiggerCities() throws Exception {
    initKieSession("moveToBiggerCities.gdst");
    final Address brno = producePeopleInCity("Brno", 7000);
    final Address prague = producePeopleInCity("Prague", 30000);
    final Address london = producePeopleInCity("London", 60000);
    final Address smallCity = new Address();
    smallCity.setCity("city with just one person");
    peter70Years.setAddress(smallCity);
    peter70Years.setLikes("big city");
    william25Years.setAddress(brno);
    william25Years.setLikes("big city");
    mary33Years.setAddress(prague);
    mary33Years.setLikes("big city");
    elizabeth35Years.setAddress(london);
    elizabeth35Years.setLikes("big city");
    kSession.insert(smallCity);
    final FactHandle peter = kSession.insert(peter70Years);
    final FactHandle wiliam = kSession.insert(william25Years);
    final FactHandle mary = kSession.insert(mary33Years);
    final FactHandle elizabeth = kSession.insert(elizabeth35Years);
    Assertions.assertThat(kSession.fireAllRules()).isEqualTo(3);
    Assertions.assertThat(((Person) kSession.getObject(peter)).getAddress().getCity()).isEqualTo("Brno");
    Assertions.assertThat(((Person) kSession.getObject(wiliam)).getAddress().getCity()).isEqualTo("Prague");
    Assertions.assertThat(((Person) kSession.getObject(mary)).getAddress().getCity()).isEqualTo("London");
    // No other bigger city
    Assertions.assertThat(((Person) kSession.getObject(elizabeth)).getAddress().getCity()).isEqualTo("London");
    kSession.dispose();
}
Also used : Address(org.drools.testcoverage.common.model.Address) FactHandle(org.kie.api.runtime.rule.FactHandle) Test(org.junit.Test)

Example 8 with Address

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

the class GuidedDecisionTableTest method testMoveToBiggerCitiesPeopleNotLikeBigCities.

@Test
public void testMoveToBiggerCitiesPeopleNotLikeBigCities() throws Exception {
    initKieSession("moveToBiggerCities.gdst");
    final Address brno = producePeopleInCity("Brno", 7000);
    final Address prague = producePeopleInCity("Prague", 30000);
    final Address london = producePeopleInCity("London", 60000);
    final Address smallCity = new Address();
    smallCity.setCity("city with just one person");
    peter70Years.setAddress(smallCity);
    william25Years.setAddress(brno);
    mary33Years.setAddress(prague);
    elizabeth35Years.setAddress(london);
    kSession.insert(smallCity);
    kSession.insert(peter70Years);
    kSession.insert(william25Years);
    kSession.insert(mary33Years);
    kSession.insert(elizabeth35Years);
    Assertions.assertThat(kSession.fireAllRules()).isEqualTo(0);
    kSession.dispose();
}
Also used : Address(org.drools.testcoverage.common.model.Address) Test(org.junit.Test)

Example 9 with Address

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

the class GuidedDecisionTableTest method testMoveToPeopleToAddress.

/**
 * This test evaluates table that uses dsl sentences in runtime
 * Especially it moves people older than 50 from Brno technology park to Brno city center
 */
@Test
public void testMoveToPeopleToAddress() throws Exception {
    initKieSession("person_actions.dsl", "movePeopleToAddress.gdst");
    final Address technologyPark = new Address();
    technologyPark.setCity("Brno");
    technologyPark.setStreet("Technology Park");
    technologyPark.setNumber(1);
    kSession.insert(technologyPark);
    peter70Years.setAddress(technologyPark);
    william25Years.setAddress(technologyPark);
    final FactHandle peter = kSession.insert(peter70Years);
    final FactHandle william = kSession.insert(william25Years);
    Assertions.assertThat(kSession.fireAllRules()).isEqualTo(1);
    Assertions.assertThat(((Person) kSession.getObject(peter)).getAddress().getStreet()).isEqualTo("Joštova");
    Assertions.assertThat(((Person) kSession.getObject(william)).getAddress().getStreet()).isEqualTo("Technology Park");
    kSession.dispose();
}
Also used : Address(org.drools.testcoverage.common.model.Address) FactHandle(org.kie.api.runtime.rule.FactHandle) Test(org.junit.Test)

Example 10 with Address

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

the class OOPathDtablesTest method prepareData.

private Person[] prepareData() {
    final Person bruno = new Person("Bruno", 25);
    bruno.setAddress(new InternationalAddress("Some Street", 10, "Nice City", "Safecountry"));
    final Person robert = new Person("Robert", 17);
    robert.setAddress(new InternationalAddress("Some Street", 12, "Small City", "Riskyland"));
    final Person joe = new Person("Joe", 11);
    joe.setAddress(new InternationalAddress("Some Street", 13, "Big City", "Safecountry"));
    final Person mike = new Person("Mike", 25);
    mike.setAddress(new Address("Some Street", 14, "Local City"));
    return new Person[] { bruno, robert, joe, mike };
}
Also used : InternationalAddress(org.drools.testcoverage.common.model.InternationalAddress) Address(org.drools.testcoverage.common.model.Address) InternationalAddress(org.drools.testcoverage.common.model.InternationalAddress) Person(org.drools.testcoverage.common.model.Person)

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