use of org.drools.traits.core.factmodel.TripleBasedBean in project drools by kiegroup.
the class TraitTest method testInternalComponents1.
@Test
public void testInternalComponents1() {
String source = "org/drools/compiler/factmodel/traits/testTraitDon.drl";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
Resource res = ResourceFactory.newClassPathResource(source);
assertNotNull(res);
kbuilder.add(res, ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
InternalKnowledgeBase kb = KnowledgeBaseFactory.newKnowledgeBase();
kb.addPackages(kbuilder.getKnowledgePackages());
TraitFactoryImpl.setMode(mode, kb);
TraitFactoryImpl tFactory = (TraitFactoryImpl) RuntimeComponentFactory.get().getTraitFactory(kb);
try {
FactType impClass = kb.getFactType("org.drools.compiler.trait.test", "Imp");
TraitableBean imp = (TraitableBean) impClass.newInstance();
FactType traitClass = kb.getFactType("org.drools.compiler.trait.test", "Student");
Class trait = traitClass.getFactClass();
TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait);
Object proxyFields = proxy.getFields();
Object coreTraits = imp._getTraitMap();
Object coreProperties = imp._getDynamicProperties();
assertTrue(proxy.getObject() instanceof TraitableBean);
assertNotNull(proxyFields);
assertNotNull(coreTraits);
assertNotNull(coreProperties);
if (mode == VirtualPropertyMode.MAP) {
assertTrue(proxyFields instanceof MapWrapper);
assertTrue(coreTraits instanceof TraitTypeMapImpl);
assertTrue(coreProperties instanceof HashMap);
} else {
assertEquals("org.drools.compiler.trait.test.Student.org.drools.compiler.trait.test.Imp_ProxyWrapper", proxyFields.getClass().getName());
assertTrue(proxyFields instanceof TripleBasedStruct);
assertTrue(coreTraits instanceof TraitTypeMapImpl);
assertTrue(coreProperties instanceof TripleBasedBean);
}
StudentProxyImpl2 sp2 = new StudentProxyImpl2(new Imp2(), null);
System.out.println(sp2.toString());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
Aggregations