use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class SecurityPolicyTest method testCustomAccumulate.
@Test
public void testCustomAccumulate() throws Exception {
String drl = "package org.foo.bar\n" + "rule testRule\n" + " when\n" + " Number() from accumulate(Object(), " + " init(System.exit(-1);), " + " action(System.exit(-1);), " + " reverse(System.exit(-1);), " + " result(0))\n" + " then\n" + "end";
try {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write(ResourceFactory.newByteArrayResource(drl.getBytes()).setSourcePath("org/foo/bar/r1.drl"));
ks.newKieBuilder(kfs).buildAll();
ReleaseId releaseId = ks.getRepository().getDefaultReleaseId();
KieContainer kc = ks.newKieContainer(releaseId);
KieSession ksession = kc.newKieSession();
ksession.fireAllRules();
Assert.fail("The security policy for the rule should have prevented this from executing...");
} catch (ShouldHavePrevented e) {
Assert.fail("The security policy for the rule should have prevented this from executing...");
} catch (Exception e) {
// test succeeded. the policy in place prevented the rule from executing the System.exit().
}
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class StrictAnnotationTest method testImportedAnnotation.
@Test
public void testImportedAnnotation() throws Exception {
String str = "package org.simple \n" + "import " + Xyz.class.getCanonicalName() + " \n" + "@Xyz rule yyy \n" + "when \n" + " $s : String()\n" + "then \n" + "end \n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str).writeKModuleXML(ks.newKieModuleModel().setConfigurationProperty(LanguageLevelOption.PROPERTY_NAME, LanguageLevelOption.DRL6_STRICT.toString()).toXML());
Results results = ks.newKieBuilder(kfs).buildAll().getResults();
assertEquals(0, results.getMessages().size());
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class SequentialTest method testSequentialWithNoLoop.
@Test(timeout = 10000L)
public void testSequentialWithNoLoop() throws Exception {
// BZ-1228098
String str = "package org.drools.compiler.test\n" + "import \n" + Message.class.getCanonicalName() + ";" + "rule R1 no-loop when\n" + " $s : String( )" + " $m : Message( )\n" + "then\n" + " modify($m) { setMessage($s) };\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/r0.drl", str);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results results = kieBuilder.getResults();
if (results.hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
throw new RuntimeException(results.getMessages().toString());
}
KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
KieBaseConfiguration kieBaseConf = ks.newKieBaseConfiguration();
kieBaseConf.setOption(SequentialOption.YES);
StatelessKieSession sequentialKsession = kieContainer.newKieBase(kieBaseConf).newStatelessKieSession();
List result = (List) sequentialKsession.execute(CommandFactory.newInsertElements(Arrays.asList("test", new Message())));
assertEquals(2, result.size());
StatelessKieSession ksession = kieContainer.getKieBase().newStatelessKieSession();
result = (List) ksession.execute(CommandFactory.newInsertElements(Arrays.asList("test", new Message())));
assertEquals(2, result.size());
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class BasicUpdateTest method setUp.
@Before
public void setUp() {
final KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
kfs.write(KieServices.Factory.get().getResources().newClassPathResource(UPDATE_TEST_DRL, DeleteTest.class));
final KieBuilder kbuilder = KieServices.Factory.get().newKieBuilder(kfs);
kbuilder.buildAll();
final List<Message> res = kbuilder.getResults().getMessages(Message.Level.ERROR);
assertEquals(res.toString(), 0, res.size());
final KieBase kbase = KieServices.Factory.get().newKieContainer(kbuilder.getKieModule().getReleaseId()).getKieBase();
ksession = kbase.newKieSession();
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class DslExpansionTest method testDSLExpansion_MessageImplNPE.
@Test
public void testDSLExpansion_MessageImplNPE() throws Exception {
final KieServices ks = KieServices.Factory.get();
final ReleaseId releaseId = ks.newReleaseId("org.kie", "dsl-test", "1.0-SNAPSHOT");
final KieModuleModel kproj = ks.newKieModuleModel();
final KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML()).writePomXML(generatePomXml(releaseId)).write("src/main/resources/KBase1/test-dsl.dsl", createDSL()).write("src/main/resources/KBase1/test-rule.dslr", createDRL());
final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
final List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
if (!messages.isEmpty()) {
for (final Message m : messages) {
System.out.println(m.getText());
}
}
assertTrue(messages.isEmpty());
}
Aggregations