use of org.drools.testcoverage.common.model.Person in project drools by kiegroup.
the class LiveQueriesBadResultTest method testAccessToNotExistingVariable.
@Test
public void testAccessToNotExistingVariable() {
ViewChangedEventListener listener = new ViewChangedEventListener() {
@Override
public void rowUpdated(Row row) {
updated.add(row.get("bad"));
}
@Override
public void rowInserted(Row row) {
inserted.add(row.get("bad"));
}
@Override
public void rowDeleted(Row row) {
deleted.add(row.get("bad"));
}
};
final KieBase kieBase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "query.drl");
KieSession ksession = kieBase.newKieSession();
ksession.insert(new Person("Petr", 25));
Assertions.assertThatThrownBy(() -> ksession.openLiveQuery("simple query with no parameters", new Object[] { "Petr", 26 }, listener)).isInstanceOf(RuntimeException.class).hasMessage("The identifier 'bad' does not exist as a bound variable for this query");
}
use of org.drools.testcoverage.common.model.Person in project drools by kiegroup.
the class RuleTemplateTest method testSampleCheese.
@Test
public void testSampleCheese() {
// first we compile the decision table into a whole lot of rules.
final ExternalSpreadsheetCompiler converter = new ExternalSpreadsheetCompiler();
final KieServices kieServices = KieServices.Factory.get();
final Resource table = kieServices.getResources().newClassPathResource("sample_cheese.xls", getClass());
final Resource template = kieServices.getResources().newClassPathResource("sample_cheese.drt", getClass());
String drl = null;
try {
// the data we are interested in starts at row 2, column 2 (i.e. B2)
drl = converter.compile(table.getInputStream(), template.getInputStream(), 2, 2);
} catch (IOException e) {
throw new IllegalArgumentException("Could not read spreadsheet or rules stream.", e);
}
// compile the drl
final Resource drlResource = kieServices.getResources().newReaderResource(new StringReader(drl));
drlResource.setTargetPath(TestConstants.DRL_TEST_TARGET_PATH);
final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, drlResource);
final Collection<KiePackage> pkgs = kbase.getKiePackages();
Assertions.assertThat(pkgs.size()).isEqualTo(2);
final ArrayList<String> names = new ArrayList<String>();
for (KiePackage kp : pkgs) {
names.add(kp.getName());
}
Assertions.assertThat(names.contains(TestConstants.PACKAGE_FUNCTIONAL)).isTrue();
Assertions.assertThat(names.contains(TestConstants.PACKAGE_TESTCOVERAGE_MODEL)).isTrue();
final KiePackage kiePackage = (KiePackage) pkgs.toArray()[names.indexOf(TestConstants.PACKAGE_FUNCTIONAL)];
Assertions.assertThat(kiePackage.getRules().size()).isEqualTo(2);
final KieSession ksession = kbase.newKieSession();
ksession.insert(new Cheese("stilton", 42));
ksession.insert(new Person("michael", "stilton", 42));
final List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ksession.fireAllRules();
LOGGER.debug(list.toString());
ksession.dispose();
}
use of org.drools.testcoverage.common.model.Person in project drools by kiegroup.
the class OOPathDslTest method dslWithOOPathAndSpecialChars.
/**
* Shows it's possible to use OOPath including some characters that are significant for both DSL and OOPath.
*/
@Test
public void dslWithOOPathAndSpecialChars() {
final String dsl = "[when]Person comes from \"{state}\"=person : " + "Person( /address#InternationalAddress[ state == \"{state}\" ] )\n";
final String drl = "package P\n" + "\n" + "import org.drools.testcoverage.common.model.InternationalAddress\n" + "import org.drools.testcoverage.common.model.Person\n" + "\n" + "rule R\n" + "when\n" + " Person comes from \"Peaceful State\"\n" + "then\n" + "end";
KieSession kieSession = new KieHelper().addContent(dsl, ResourceType.DSL).addContent(drl, ResourceType.DSLR).build().newKieSession();
final Person person = new Person("Bruno", 21);
person.setAddress(new InternationalAddress("Some Street", 10, "Beautiful City", "Peaceful State"));
kieSession.insert(person);
assertThat(kieSession.fireAllRules()).isEqualTo(1);
}
use of org.drools.testcoverage.common.model.Person 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);
}
use of org.drools.testcoverage.common.model.Person in project drools by kiegroup.
the class DecisionTableTest method testMultipleTableXLS.
@Test
public void testMultipleTableXLS() {
final Resource decisionTable = ResourceUtil.getDecisionTableResourceFromClasspath("multiple_tables.xls", getClass(), DecisionTableInputType.XLS);
final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, decisionTable);
Assertions.assertThat(2).isEqualTo(kbase.getKiePackages().size());
final KieSession session = kbase.newKieSession();
// testing person object from the first table
final Person person = new Person("Paul");
person.setId(1);
Assertions.assertThat(person.getName()).isEqualTo("Paul");
Assertions.assertThat(person.getId()).isEqualTo(1);
// testing second person, he should be renamed by rules in the second
// table
final Person person2 = new Person("Helmut von Seireit");
person2.setId(1000);
Assertions.assertThat(person2.getName()).isEqualTo("Helmut von Seireit");
Assertions.assertThat(person2.getId()).isEqualTo(1000);
session.insert(person);
session.insert(person2);
session.fireAllRules();
Assertions.assertThat(person.getName()).isEqualTo("Paul");
Assertions.assertThat(person.getId()).isEqualTo(2);
Assertions.assertThat(person2.getName()).isEqualTo("Wilhelm von Seireit");
Assertions.assertThat(person2.getId()).isEqualTo(1000);
session.dispose();
}
Aggregations