use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class RuleBuilderTest method testInvalidDialect.
@Test
public void testInvalidDialect() throws Exception {
final PackageDescr pkgDescr = new PackageDescr("org.drools");
final RuleDescr ruleDescr = new RuleDescr("Test Rule");
ruleDescr.addAttribute(new AttributeDescr("dialect", "mvl"));
ruleDescr.setConsequence("");
pkgDescr.addRule(ruleDescr);
final KnowledgeBuilderImpl kBuilder = new KnowledgeBuilderImpl();
kBuilder.addPackage(pkgDescr);
assertFalse(kBuilder.getErrors().toString(), kBuilder.getErrors().isEmpty());
}
use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class PackageDescrTest method testGetPreferredPkgUUID.
@Test
public void testGetPreferredPkgUUID() {
PackageDescr descr = new PackageDescr();
assertFalse(descr.getPreferredPkgUUID().isPresent());
String pkgUUID = generateUUID();
descr.setPreferredPkgUUID(pkgUUID);
assertTrue(descr.getPreferredPkgUUID().isPresent());
assertEquals(pkgUUID, descr.getPreferredPkgUUID().get());
}
use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class PackageDescrTest method testAttributeOverriding.
@Test
public void testAttributeOverriding() {
PackageDescr desc = new PackageDescr("foo");
AttributeDescr at1 = new AttributeDescr("foo", "bar");
AttributeDescr at2 = new AttributeDescr("foo2", "default");
desc.addAttribute(at1);
desc.addAttribute(at2);
RuleDescr rule = new RuleDescr("abc");
rule.addAttribute(new AttributeDescr("foo", "overridden"));
desc.addRule(rule);
List pkgAts = desc.getAttributes();
assertEquals("bar", ((AttributeDescr) pkgAts.get(0)).getValue());
assertEquals("default", ((AttributeDescr) pkgAts.get(1)).getValue());
desc.afterRuleAdded(rule);
Map<String, AttributeDescr> ruleAts = rule.getAttributes();
assertEquals("overridden", ((AttributeDescr) ruleAts.get("foo")).getValue());
assertEquals("default", ((AttributeDescr) ruleAts.get("foo2")).getValue());
}
use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class PackageDescrTest method testSerializationImportDescr.
@Test
public void testSerializationImportDescr() {
PackageDescrBuilder builder = DescrFactory.newPackage().name("foo");
String className = Person.class.getName();
builder.newImport().target(className).end();
PackageDescr descr = builder.getDescr();
ImportDescr importDescr = new ImportDescr(className);
ImportDescr badImportDescr = new ImportDescr(null);
assertTrue(descr.getImports().contains(importDescr));
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(baos);
descr.writeExternal(out);
ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
PackageDescr newDescr = new PackageDescr();
newDescr.readExternal(in);
assertFalse(newDescr.getImports().contains(badImportDescr));
assertTrue(newDescr.getImports().contains(importDescr));
assertFalse(newDescr.getPreferredPkgUUID().isPresent());
} catch (IOException | ClassNotFoundException e) {
fail(e.getMessage());
}
}
use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class PackageDescrTest method testSerializationPkgUUID.
@Test
public void testSerializationPkgUUID() {
PackageDescrBuilder builder = DescrFactory.newPackage().name("foo");
String className = Person.class.getName();
builder.newImport().target(className).end();
PackageDescr descr = builder.getDescr();
String pkgUUID = generateUUID();
descr.setPreferredPkgUUID(pkgUUID);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(baos);
descr.writeExternal(out);
ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
PackageDescr newDescr = new PackageDescr();
newDescr.readExternal(in);
assertTrue(newDescr.getPreferredPkgUUID().isPresent());
assertEquals(pkgUUID, newDescr.getPreferredPkgUUID().get());
} catch (IOException | ClassNotFoundException e) {
fail(e.getMessage());
}
}
Aggregations