use of org.kie.api.KieServices in project drools by kiegroup.
the class KieRepositoryTest method testTryLoadNotExistingKjarFromClasspath.
@Test
public void testTryLoadNotExistingKjarFromClasspath() {
// DROOLS-1335
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { this.getClass().getResource("/kie-project-simple-1.0.0.jar") });
Thread.currentThread().setContextClassLoader(urlClassLoader);
try {
KieServices ks = KieServices.Factory.get();
KieRepository kieRepository = ks.getRepository();
ReleaseId releaseId = ks.newReleaseId("org.test", "kie-project-simple", "1.0.1");
KieModule kieModule = kieRepository.getKieModule(releaseId);
assertNull(kieModule);
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
}
use of org.kie.api.KieServices in project drools by kiegroup.
the class LifecycleTest method initSession.
@Before
public void initSession() {
String drlString = "package org.jboss.brms\n" + "import org.drools.compiler.StockTick\n" + "declare StockTick\n" + " @role( event )\n" + " @expires( 4s )\n" + "end\n" + "rule \"TestEventReceived\"\n" + " when\n" + " $event : StockTick() over window:time(4s) from entry-point EventStream\n" + " then\n" + " // do something;\n" + "end";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
final Resource drl = ks.getResources().newByteArrayResource(drlString.getBytes()).setTargetPath("org/jboss/brms/lifecycle.drl");
kfs.write(drl);
KieModuleModel kmoduleModel = ks.newKieModuleModel();
kmoduleModel.newKieBaseModel("defaultKBase").addPackage("*").setEventProcessingMode(EventProcessingOption.STREAM).newKieSessionModel("defaultKieSession").setDefault(true).setClockType(ClockTypeOption.get("pseudo"));
kfs.writeKModuleXML(kmoduleModel.toXML());
KieBuilder builder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, builder.getResults().getMessages().size());
this.kieSession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
}
use of org.kie.api.KieServices in project drools by kiegroup.
the class ExtendsTest method testDeclareExtendsWithFullyQualifiedName.
@Test
public void testDeclareExtendsWithFullyQualifiedName() {
String drl = "package org.drools.extends.test; \n" + "" + "declare org.drools.extends.test.Foo end \n" + "declare org.drools.extends.test.Bar extends org.drools.extends.test.Foo end \n" + "";
KieServices kieServices = KieServices.Factory.get();
KieFileSystem kfs = kieServices.newKieFileSystem();
kfs.write(kieServices.getResources().newByteArrayResource(drl.getBytes()).setSourcePath("test.drl").setResourceType(ResourceType.DRL));
KieBuilder kieBuilder = kieServices.newKieBuilder(kfs);
kieBuilder.buildAll();
assertFalse(kieBuilder.getResults().hasMessages(Message.Level.ERROR));
}
use of org.kie.api.KieServices in project drools by kiegroup.
the class I18nTest method testKieFileSystem.
@Test
public void testKieFileSystem() {
String str = "package org.drools.compiler.i18ntest;\n" + "import org.drools.compiler.I18nPerson;\n" + "\n" + "global java.util.List list;\n" + "rule \"名称 is 山田花子\"\n" + " when\n" + " p : I18nPerson( 名称 == \"山田花子\" )\n" + " then\n" + " list.add( \"名称は山田花子です\" );\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
ks.newKieBuilder(kfs).buildAll();
KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
List list = new ArrayList();
ksession.setGlobal("list", list);
I18nPerson i18nPerson = new I18nPerson();
i18nPerson.set名称("山田花子");
ksession.insert(i18nPerson);
ksession.fireAllRules();
assertTrue(list.contains("名称は山田花子です"));
ksession.dispose();
}
use of org.kie.api.KieServices in project drools by kiegroup.
the class I18nTest method testKieModuleJar.
@Test
public void testKieModuleJar() {
String str = "package org.drools.compiler.i18ntest;\n" + "import org.drools.compiler.I18nPerson;\n" + "\n" + "global java.util.List list;\n" + "rule \"名称 is 山田花子\"\n" + " when\n" + " p : I18nPerson( 名称 == \"山田花子\" )\n" + " then\n" + " list.add( \"名称は山田花子です\" );\n" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "118ntest", "1.0.0");
byte[] jar = createKJar(ks, releaseId, null, str);
KieModule km = deployJar(ks, jar);
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
List list = new ArrayList();
ksession.setGlobal("list", list);
I18nPerson i18nPerson = new I18nPerson();
i18nPerson.set名称("山田花子");
ksession.insert(i18nPerson);
ksession.fireAllRules();
assertTrue(list.contains("名称は山田花子です"));
ksession.dispose();
}
Aggregations