use of org.kie.soup.project.datamodel.commons.types.ClassTypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testResolveMultidimensionnalArrayOfObjectsFromImport.
@Test
public void testResolveMultidimensionnalArrayOfObjectsFromImport() throws Exception {
final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
resolver.addImport("org.drools.core.test.model.Cheese");
assertEquals(String[][].class, resolver.resolveType("String[][]"));
assertEquals(String[][].class, resolver.resolveType("java.lang.String[][]"));
assertEquals(Cheese[][].class, resolver.resolveType("Cheese[][]"));
assertEquals(Cheese[][].class, resolver.resolveType("org.drools.core.test.model.Cheese[][]"));
}
use of org.kie.soup.project.datamodel.commons.types.ClassTypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testResolveObjectFromImport.
@Test
public void testResolveObjectFromImport() throws Exception {
final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
resolver.addImport("org.drools.core.test.model.Cheese");
resolver.addImport("org.drools.core.test.model.FirstClass");
resolver.addImport("org.drools.core.test.model.FirstClass.AlternativeKey");
resolver.addImport("org.drools.core.test.model.SecondClass");
resolver.addImport("org.drools.core.test.model.SecondClass.AlternativeKey");
assertEquals(String.class, resolver.resolveType("String"));
assertEquals(String.class, resolver.resolveType("java.lang.String"));
assertEquals(Cheese.class, resolver.resolveType("Cheese"));
assertEquals(Cheese.class, resolver.resolveType("org.drools.core.test.model.Cheese"));
assertEquals(FirstClass.class, resolver.resolveType("org.drools.core.test.model.FirstClass"));
assertEquals(FirstClass.AlternativeKey.class, resolver.resolveType("org.drools.core.test.model.FirstClass.AlternativeKey"));
assertEquals(SecondClass.class, resolver.resolveType("org.drools.core.test.model.SecondClass"));
assertEquals(SecondClass.AlternativeKey.class, resolver.resolveType("org.drools.core.test.model.SecondClass.AlternativeKey"));
}
use of org.kie.soup.project.datamodel.commons.types.ClassTypeResolver in project drools by kiegroup.
the class ScenarioRunnerTest method testRuleFlowGroupActivation.
@Test
public void testRuleFlowGroupActivation() throws Exception {
Scenario scenario = new Scenario();
scenario.getImports().addImport(new Import("foo.bar.Coolness"));
Fixture[] given = new Fixture[] { new FactData("Coolness", "c", Arrays.<Field>asList(new FieldData("num", "42"), new FieldData("name", "mic")), false) };
scenario.getFixtures().addAll(Arrays.asList(given));
ExecutionTrace executionTrace = new ExecutionTrace();
scenario.getRules().add("rule1");
scenario.setInclusive(true);
scenario.getFixtures().add(executionTrace);
Expectation[] assertions = new Expectation[2];
assertions[0] = new VerifyFact("c", ls(new VerifyField("num", "42", "==")));
assertions[1] = new VerifyRuleFired("rule1", 1, null);
scenario.getFixtures().addAll(Arrays.asList(assertions));
KieSession ksession = getKieSession("rule_flow_actication.drl");
ClassLoader classLoader = ((KnowledgeBaseImpl) ksession.getKieBase()).getRootClassLoader();
HashSet<String> imports = new HashSet<String>();
imports.add("foo.bar.*");
TypeResolver resolver = new ClassTypeResolver(imports, classLoader);
Class<?> coolnessClass = classLoader.loadClass("foo.bar.Coolness");
assertNotNull(coolnessClass);
ClassLoader cl_ = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);
// resolver will need to have generated beans in it - possibly using a composite classloader from the package,
// including whatever CL has the generated beans...
ScenarioRunner scenarioRunner = new ScenarioRunner(ksession);
scenarioRunner.run(scenario);
assertEquals(0, executionTrace.getNumberOfRulesFired().intValue());
assertFalse(scenario.wasSuccessful());
// Activate rule flow
scenario.getFixtures().clear();
given = new Fixture[] { new FactData("Coolness", "c", Arrays.<Field>asList(new FieldData("num", "42"), new FieldData("name", "mic")), false), new ActivateRuleFlowGroup("asdf") };
scenario.getFixtures().addAll(Arrays.asList(given));
scenario.getFixtures().add(executionTrace);
((InternalAgendaGroup) ksession.getAgenda().getRuleFlowGroup("asdf")).setAutoDeactivate(false);
scenarioRunner = new ScenarioRunner(ksession);
scenarioRunner.run(scenario);
assertTrue(scenario.wasSuccessful());
Thread.currentThread().setContextClassLoader(cl_);
}
use of org.kie.soup.project.datamodel.commons.types.ClassTypeResolver in project drools by kiegroup.
the class FactAssignmentFieldPopulatorTest method testSimpleFields.
@Test
public void testSimpleFields() throws Exception {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
TypeResolver typeResolver = new ClassTypeResolver(new HashSet<String>(), classLoader);
typeResolver.addImport("org.drools.workbench.models.testscenarios.backend.Cheese");
Mouse mouse = new Mouse();
FactAssignmentField factAssignmentField = new FactAssignmentField("cheese", "Cheese");
factAssignmentField.getFact().getFieldData().add(new FieldData("type", "Best cheddar EVER! (tm)"));
FactAssignmentFieldPopulator factAssignmentFieldPopulator = new FactAssignmentFieldPopulator(mouse, factAssignmentField, typeResolver);
factAssignmentFieldPopulator.populate(new HashMap<String, Object>());
assertEquals("Best cheddar EVER! (tm)", mouse.getCheese().getType());
}
use of org.kie.soup.project.datamodel.commons.types.ClassTypeResolver in project drools by kiegroup.
the class FactAssignmentFieldPopulatorTest method testFactAssignmentField.
@Test
public void testFactAssignmentField() throws Exception {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
TypeResolver typeResolver = new ClassTypeResolver(new HashSet<String>(), classLoader);
typeResolver.addImport("org.drools.workbench.models.testscenarios.backend.Cheese");
Mouse mouse = new Mouse();
FactAssignmentField factAssignmentField = new FactAssignmentField("cheese", "Cheese");
FactAssignmentFieldPopulator factAssignmentFieldPopulator = new FactAssignmentFieldPopulator(mouse, factAssignmentField, typeResolver);
factAssignmentFieldPopulator.populate(new HashMap<String, Object>());
assertNotNull(mouse.getCheese());
}
Aggregations