use of org.drools.core.io.impl.ByteArrayResource in project drools by kiegroup.
the class ExtendsTest method testMultipleInheritanceWithPosition1.
@Test
public void testMultipleInheritanceWithPosition1() throws Exception {
// DROOLS-249
String drl = "package org.drools.test\n" + "declare trait PosTrait\n" + "@propertyReactive\n" + " field0 : int = 100 //@position(0)\n" + " field1 : int = 101 //@position(1)\n" + " field2 : int = 102 //@position(0)\n" + "end\n" + "\n" + "declare trait MultiInhPosTrait extends PosTrait\n" + "@propertyReactive\n" + " mfield0 : int = 200 //@position(0)\n" + " mfield1 : int = 201 @position(2)\n" + "end";
KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kBuilder.add(new ByteArrayResource(drl.getBytes()), ResourceType.DRL);
if (kBuilder.hasErrors()) {
System.err.println(kBuilder.getErrors());
}
assertFalse(kBuilder.hasErrors());
InternalKnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowledgeBase.addPackages(kBuilder.getKnowledgePackages());
FactType sw = knowledgeBase.getFactType("org.drools.test", "MultiInhPosTrait");
assertEquals(5, sw.getFields().size());
assertEquals("field0", sw.getFields().get(0).getName());
assertEquals("field1", sw.getFields().get(1).getName());
assertEquals("mfield1", sw.getFields().get(2).getName());
assertEquals("field2", sw.getFields().get(3).getName());
assertEquals("mfield0", sw.getFields().get(4).getName());
}
use of org.drools.core.io.impl.ByteArrayResource in project drools by kiegroup.
the class ExtendsTest method testExtendSelf.
@Test
public void testExtendSelf() throws Exception {
String s1 = "package org.drools;\n" + "global java.util.List list;\n" + "\n" + "declare Bean extends Bean \n" + " foo : int @key\n" + "end\n";
KieBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kBuilder.add(new ByteArrayResource(s1.getBytes()), ResourceType.DRL);
assertTrue(kBuilder.hasErrors());
}
use of org.drools.core.io.impl.ByteArrayResource in project drools by kiegroup.
the class ExtendsTest method testExtendOverride.
@Test
public void testExtendOverride() {
String drl = "package test.beans;\n" + "\n" + "import java.util.List;\n" + "import java.util.ArrayList;\n" + "\n" + "global List ans;" + "\n" + "\n" + "declare ArrayList\n" + "end\n" + "" + "declare Bean extends ArrayList\n" + " fld : int = 4 \n" + " myField : String = \"xxx\" \n" + "end\n" + "\n" + "declare Bean2 extends Bean\n" + " moref : double\n" + " myField : String\n" + "end\n" + "rule \"Init\"\n" + "when\n" + "then\n" + " Bean b = new Bean2();\n" + " ans.add(b);" + " System.out.println(b);\t\n" + "end\n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ByteArrayResource(drl.getBytes()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = createKnowledgeSession(kbase);
List out = new ArrayList();
ksession.setGlobal("ans", out);
ksession.fireAllRules();
Object x = out.get(0);
FactType type = kbase.getFactType("test.beans", "Bean2");
assertEquals(4, type.get(x, "fld"));
assertEquals("xxx", type.get(x, "myField"));
assertEquals(0.0, type.get(x, "moref"));
assertTrue(x instanceof ArrayList);
}
use of org.drools.core.io.impl.ByteArrayResource in project drools by kiegroup.
the class Misc2Test method testUnsupportedPolymorphicDeclaration.
@Test
public void testUnsupportedPolymorphicDeclaration() {
// DROOLS-162
String drl = "package org.drools.test; \n" + "" + "declare Foo end \n" + "declare Bar end \n" + "" + "" + "rule X when\n" + " $x : Foo() " + " or " + " $x : Bar() \n" + "then\n" + " System.out.println( $x ); \n" + "end\n" + "" + "rule Init\n" + "when\n" + "then\n" + " insert( new Foo() ); \n" + " insert( new Bar() ); \n" + "end";
KnowledgeBuilder kb = KnowledgeBuilderFactory.newKnowledgeBuilder();
kb.add(new ByteArrayResource(drl.getBytes()), ResourceType.DRL);
assertTrue(kb.hasErrors());
}
use of org.drools.core.io.impl.ByteArrayResource in project drools by kiegroup.
the class Misc2Test method testReportErrorOnWrongDateEffective.
@Test
public void testReportErrorOnWrongDateEffective() {
// BZ-1013545
String drl = // ensure no Locale can parse the Date
"rule X date-effective \"9-asbrdfh-1974\" when\n" + " $s : String() " + "then\n" + "end\n";
KnowledgeBuilder kb = KnowledgeBuilderFactory.newKnowledgeBuilder();
kb.add(new ByteArrayResource(drl.getBytes()), ResourceType.DRL);
assertTrue(kb.hasErrors());
}
Aggregations