Search in sources :

Example 46 with FactData

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

the class MethodParameterCallValueEditor method boundVariable.

private ListBox boundVariable(final FieldNature c) {
    /*
         * If there is a bound variable that is the same type of the current
         * variable type, then propose a list
         */
    final ListBox listVariable = new ListBox();
    List<String> vars = model.getFactNamesInScope(ex, true);
    for (String v : vars) {
        FactData factData = (FactData) model.getFactTypes().get(v);
        if (factData.getType().equals(this.methodParameter.type)) {
            // First selection is empty
            if (listVariable.getItemCount() == 0) {
                listVariable.addItem("...");
            }
            listVariable.addItem("=" + v);
        }
    }
    if (methodParameter.value.equals("=")) {
        listVariable.setSelectedIndex(0);
    } else {
        for (int i = 0; i < listVariable.getItemCount(); i++) {
            if (listVariable.getItemText(i).equals(methodParameter.value)) {
                listVariable.setSelectedIndex(i);
            }
        }
    }
    if (listVariable.getItemCount() > 0) {
        listVariable.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent event) {
                methodParameter.value = listVariable.getValue(listVariable.getSelectedIndex());
                refresh();
            }
        });
    }
    return listVariable;
}
Also used : ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 47 with FactData

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

Example 48 with FactData

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

the class VerifyFieldConstraintEditor method isThereABoundVariableToSet.

private boolean isThereABoundVariableToSet() {
    boolean retour = false;
    List<String> vars = this.scenario.getFactNamesInScope(executionTrace, true);
    if (vars.size() > 0) {
        for (int i = 0; i < vars.size(); i++) {
            String var = vars.get(i);
            FactData f = scenario.getFactTypes().get(var);
            String fieldType = oracle.getFieldType(this.factType, field.getFieldName());
            if (f.getType().equals(fieldType)) {
                retour = true;
                break;
            }
        }
    }
    return retour;
}
Also used : FactData(org.drools.workbench.models.testscenarios.shared.FactData)

Example 49 with FactData

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

the class ScenarioTestEditorServiceImplTest method loadScenario.

@Test
public void loadScenario() throws Exception {
    final URL scenarioResource = getClass().getResource("Are they old enough.scenario");
    final Path scenarioPath = PathFactory.newPath(scenarioResource.getFile(), scenarioResource.toURI().toString());
    final Scenario loadedScenario = testEditorService.load(scenarioPath);
    assertNotNull(loadedScenario);
    assertEquals("mortgages.mortgages", loadedScenario.getPackageName());
    assertEquals(5, loadedScenario.getFixtures().size());
    assertTrue(loadedScenario.getFixtures().get(0) instanceof FactData);
    assertTrue(loadedScenario.getFixtures().get(1) instanceof FactData);
    assertTrue(loadedScenario.getFixtures().get(2) instanceof FactData);
    assertTrue(loadedScenario.getFixtures().get(3) instanceof ExecutionTrace);
    assertTrue(loadedScenario.getFixtures().get(4) instanceof VerifyFact);
}
Also used : Path(org.uberfire.backend.vfs.Path) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) URL(java.net.URL) 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