use of org.drools.workbench.models.testscenarios.shared.ActivateRuleFlowGroup 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.ActivateRuleFlowGroup in project drools-wb by kiegroup.
the class ActivateRuleFlowWidget method render.
private void render(final FixtureList retList, final FlexTable outer, final Scenario sc) {
outer.clear();
outer.getCellFormatter().setStyleName(0, 0, "modeller-fact-TypeHeader");
outer.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
outer.setStyleName("modeller-fact-pattern-Widget");
outer.setWidget(0, 0, new SmallLabel(TestScenarioConstants.INSTANCE.ActivateRuleFlowGroup()));
outer.getFlexCellFormatter().setColSpan(0, 0, 2);
int row = 1;
for (Fixture fixture : retList) {
final ActivateRuleFlowGroup acticateRuleFlowGroup = (ActivateRuleFlowGroup) fixture;
outer.setWidget(row, 0, new SmallLabel(acticateRuleFlowGroup.getName()));
Button deleteButton = new Button();
deleteButton.setIcon(IconType.TRASH);
deleteButton.setTitle(TestScenarioConstants.INSTANCE.RemoveThisRuleFlowActivation());
deleteButton.addClickHandler(clickEvent -> {
retList.remove(acticateRuleFlowGroup);
sc.getFixtures().remove(acticateRuleFlowGroup);
render(retList, outer, sc);
parent.renderEditor();
});
outer.setWidget(row, 1, deleteButton);
row++;
}
ScenarioUtils.addBottomAndRightPaddingToTableCells(outer);
}
use of org.drools.workbench.models.testscenarios.shared.ActivateRuleFlowGroup in project drools by kiegroup.
the class ScenarioRunner method applyFixtures.
private void applyFixtures(final List<Fixture> fixtures, final ScenarioSettings scenarioSettings) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InvalidClockTypeException {
for (Iterator<Fixture> iterator = fixtures.iterator(); iterator.hasNext(); ) {
Fixture fixture = iterator.next();
if (fixture instanceof FactData) {
factPopulator.add(factPopulatorFactory.createFactPopulator((FactData) fixture));
} else if (fixture instanceof RetractFact) {
factPopulator.retractFact(((RetractFact) fixture).getName());
} else if (fixture instanceof CallMethod) {
workingMemoryWrapper.executeMethod((CallMethod) fixture);
} else if (fixture instanceof ActivateRuleFlowGroup) {
workingMemoryWrapper.activateRuleFlowGroup(((ActivateRuleFlowGroup) fixture).getName());
} else if (fixture instanceof ExecutionTrace) {
factPopulator.populate();
workingMemoryWrapper.executeSubScenario((ExecutionTrace) fixture, scenarioSettings);
} else if (fixture instanceof Expectation) {
factPopulator.populate();
workingMemoryWrapper.verifyExpectation((Expectation) fixture);
} else {
throw new IllegalArgumentException("Not sure what to do with " + fixture);
}
}
factPopulator.populate();
}
use of org.drools.workbench.models.testscenarios.shared.ActivateRuleFlowGroup in project drools-wb by kiegroup.
the class ScenarioHelper method lumpyMap.
/**
* Called lumpy map - as this takes a flat list of fixtures, and groups
* things together. It will return a list - of which each element will
* either be a list - or a map. If its a map - then its a map of FactData to
* the fact type. If its a list, then it will be expectations or
* retractions.
* <p/>
* Man, this will be so much nicer with generics.
* @return List<List<VeryifyRuleFired or VerifyFact or RetractFact> OR
* Map<String, List<FactData>> OR ExecutionTrace>
*/
public List<Fixture> lumpyMap(final List<Fixture> fixtures) {
List<Fixture> output = new ArrayList<Fixture>();
FixturesMap dataInput = new FixturesMap();
CallFixtureMap callOnDataInput = new CallFixtureMap();
FixtureList verifyFact = new FixtureList();
FixtureList verifyRule = new FixtureList();
FixtureList retractFacts = new FixtureList();
for (Fixture fixture : fixtures) {
if (fixture instanceof FactData) {
accumulateDataForFactData(dataInput, (FactData) fixture);
} else if (fixture instanceof CallMethod) {
accumulateCallMethod(callOnDataInput, (CallMethod) fixture);
} else if (fixture instanceof ActivateRuleFlowGroup) {
accumulateDataForActivateRuleFlowGroup(dataInput, fixture);
} else if (fixture instanceof RetractFact) {
retractFacts.add(fixture);
} else if (fixture instanceof VerifyRuleFired) {
verifyRule.add(fixture);
} else if (fixture instanceof VerifyFact) {
verifyFact.add(fixture);
} else if (fixture instanceof ExecutionTrace) {
gatherFixtures(output, dataInput, callOnDataInput, verifyFact, verifyRule, retractFacts, false);
output.add(fixture);
verifyRule = new FixtureList();
verifyFact = new FixtureList();
retractFacts = new FixtureList();
callOnDataInput = new CallFixtureMap();
dataInput = new FixturesMap();
}
}
gatherFixtures(output, dataInput, callOnDataInput, verifyFact, verifyRule, retractFacts, true);
return output;
}
Aggregations