Search in sources :

Example 11 with ClassTypeResolver

use of org.kie.soup.project.datamodel.commons.types.ClassTypeResolver in project drools by kiegroup.

the class FactPopulatorTest method getTypeResolver.

private TypeResolver getTypeResolver() {
    TypeResolver resolver = new ClassTypeResolver(new HashSet<String>(), getClassLoader());
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.MyCollectionWrapper");
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.Cheesery");
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.Cheese");
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.SqlDateWrapper");
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.CheeseType");
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.Person");
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.OuterFact");
    return resolver;
}
Also used : ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)

Example 12 with ClassTypeResolver

use of org.kie.soup.project.datamodel.commons.types.ClassTypeResolver in project drools by kiegroup.

the class GlobalFactPopulatorTest method testWithGlobals.

@Test
public void testWithGlobals() throws Exception {
    FactData global = new FactData("Cheese", "c", Arrays.<Field>asList(new FieldData("type", "cheddar")), false);
    TypeResolver resolver = new ClassTypeResolver(new HashSet<String>(), Thread.currentThread().getContextClassLoader());
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.Cheese");
    KieSession ksession = mock(KieSession.class);
    Map<String, Object> populatedData = new HashMap<String, Object>();
    Map<String, Object> globalData = new HashMap<String, Object>();
    GlobalFactPopulator globalFactPopulator = new GlobalFactPopulator(populatedData, resolver, global, globalData);
    globalFactPopulator.populate(ksession, new HashMap<String, FactHandle>());
    verify(ksession).setGlobal(eq(global.getName()), any(Object.class));
    assertEquals(1, globalData.size());
    assertEquals(0, populatedData.size());
}
Also used : HashMap(java.util.HashMap) FactHandle(org.kie.api.runtime.rule.FactHandle) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactData(org.drools.workbench.models.testscenarios.shared.FactData) KieSession(org.kie.api.runtime.KieSession) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) Test(org.junit.Test)

Example 13 with ClassTypeResolver

use of org.kie.soup.project.datamodel.commons.types.ClassTypeResolver in project drools by kiegroup.

the class NewFactPopulatorTest method setUp.

@Before
public void setUp() throws Exception {
    typeResolver = new ClassTypeResolver(new HashSet<String>(), Thread.currentThread().getContextClassLoader());
    populatedData = new HashMap<String, Object>();
    workingMemory = mock(KieSession.class);
}
Also used : KieSession(org.kie.api.runtime.KieSession) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 14 with ClassTypeResolver

use of org.kie.soup.project.datamodel.commons.types.ClassTypeResolver in project drools by kiegroup.

the class ToTypedExpressionTest method setUp.

@Before
public void setUp() throws Exception {
    imports = new HashSet<>();
    packageModel = new PackageModel("", null, false, null);
    typeResolver = new ClassTypeResolver(imports, getClass().getClassLoader());
    ruleContext = new RuleContext(knowledgeBuilder, packageModel, ruleDescr, typeResolver, true);
    imports.add("org.drools.modelcompiler.domain.Person");
}
Also used : PackageModel(org.drools.modelcompiler.builder.PackageModel) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) Before(org.junit.Before)

Example 15 with ClassTypeResolver

use of org.kie.soup.project.datamodel.commons.types.ClassTypeResolver in project drools by kiegroup.

the class PackageHeaderLoader method findImportsFromJars.

private void findImportsFromJars(Collection<String> imports, List<JarInputStream> jarInputStreams) throws IOException {
    ClassTypeResolver resolver = new ClassTypeResolver(new HashSet<String>(), new VerifierMapBackedClassLoader(jarInputStreams));
    for (String className : imports) {
        classNames.add(className);
        try {
            Class clazz = resolver.resolveType(className);
            addFields(clazz);
        } catch (ClassNotFoundException e) {
            missingClasses.add(className);
        }
    }
}
Also used : ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)

Aggregations

ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)28 Test (org.junit.Test)21 HashSet (java.util.HashSet)19 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)9 FactAssignmentField (org.drools.workbench.models.testscenarios.shared.FactAssignmentField)3 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)3 KieSession (org.kie.api.runtime.KieSession)3 HashMap (java.util.HashMap)2 Cheese (org.drools.core.test.model.Cheese)2 FirstClass (org.drools.core.test.model.FirstClass)2 Mouse (org.drools.workbench.models.testscenarios.backend.Mouse)2 FactData (org.drools.workbench.models.testscenarios.shared.FactData)2 Before (org.junit.Before)2 Date (java.util.Date)1 ClassFieldAccessorCache (org.drools.core.base.ClassFieldAccessorCache)1 InternalAgendaGroup (org.drools.core.common.InternalAgendaGroup)1 ProjectClassLoader (org.drools.core.common.ProjectClassLoader)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1