Search in sources :

Example 16 with ClassTypeResolver

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

the class ScenarioRunner method run.

public void run(final Scenario scenario) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException, InvalidClockTypeException {
    final Map<String, Object> populatedData = new HashMap<String, Object>();
    final Map<String, Object> globalData = new HashMap<String, Object>();
    // This looks safe!
    final KieBase kieBase = ksession.getKieBase();
    final ClassLoader classloader2 = ((InternalKnowledgeBase) kieBase).getRootClassLoader();
    final ClassTypeResolver resolver = new ClassTypeResolver(getImports(scenario), classloader2);
    this.workingMemoryWrapper = new TestScenarioKSessionWrapper(ksession, resolver, populatedData, globalData, scenarioUsesTimeWalk(scenario));
    this.factPopulatorFactory = new FactPopulatorFactory(populatedData, globalData, resolver);
    this.factPopulator = new FactPopulator(ksession, populatedData);
    MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
    scenario.setLastRunResult(new Date());
    populateGlobals(scenario.getGlobals());
    applyFixtures(scenario.getFixtures(), createScenarioSettings(scenario));
}
Also used : FactPopulatorFactory(org.drools.workbench.models.testscenarios.backend.populators.FactPopulatorFactory) FactPopulator(org.drools.workbench.models.testscenarios.backend.populators.FactPopulator) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Date(java.util.Date)

Example 17 with ClassTypeResolver

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

the class FactAssignmentFieldPopulatorTest method testMatryoshkaDollSituation.

@Test
public void testMatryoshkaDollSituation() throws Exception {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    TypeResolver typeResolver = new ClassTypeResolver(new HashSet<String>(), classLoader);
    typeResolver.addImport("org.drools.workbench.models.testscenarios.backend.MatryoshkaDoll");
    MatryoshkaDoll matryoshkaDoll = new MatryoshkaDoll();
    FactAssignmentField factAssignmentField = createFactAssignmentField();
    addFactAssignmentFieldIntoFactAssignmentField(factAssignmentField, 5);
    FactAssignmentFieldPopulator factAssignmentFieldPopulator = new FactAssignmentFieldPopulator(matryoshkaDoll, factAssignmentField, typeResolver);
    factAssignmentFieldPopulator.populate(new HashMap<String, Object>());
    assertNotNull(matryoshkaDoll.getMatryoshkaDoll());
    assertNotNull(matryoshkaDoll.getMatryoshkaDoll().getMatryoshkaDoll());
    assertNotNull(matryoshkaDoll.getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll());
    assertNotNull(matryoshkaDoll.getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll());
    assertNotNull(matryoshkaDoll.getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll());
    assertNotNull(matryoshkaDoll.getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll());
    assertNull(matryoshkaDoll.getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll());
}
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) MatryoshkaDoll(org.drools.workbench.models.testscenarios.backend.MatryoshkaDoll) FactAssignmentField(org.drools.workbench.models.testscenarios.shared.FactAssignmentField) Test(org.junit.Test)

Example 18 with ClassTypeResolver

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

the class KiePackagesBuilder method createKiePackage.

private KnowledgePackageImpl createKiePackage(String name) {
    KnowledgePackageImpl kpkg = new KnowledgePackageImpl(name);
    kpkg.setClassFieldAccessorCache(new ClassFieldAccessorCache(configuration.getClassLoader()));
    TypeResolver typeResolver = new ClassTypeResolver(new HashSet<>(kpkg.getImports().keySet()), configuration.getClassLoader(), name);
    typeResolver.addImport(name + ".*");
    kpkg.setTypeResolver(typeResolver);
    return kpkg;
}
Also used : ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) KnowledgePackageImpl(org.drools.core.definitions.impl.KnowledgePackageImpl) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)

Example 19 with ClassTypeResolver

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

the class ClassTypeResolverTest method testResolveMultidimensionnalArrayOfPrimitiveTypes.

@Test
public void testResolveMultidimensionnalArrayOfPrimitiveTypes() throws Exception {
    final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
    assertEquals(int[][].class, resolver.resolveType("int[][]"));
    assertEquals(int[][][].class, resolver.resolveType("int[][][]"));
    assertEquals(int[][][][].class, resolver.resolveType("int[][][][]"));
}
Also used : ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with ClassTypeResolver

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

the class ClassTypeResolverTest method testDefaultPackageImport.

@Test
public void testDefaultPackageImport() throws Exception {
    final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
    resolver.addImport("Goo");
    try {
        resolver.resolveType("Goo");
        fail("Can't import default namespace classes");
    } catch (ClassNotFoundException e) {
    // swallow as this should be thrown
    }
}
Also used : ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

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