use of org.drools.core.definitions.rule.impl.GlobalImpl in project drools by kiegroup.
the class KnowledgePackageMetaDataTest method testMetaData.
@Test
public void testMetaData() {
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());
KiePackage pack = kBase.getPackage("org.drools.compiler.test.definitions");
assertNotNull(pack);
assertEquals(2, pack.getFunctionNames().size());
assertTrue(pack.getFunctionNames().contains("fun1"));
assertTrue(pack.getFunctionNames().contains("fun2"));
assertEquals(2, pack.getGlobalVariables().size());
GlobalImpl g1 = new GlobalImpl("N", "java.lang.Integer");
GlobalImpl g2 = new GlobalImpl("list", "java.util.List");
assertTrue(pack.getGlobalVariables().contains(g1));
assertTrue(pack.getGlobalVariables().contains(g2));
assertEquals(2, pack.getFactTypes().size());
FactType type;
for (int j = 0; j < 2; j++) {
type = pack.getFactTypes().iterator().next();
if (type.getName().equals("org.drools.compiler.test.definitions.Person")) {
assertEquals(2, type.getFields().size());
} else if (type.getName().equals("org.drools.compiler.test.definitions.Foo")) {
assertEquals("org.drools.compiler.test.definitions.Person", type.getSuperClass());
FactField fld = type.getField("bar");
assertEquals(2, fld.getIndex());
assertEquals(String.class, fld.getType());
} else {
fail("Unexpected fact type " + type);
}
}
assertEquals(2, pack.getQueries().size());
for (Query q : pack.getQueries()) {
assertTrue(q.getName().equals("qry1") || q.getName().equals("qry2"));
}
assertEquals(4, pack.getRules().size());
assertTrue(pack.getRules().containsAll(pack.getQueries()));
}
Aggregations