use of org.kie.internal.builder.KnowledgeBuilderResults in project drools by kiegroup.
the class TypeDeclarationTest method testNoAnnotationUpdateIfError.
@Test
public void testNoAnnotationUpdateIfError() {
String str1 = "";
str1 += "package org.drools.compiler \n" + "declare org.drools.EventA \n" + " name : String \n" + " duration : Long \n" + "end \n";
String str2 = "";
str2 += "package org.drools.compiler \n" + "declare org.drools.EventA \n" + " @role (event) \n" + " @duration (duration) \n" + " anotherField : String \n" + "end \n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str1.getBytes()), ResourceType.DRL);
kbuilder.add(ResourceFactory.newByteArrayResource(str2.getBytes()), ResourceType.DRL);
if (!kbuilder.hasErrors()) {
fail("Errors Expected");
}
// No Warnings
KnowledgeBuilderResults warnings = kbuilder.getResults(ResultSeverity.WARNING);
assertEquals(0, warnings.size());
// just 1 package was created
assertEquals(0, kbuilder.getKnowledgePackages().size());
}
use of org.kie.internal.builder.KnowledgeBuilderResults in project drools by kiegroup.
the class Misc2Test method testDontFailOnDuplicatedRuleWithDeclaredTypeError.
@Test
public void testDontFailOnDuplicatedRuleWithDeclaredTypeError() {
String rule1 = "rule \"Some Rule\"\n" + "when\n" + " $s: String()\n" + "then\n" + "end";
String rule2 = "declare DClass\n" + " prop : String\n" + "end\n" + "rule \"Some Rule\"\n" + "when\n" + " $d: DClass()\n" + "then\n" + "end";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(rule1.getBytes()), ResourceType.DRL);
kbuilder.add(ResourceFactory.newByteArrayResource(rule2.getBytes()), ResourceType.DRL);
// rules.
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
// We must have 1 INFO result.
KnowledgeBuilderResults infos = kbuilder.getResults(ResultSeverity.INFO);
assertNotNull(infos);
assertEquals(1, infos.size());
}
use of org.kie.internal.builder.KnowledgeBuilderResults in project drools by kiegroup.
the class TypeDeclarationTest method testAnnotationReDefinition.
@Test
public void testAnnotationReDefinition() {
String str1 = "";
str1 += "package org.kie \n" + "declare org.kie.EventA \n" + " name : String \n" + " duration : Long \n" + "end \n";
String str2 = "";
str2 += "package org.kie \n" + "declare org.kie.EventA \n" + " @role (event) \n" + " @duration (duration) \n" + "end \n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str1.getBytes()), ResourceType.DRL);
kbuilder.add(ResourceFactory.newByteArrayResource(str2.getBytes()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
// No Warnings
KnowledgeBuilderResults warnings = kbuilder.getResults(ResultSeverity.WARNING);
Assert.assertEquals(0, warnings.size());
// just 1 package was created
Assert.assertEquals(1, kbuilder.getKnowledgePackages().size());
// Get the Fact Type for org.kie.EventA
FactType factType = ((KnowledgePackageImpl) kbuilder.getKnowledgePackages().iterator().next()).getFactType("org.kie.EventA");
assertNotNull(factType);
// 'name' field must still be there
FactField field = factType.getField("name");
assertNotNull(field);
// 'duration' field must still be there
field = factType.getField("duration");
assertNotNull(field);
// New Annotations must be there too
TypeDeclaration typeDeclaration = ((KnowledgePackageImpl) kbuilder.getKnowledgePackages().iterator().next()).getTypeDeclaration("EventA");
assertEquals(Role.Type.EVENT, typeDeclaration.getRole());
assertEquals("duration", typeDeclaration.getDurationAttribute());
}
Aggregations