Search in sources :

Example 1 with ActivateRuleFlowGroup

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_);
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) ActivateRuleFlowGroup(org.drools.workbench.models.testscenarios.shared.ActivateRuleFlowGroup) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) Field(org.drools.workbench.models.testscenarios.shared.Field) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ProjectClassLoader(org.drools.core.common.ProjectClassLoader) KieSession(org.kie.api.runtime.KieSession) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) HashSet(java.util.HashSet) InternalAgendaGroup(org.drools.core.common.InternalAgendaGroup) VerifyRuleFired(org.drools.workbench.models.testscenarios.shared.VerifyRuleFired) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) Expectation(org.drools.workbench.models.testscenarios.shared.Expectation) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) Test(org.junit.Test)

Example 2 with ActivateRuleFlowGroup

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);
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) Button(org.gwtbootstrap3.client.ui.Button) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) ActivateRuleFlowGroup(org.drools.workbench.models.testscenarios.shared.ActivateRuleFlowGroup)

Example 3 with ActivateRuleFlowGroup

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();
}
Also used : FactData(org.drools.workbench.models.testscenarios.shared.FactData) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) ActivateRuleFlowGroup(org.drools.workbench.models.testscenarios.shared.ActivateRuleFlowGroup) Expectation(org.drools.workbench.models.testscenarios.shared.Expectation) RetractFact(org.drools.workbench.models.testscenarios.shared.RetractFact) CallMethod(org.drools.workbench.models.testscenarios.shared.CallMethod)

Example 4 with ActivateRuleFlowGroup

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;
}
Also used : VerifyRuleFired(org.drools.workbench.models.testscenarios.shared.VerifyRuleFired) ArrayList(java.util.ArrayList) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) ActivateRuleFlowGroup(org.drools.workbench.models.testscenarios.shared.ActivateRuleFlowGroup) CallMethod(org.drools.workbench.models.testscenarios.shared.CallMethod) CallFixtureMap(org.drools.workbench.models.testscenarios.shared.CallFixtureMap) FactData(org.drools.workbench.models.testscenarios.shared.FactData) FixturesMap(org.drools.workbench.models.testscenarios.shared.FixturesMap) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) FixtureList(org.drools.workbench.models.testscenarios.shared.FixtureList) RetractFact(org.drools.workbench.models.testscenarios.shared.RetractFact)

Aggregations

ActivateRuleFlowGroup (org.drools.workbench.models.testscenarios.shared.ActivateRuleFlowGroup)4 Fixture (org.drools.workbench.models.testscenarios.shared.Fixture)4 ExecutionTrace (org.drools.workbench.models.testscenarios.shared.ExecutionTrace)3 FactData (org.drools.workbench.models.testscenarios.shared.FactData)3 CallMethod (org.drools.workbench.models.testscenarios.shared.CallMethod)2 Expectation (org.drools.workbench.models.testscenarios.shared.Expectation)2 RetractFact (org.drools.workbench.models.testscenarios.shared.RetractFact)2 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)2 VerifyRuleFired (org.drools.workbench.models.testscenarios.shared.VerifyRuleFired)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 InternalAgendaGroup (org.drools.core.common.InternalAgendaGroup)1 ProjectClassLoader (org.drools.core.common.ProjectClassLoader)1 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)1 CallFixtureMap (org.drools.workbench.models.testscenarios.shared.CallFixtureMap)1 Field (org.drools.workbench.models.testscenarios.shared.Field)1 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)1 FixtureList (org.drools.workbench.models.testscenarios.shared.FixtureList)1 FixturesMap (org.drools.workbench.models.testscenarios.shared.FixturesMap)1 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)1