Search in sources :

Example 21 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData in project drools-wb by kiegroup.

the class TestScenarioFactory method makeTestScenarioWithoutVerifyFact.

public static Scenario makeTestScenarioWithoutVerifyFact(final String packageName, final Collection<Import> imports, final String name) {
    final Scenario model = new Scenario();
    model.getImports().getImports().addAll(imports);
    model.setPackageName(packageName);
    model.setName(name);
    model.getFixtures().add(new FactData("Applicant", "$a", new ArrayList<Field>() {

        {
            add(new FieldData("age", "33"));
        }
    }, false));
    return model;
}
Also used : FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ArrayList(java.util.ArrayList) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario)

Example 22 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData in project drools-wb by kiegroup.

the class MethodParameterCallValueEditor method showTypeChoice.

protected void showTypeChoice(final Widget w) {
    final FormStylePopup form = new FormStylePopup(TestScenarioAltedImages.INSTANCE.Wizard(), TestScenarioConstants.INSTANCE.FieldValue());
    Button lit = new Button(TestScenarioConstants.INSTANCE.LiteralValue());
    lit.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            methodParameter.nature = FieldData.TYPE_LITERAL;
            methodParameter.value = " ";
            refresh();
            form.hide();
        }
    });
    form.addAttribute(TestScenarioConstants.INSTANCE.LiteralValue() + ":", widgets(lit, new InfoPopup(TestScenarioConstants.INSTANCE.Literal(), TestScenarioConstants.INSTANCE.LiteralValTip())));
    form.addRow(new HTML("<hr/>"));
    form.addRow(new SmallLabel(TestScenarioConstants.INSTANCE.AdvancedSection()));
    /*
         * If there is a bound variable that is the same type of the current
         * variable type, then show a button
         */
    List<String> vars = model.getFactNamesInScope(ex, true);
    for (String v : vars) {
        boolean createButton = false;
        Button variable = new Button(TestScenarioConstants.INSTANCE.BoundVariable());
        FactData factData = (FactData) model.getFactTypes().get(v);
        if (factData.getType().equals(this.parameterType)) {
            createButton = true;
        }
        if (createButton == true) {
            form.addAttribute(TestScenarioConstants.INSTANCE.BoundVariable() + ":", variable);
            variable.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    methodParameter.nature = FieldData.TYPE_VARIABLE;
                    methodParameter.value = "=";
                    refresh();
                    form.hide();
                }
            });
            break;
        }
    }
    form.show();
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Button(org.gwtbootstrap3.client.ui.Button) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FactData(org.drools.workbench.models.testscenarios.shared.FactData) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) HTML(com.google.gwt.user.client.ui.HTML) InfoPopup(org.uberfire.ext.widgets.common.client.common.InfoPopup)

Example 23 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData 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 24 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.

the class FactDataTest method testAdd.

@Test
public void testAdd() {
    FactData fd = new FactData("x", "y", new ArrayList(), false);
    assertEquals(0, fd.getFieldData().size());
    fd.getFieldData().add(new FieldData("x", "y"));
    assertEquals(1, fd.getFieldData().size());
    fd.getFieldData().add(new FieldData("q", "x"));
    assertEquals(2, fd.getFieldData().size());
}
Also used : FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 25 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.

the class ScenarioRunnerTest method testIntegrationWithModify.

@Test
public void testIntegrationWithModify() throws Exception {
    Scenario sc = new Scenario();
    sc.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Cheese"));
    sc.getFixtures().add(new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("price", "1")), false));
    sc.getFixtures().add(new ExecutionTrace());
    sc.getFixtures().add(new VerifyFact("c1", ls(new VerifyField("type", "rule1", "=="))));
    sc.getFixtures().add(new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("price", "42")), true));
    sc.getFixtures().add(new ExecutionTrace());
    sc.getFixtures().add(new VerifyFact("c1", ls(new VerifyField("type", "rule3", "=="))));
    KieSession ksession = getKieSession("test_stateful.drl");
    ScenarioRunner run = new ScenarioRunner(ksession);
    run.run(sc);
    assertTrue(sc.wasSuccessful());
}
Also used : FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) Field(org.drools.workbench.models.testscenarios.shared.Field) Import(org.kie.soup.project.datamodel.imports.Import) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) KieSession(org.kie.api.runtime.KieSession) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

Aggregations

FactData (org.drools.workbench.models.testscenarios.shared.FactData)49 Test (org.junit.Test)36 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)29 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)24 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)19 ArrayList (java.util.ArrayList)17 ExecutionTrace (org.drools.workbench.models.testscenarios.shared.ExecutionTrace)16 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)15 CollectionFieldData (org.drools.workbench.models.testscenarios.shared.CollectionFieldData)13 Field (org.drools.workbench.models.testscenarios.shared.Field)12 Import (org.kie.soup.project.datamodel.imports.Import)11 VerifyRuleFired (org.drools.workbench.models.testscenarios.shared.VerifyRuleFired)9 KieSession (org.kie.api.runtime.KieSession)8 Cheese (org.drools.workbench.models.testscenarios.backend.Cheese)7 Expectation (org.drools.workbench.models.testscenarios.shared.Expectation)7 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)7 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)7 RetractFact (org.drools.workbench.models.testscenarios.shared.RetractFact)6 Fixture (org.drools.workbench.models.testscenarios.shared.Fixture)5 HashMap (java.util.HashMap)3