use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.
the class ScenarioRunnerTest method testImports.
@Test
public void testImports() throws Exception {
Scenario scenario = new Scenario();
scenario.setPackageName("org.drools.workbench.models.testscenarios.backend");
ScenarioRunner runner = new ScenarioRunner(ksession);
scenario.getFixtures().add(new FactData("Cheese", "f1", Collections.EMPTY_LIST, false));
runner.run(scenario);
assertTrue(scenario.wasSuccessful());
}
use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.
the class ScenarioRunnerTest method testIntegrationInfiniteLoop.
@Test
public void testIntegrationInfiniteLoop() throws Exception {
Scenario sc = new Scenario();
sc.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Cheese"));
sc.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Person"));
FactData[] facts = new FactData[] { new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("type", "cheddar"), new FieldData("price", "42")), false) };
sc.getGlobals().add(new FactData("Person", "p", new ArrayList(), false));
sc.getFixtures().addAll(Arrays.asList(facts));
ExecutionTrace executionTrace = new ExecutionTrace();
sc.getRules().add("rule1");
sc.getRules().add("rule2");
sc.setInclusive(true);
sc.getFixtures().add(executionTrace);
Expectation[] assertions = new Expectation[5];
assertions[0] = new VerifyFact("c1", ls(new VerifyField("type", "cheddar", "==")));
assertions[1] = new VerifyFact("p", ls(new VerifyField("name", "rule1", "=="), new VerifyField("status", "rule2", "==")));
assertions[2] = new VerifyRuleFired("rule1", 1, null);
assertions[3] = new VerifyRuleFired("rule2", 1, null);
assertions[4] = new VerifyRuleFired("rule3", 0, null);
sc.getFixtures().addAll(Arrays.asList(assertions));
KieSession ksession = getKieSession("test_rules_infinite_loop.drl");
ScenarioRunner run = new ScenarioRunner(ksession);
run.run(sc);
assertEquals(sc.getMaxRuleFirings(), executionTrace.getNumberOfRulesFired().intValue());
}
use of org.drools.workbench.models.testscenarios.shared.FactData 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.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.
the class ScenarioRunnerTest method testPopulateFactsWithInterfaces.
@Test
public void testPopulateFactsWithInterfaces() throws Exception {
Scenario sc = new Scenario();
sc.getImports().addImport(new Import("java.util.List"));
List facts = ls(new FactData("List", "ls", new ArrayList(), false));
List globals = ls(new FactData("List", "ls", new ArrayList(), false));
sc.getFixtures().addAll(facts);
sc.getGlobals().addAll(globals);
ScenarioRunner runner = new ScenarioRunner(ksession);
runner.run(sc);
}
use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.
the class ScenarioRunnerTest method populateScenarioForFailure.
private Expectation[] populateScenarioForFailure(Scenario sc) {
FactData[] facts = new FactData[] { new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("type", "cheddar"), new FieldData("price", "42")), false) };
sc.getFixtures().addAll(Arrays.asList(facts));
sc.getGlobals().add(new FactData("Person", "p", new ArrayList(), false));
ExecutionTrace executionTrace = new ExecutionTrace();
sc.getRules().add("rule1");
sc.getRules().add("rule2");
sc.setInclusive(true);
sc.getFixtures().add(executionTrace);
Expectation[] assertions = new Expectation[5];
assertions[0] = new VerifyFact("c1", ls(new VerifyField("type", "cheddar", "==")));
assertions[1] = new VerifyFact("p", ls(new VerifyField("name", "XXX", "=="), new VerifyField("status", "rule2", "==")));
assertions[2] = new VerifyRuleFired("rule1", 1, null);
assertions[3] = new VerifyRuleFired("rule2", 1, null);
assertions[4] = new VerifyRuleFired("rule3", 2, null);
sc.getFixtures().addAll(Arrays.asList(assertions));
return assertions;
}
Aggregations