use of org.drools.testcoverage.common.model.Person in project drools by kiegroup.
the class DecisionTableTest method testSimpleDecisionTable.
private void testSimpleDecisionTable(final Resource decisionTable) {
final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, decisionTable);
final KieSession session = kbase.newKieSession();
final Person person = new Person("Paul");
person.setId(1);
Assertions.assertThat(person.getName()).isEqualTo("Paul");
Assertions.assertThat(person.getId()).isEqualTo(1);
session.insert(person);
session.fireAllRules();
Assertions.assertThat(person.getName()).isEqualTo("Paul");
Assertions.assertThat(person.getId()).isEqualTo(2);
session.dispose();
}
use of org.drools.testcoverage.common.model.Person 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;
}
use of org.drools.testcoverage.common.model.Person in project drools by kiegroup.
the class GuidedDecisionTableTest method testDetectWhatPersonLikesAndMoveConditionsNotMet.
@Test
public void testDetectWhatPersonLikesAndMoveConditionsNotMet() throws Exception {
initKieSession("detectWhatPersonLikesAndMove.gdst");
william25Years.setLikes("money");
final FactHandle williamLikesMoney = kSession.insert(william25Years);
mary33Years.setLikes("cheese");
final FactHandle maryLikesCheese = kSession.insert(mary33Years);
peter70Years.setLikes("movies");
final FactHandle peterLikesMovies = kSession.insert(peter70Years);
kSession.fireAllRules();
Assertions.assertThat(((Person) kSession.getObject(williamLikesMoney)).getAddress()).isNull();
Assertions.assertThat(((Person) kSession.getObject(maryLikesCheese)).getAddress()).isNull();
Assertions.assertThat(((Person) kSession.getObject(peterLikesMovies)).getAddress()).isNull();
kSession.dispose();
}
use of org.drools.testcoverage.common.model.Person in project drools by kiegroup.
the class GuidedDecisionTableTest method testOptimizeAddressesMovePeopleAndRemoveUnusedAddresses.
@Test
public void testOptimizeAddressesMovePeopleAndRemoveUnusedAddresses() throws Exception {
initKieSession("optimizeAddresses.gdst");
final FactHandle desertCottage = kSession.insert(cottageInDesert);
final FactHandle mountainsCottage = kSession.insert(cottageInMountains);
final FactHandle elizabeth = kSession.insert(elizabeth35Years);
kSession.fireAllRules();
Assertions.assertThat(kSession.getObject(mountainsCottage)).isNotNull();
Assertions.assertThat(kSession.getObject(elizabeth)).isNotNull();
Assertions.assertThat(((Person) kSession.getObject(elizabeth)).getAddress()).isEqualTo(cottageInMountains);
Assertions.assertThat(kSession.getObject(desertCottage)).isNull();
kSession.dispose();
}
use of org.drools.testcoverage.common.model.Person in project drools by kiegroup.
the class ActivationTest method noDormantCheckOnModifies.
/**
* Tests improper deactivation of already activated rule on the agenda. See
* BZ 862325.
*/
@Test
public void noDormantCheckOnModifies() throws Exception {
AgendaEventListener ael = mock(AgendaEventListener.class);
session.addEventListener(ael);
session.setGlobal("LOGGER", LOGGER);
List<Command<?>> commands = new ArrayList<Command<?>>();
commands.add(getCommands().newInsert(new Person("Bob", 19)));
commands.add(getCommands().newInsert(new Cheese("brie", 10)));
commands.add(getCommands().newFireAllRules());
session.execute(getCommands().newBatchExecution(commands, null));
// both rules should fire exactly once
verify(ael, times(2)).afterMatchFired(any(AfterMatchFiredEvent.class));
// no cancellations should have happened
verify(ael, never()).matchCancelled(any(MatchCancelledEvent.class));
}
Aggregations