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));
}
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());
}
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;
}
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[][][][]"));
}
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
}
}
Aggregations