use of org.drools.core.definitions.InternalKnowledgePackage in project drools by kiegroup.
the class WeaverTest method testBayesPackageWeaving.
@Test
public void testBayesPackageWeaving() throws Exception {
KnowledgeBuilderImpl kbuilder = new KnowledgeBuilderImpl();
kbuilder.add(ResourceFactory.newClassPathResource("Garden.xmlbif", AssemblerTest.class), ResourceType.BAYES);
InternalKnowledgeBase kbase = getKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
InternalKnowledgePackage kpkg = (InternalKnowledgePackage) kbase.getKiePackage("org.drools.beliefs.bayes.integration");
Map<ResourceType, ResourceTypePackage> map = kpkg.getResourceTypePackages();
BayesPackage existing = (BayesPackage) map.get(ResourceType.BAYES);
JunctionTree jtree = existing.getJunctionTree("Garden");
assertNotNull(jtree);
}
use of org.drools.core.definitions.InternalKnowledgePackage in project drools by kiegroup.
the class FactTemplateTest method testFacts.
@Test
public void testFacts() {
InternalKnowledgePackage pkg = new KnowledgePackageImpl("org.store");
final FieldTemplate cheeseName = new FieldTemplateImpl("name", 0, String.class);
final FieldTemplate cheesePrice = new FieldTemplateImpl("price", 1, Integer.class);
final FieldTemplate[] fields1 = new FieldTemplate[] { cheeseName, cheesePrice };
final FactTemplate cheese1 = new FactTemplateImpl(pkg, "Cheese", fields1);
final Fact stilton1 = cheese1.createFact(10);
stilton1.setFieldValue("name", "stilton");
stilton1.setFieldValue("price", new Integer(200));
final Fact stilton2 = cheese1.createFact(11);
stilton2.setFieldValue(0, "stilton");
stilton2.setFieldValue(1, new Integer(200));
assertEquals(stilton1, stilton2);
assertEquals(stilton1.hashCode(), stilton2.hashCode());
final Fact brie = cheese1.createFact(12);
brie.setFieldValue("name", "brie");
brie.setFieldValue("price", new Integer(55));
assertFalse(stilton1.equals(brie));
assertFalse(stilton1.hashCode() == brie.hashCode());
}
use of org.drools.core.definitions.InternalKnowledgePackage in project drools by kiegroup.
the class FactTemplateTest method testFieldsAndGetters.
@Test
public void testFieldsAndGetters() {
InternalKnowledgePackage pkg = new KnowledgePackageImpl("org.store");
final FieldTemplate cheeseName = new FieldTemplateImpl("name", 0, String.class);
final FieldTemplate cheesePrice = new FieldTemplateImpl("price", 1, Integer.class);
final FieldTemplate[] fields = new FieldTemplate[] { cheeseName, cheesePrice };
final FactTemplate cheese = new FactTemplateImpl(pkg, "Cheese", fields);
assertEquals("org.store", cheese.getPackage().getName());
assertEquals("Cheese", cheese.getName());
assertEquals(2, cheese.getNumberOfFields());
assertSame(fields, cheese.getAllFieldTemplates());
assertSame(cheeseName, cheese.getFieldTemplate(0));
assertSame(cheesePrice, cheese.getFieldTemplate(1));
assertSame(cheeseName, cheese.getFieldTemplate("name"));
assertSame(cheesePrice, cheese.getFieldTemplate("price"));
assertEquals(0, cheese.getFieldTemplateIndex("name"));
assertEquals(1, cheese.getFieldTemplateIndex("price"));
}
use of org.drools.core.definitions.InternalKnowledgePackage in project drools by kiegroup.
the class FactTemplateFieldExtractorTest method testDeclaration.
@Test
public void testDeclaration() {
InternalKnowledgePackage pkg = new KnowledgePackageImpl("org.store");
final FieldTemplate cheeseName = new FieldTemplateImpl("name", 0, String.class);
final FieldTemplate cheesePrice = new FieldTemplateImpl("price", 1, Integer.class);
final FieldTemplate[] fields = new FieldTemplate[] { cheeseName, cheesePrice };
final FactTemplate cheese = new FactTemplateImpl(pkg, "Cheese", fields);
final InternalReadAccessor extractName = new FactTemplateFieldExtractor(cheese, 0);
final Pattern pattern = new Pattern(0, new FactTemplateObjectType(cheese));
final Declaration declaration = new Declaration("typeOfCheese", extractName, pattern);
final Fact brie = cheese.createFact(12);
brie.setFieldValue("name", "brie");
brie.setFieldValue("price", new Integer(55));
// Check we can extract Declarations correctly
assertEquals("brie", declaration.getValue(null, brie));
}
use of org.drools.core.definitions.InternalKnowledgePackage in project drools by kiegroup.
the class FactTemplateFieldExtractorTest method testExtractor.
@Test
public void testExtractor() {
InternalKnowledgePackage pkg = new KnowledgePackageImpl("org.store");
final FieldTemplate cheeseName = new FieldTemplateImpl("name", 0, String.class);
final FieldTemplate cheesePrice = new FieldTemplateImpl("price", 1, Integer.class);
final FieldTemplate[] fields = new FieldTemplate[] { cheeseName, cheesePrice };
final FactTemplate cheese = new FactTemplateImpl(pkg, "Cheese", fields);
final InternalReadAccessor extractName = new FactTemplateFieldExtractor(cheese, 0);
final InternalReadAccessor extractPrice = new FactTemplateFieldExtractor(cheese, 1);
final Fact stilton = cheese.createFact(10);
stilton.setFieldValue("name", "stilton");
stilton.setFieldValue("price", new Integer(200));
assertEquals("stilton", extractName.getValue(null, stilton));
assertEquals(new Integer(200), extractPrice.getValue(null, stilton));
assertFalse(extractName.isNullValue(null, stilton));
stilton.setFieldValue("name", null);
assertTrue(extractName.isNullValue(null, stilton));
assertFalse(extractPrice.isNullValue(null, stilton));
final Fact brie = cheese.createFact(12);
brie.setFieldValue("name", "brie");
brie.setFieldValue("price", new Integer(55));
assertEquals("brie", extractName.getValue(null, brie));
assertEquals(new Integer(55), extractPrice.getValue(null, brie));
assertFalse(extractName.isNullValue(null, brie));
brie.setFieldValue("name", null);
assertTrue(extractName.isNullValue(null, brie));
assertFalse(extractPrice.isNullValue(null, stilton));
}
Aggregations