use of org.kie.api.definition.KiePackage in project drools by kiegroup.
the class RuleRunner method runRules.
public void runRules(String[] rules, Object[] facts) {
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
for (int i = 0; i < rules.length; i++) {
String ruleFile = rules[i];
System.out.println("Loading file: " + ruleFile);
kbuilder.add(ResourceFactory.newClassPathResource(ruleFile, RuleRunner.class), ResourceType.DRL);
}
Collection<KiePackage> pkgs = kbuilder.getKnowledgePackages();
kbase.addPackages(pkgs);
KieSession ksession = kbase.newKieSession();
for (int i = 0; i < facts.length; i++) {
Object fact = facts[i];
System.out.println("Inserting fact: " + fact);
ksession.insert(fact);
}
ksession.fireAllRules();
}
use of org.kie.api.definition.KiePackage in project drools by kiegroup.
the class DecisionTableTest method testDecisionTableWithDateAttributes.
private void testDecisionTableWithDateAttributes(final Resource decisionTable) {
final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, decisionTable);
final ArrayList<String> names = new ArrayList<>();
final Collection<KiePackage> pkgs = kbase.getKiePackages();
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(3);
}
use of org.kie.api.definition.KiePackage in project drools by kiegroup.
the class HeaderTest method testPMMLHeader.
@Test
public void testPMMLHeader() {
String source = PMML4Helper.pmmlDefaultPackageName().replace(".", File.separator) + File.separator + "test_header.xml";
boolean header = false;
boolean timestamp = false;
boolean appl = false;
boolean descr = false;
boolean copyright = false;
boolean annotation = false;
PMML4Compiler compiler = new PMML4Compiler();
compiler.getHelper().setPack("org.kie.pmml.pmml_4_2.test");
String theory = compiler.compile(source, null);
BufferedReader reader = new BufferedReader(new StringReader(theory));
try {
String line = "";
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.startsWith("// Imported PMML Model Theory"))
header = true;
else if (line.startsWith("// Creation timestamp :"))
timestamp = line.contains("now");
else if (line.startsWith("// Description :"))
descr = line.contains("test");
else if (line.startsWith("// Copyright :"))
copyright = line.contains("opensource");
else if (line.startsWith("// Annotation :"))
annotation = line.contains("notes here");
else if (line.startsWith("// Trained with :"))
appl = line.contains("handmade");
}
} catch (IOException ioe) {
ioe.printStackTrace();
fail();
}
assertTrue(header);
assertTrue(timestamp);
assertTrue(descr);
assertTrue(copyright);
assertTrue(annotation);
assertTrue(appl);
KieSession ksession = getSession(theory);
KiePackage pack = ksession.getKieBase().getKiePackage("org.kie.pmml.pmml_4_2.test");
assertNotNull(pack);
ksession.dispose();
}
use of org.kie.api.definition.KiePackage in project drools by kiegroup.
the class KieModuleMavenTest method testKieContainerBeforeAndAfterDeployOfSnapshot.
@Test
public void testKieContainerBeforeAndAfterDeployOfSnapshot() throws Exception {
// BZ-1007977
KieServices ks = KieServices.Factory.get();
String group = "org.kie.test";
String artifact = "test-module";
String version = "1.0.0-SNAPSHOT";
ReleaseId releaseId = ks.newReleaseId(group, artifact, version);
String prefix = new File(".").getAbsolutePath().contains("kie-ci") ? "" : "kie-ci/";
File kjar = new File(prefix + "src/test/resources/kjar/kjar-module-before.jar");
File pom = new File(prefix + "src/test/resources/kjar/pom-kjar.xml");
MavenRepository repository = getMavenRepository();
repository.installArtifact(releaseId, kjar, pom);
KieContainer kContainer = ks.newKieContainer(releaseId);
KieBase kbase = kContainer.getKieBase();
assertNotNull(kbase);
Collection<KiePackage> packages = kbase.getKiePackages();
assertNotNull(packages);
assertEquals(1, packages.size());
Collection<Rule> rules = packages.iterator().next().getRules();
assertEquals(2, rules.size());
ks.getRepository().removeKieModule(releaseId);
// deploy new version
File kjar1 = new File(prefix + "src/test/resources/kjar/kjar-module-after.jar");
File pom1 = new File(prefix + "src/test/resources/kjar/pom-kjar.xml");
repository.installArtifact(releaseId, kjar1, pom1);
KieContainer kContainer2 = ks.newKieContainer(releaseId);
KieBase kbase2 = kContainer2.getKieBase();
assertNotNull(kbase2);
Collection<KiePackage> packages2 = kbase2.getKiePackages();
assertNotNull(packages2);
assertEquals(1, packages2.size());
Collection<Rule> rules2 = packages2.iterator().next().getRules();
assertEquals(4, rules2.size());
ks.getRepository().removeKieModule(releaseId);
}
use of org.kie.api.definition.KiePackage in project drools by kiegroup.
the class KieBaseIncludesTest method getNumberOfRules.
/**
* Helper method which determines the number of rules in the {@link KieBase}.
*
* @param kieBase
* the {@link KieBase}
* @return the number of rules in the {@link KieBase}
*/
private static long getNumberOfRules(KieBase kieBase) {
long nrOfRules = 0;
Collection<KiePackage> kiePackages = kieBase.getKiePackages();
for (KiePackage nextKiePackage : kiePackages) {
Collection<Rule> rules = nextKiePackage.getRules();
System.out.println(rules);
nrOfRules += rules.size();
}
return nrOfRules;
}
Aggregations