use of org.kie.api.io.Resource in project drools by kiegroup.
the class FusionAfterBeforeTest method testAfterBeforeOperators.
@Test
public void testAfterBeforeOperators() {
final Resource drlResource = KieServices.Factory.get().getResources().newClassPathResource("fusionAfterBeforeTest.drl", getClass());
final KieBase kieBase = KieBaseUtil.getKieBaseAndBuildInstallModule(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, drlResource);
final KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
ksconf.setOption(ClockTypeOption.get("pseudo"));
final KieSession ksession = kieBase.newKieSession(ksconf, null);
final TrackingAgendaEventListener listener = new TrackingAgendaEventListener();
ksession.addEventListener(listener);
final EntryPoint stream = ksession.getEntryPoint("EventStream");
SessionPseudoClock clock = ksession.getSessionClock();
try {
for (int i = 0; i < 3; i++) {
final MessageEvent tc = new MessageEvent(MessageEvent.Type.received, new Message());
stream.insert(tc);
ksession.fireAllRules();
clock.advanceTime(8, TimeUnit.SECONDS);
}
ksession.fireAllRules();
} finally {
ksession.dispose();
}
Assertions.assertThat(listener.isRuleFired("AfterMessageEvent")).as("Rule 'AfterMessageEvent' was no fired!").isTrue();
Assertions.assertThat(listener.isRuleFired("BeforeMessageEvent")).as("Rule 'BeforeMessageEvent' was no fired!").isTrue();
// each rules should be fired 2 times
int firedCount = 2;
int actuallyFired = listener.ruleFiredCount("AfterMessageEvent");
Assertions.assertThat(firedCount).as("Rule 'AfterMessageEvent' should be fired 2 times, but was fired " + firedCount + " time(s)!").isEqualTo(actuallyFired);
firedCount = listener.ruleFiredCount("BeforeMessageEvent");
Assertions.assertThat(firedCount).as("Rule 'BeforeMessageEvent' should be fired 2 times, but was fired " + firedCount + " time(s)!").isEqualTo(actuallyFired);
}
use of org.kie.api.io.Resource in project drools by kiegroup.
the class BenchmarkUtil method writeDomainModelToKJar.
private static void writeDomainModelToKJar(final KieServices kieServices, final KieFileSystem kieFileSystem) {
final String javaSrc = Person.class.getCanonicalName().replace('.', File.separatorChar) + ".java";
final Resource javaResource = kieServices.getResources().newFileSystemResource("src/test/java/" + javaSrc);
kieFileSystem.write("src/main/java/" + javaSrc, javaResource);
}
use of org.kie.api.io.Resource in project drools by kiegroup.
the class PMML4Compiler method prepareTemplate.
private static void prepareTemplate(String ntempl) {
try {
String path = TEMPLATE_PATH + ntempl;
Resource res = ResourceFactory.newClassPathResource(path, org.kie.pmml.pmml_4_2.PMML4Compiler.class);
if (res != null) {
InputStream stream = res.getInputStream();
if (stream != null) {
registry.addNamedTemplate(path.substring(path.lastIndexOf('/') + 1), TemplateCompiler.compileTemplate(stream));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.kie.api.io.Resource in project drools by kiegroup.
the class PMML4Compiler method compile.
public String compile(String resource, ClassLoader classLoader) {
String theory = null;
Resource cpr = new ClassPathResource(resource);
try {
theory = compile(cpr.getInputStream(), classLoader);
} catch (IOException e) {
results.add(new PMMLError(e.toString()));
e.printStackTrace();
}
return theory;
}
use of org.kie.api.io.Resource in project drools by kiegroup.
the class PMML4Compiler method getInputStreamByFileName.
private InputStream getInputStreamByFileName(String fileName) {
InputStream is = null;
Resource res = ResourceFactory.newClassPathResource(fileName);
try {
is = res.getInputStream();
} catch (Exception e) {
}
if (is == null) {
res = ResourceFactory.newFileResource(fileName);
}
try {
is = res.getInputStream();
} catch (Exception e) {
this.results.add(new PMMLError("Unable to retrieve file based resource: " + fileName));
}
return is;
}
Aggregations