Search in sources :

Example 1 with FixtureList

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

the class TestScenarioIndexVisitor method visit.

private void visit(final Fixture fixture) {
    if (fixture instanceof FixtureList) {
        for (Fixture child : ((FixtureList) fixture)) {
            visit(child);
        }
    } else if (fixture instanceof FixturesMap) {
        for (Fixture child : ((FixturesMap) fixture).values()) {
            visit(child);
        }
    } else if (fixture instanceof FactData) {
        final FactData factData = (FactData) fixture;
        final String typeName = factData.getType();
        final String fullyQualifiedClassName = getFullyQualifiedClassName(typeName);
        ResourceReference resRef = addResourceReference(fullyQualifiedClassName, ResourceType.JAVA);
        factDataToFullyQualifiedClassNameMap.put(factData.getName(), fullyQualifiedClassName);
        for (Field field : factData.getFieldData()) {
            final String fieldName = field.getName();
            final String fieldFullyQualifiedClassName = getFieldFullyQualifiedClassName(fullyQualifiedClassName, fieldName);
            resRef.addPartReference(fieldName, PartType.FIELD);
            addResourceReference(fieldFullyQualifiedClassName, ResourceType.JAVA);
        }
    } else if (fixture instanceof VerifyFact) {
        final VerifyFact verifyFact = (VerifyFact) fixture;
        final String typeName = verifyFact.getName();
        // If VerifyFact is not anonymous lookup FQCN from previous FactData elements
        String fullyQualifiedClassName = null;
        if (!verifyFact.anonymous) {
            fullyQualifiedClassName = factDataToFullyQualifiedClassNameMap.get(verifyFact.getName());
        } else {
            fullyQualifiedClassName = getFullyQualifiedClassName(typeName);
        }
        ResourceReference resRef = null;
        if (fullyQualifiedClassName != null) {
            resRef = addResourceReference(fullyQualifiedClassName, ResourceType.JAVA);
            for (VerifyField field : verifyFact.getFieldValues()) {
                final String fieldName = field.getFieldName();
                final String fieldFullyQualifiedClassName = getFieldFullyQualifiedClassName(fullyQualifiedClassName, fieldName);
                resRef.addPartReference(fieldName, PartType.FIELD);
                addResourceReference(fieldFullyQualifiedClassName, ResourceType.JAVA);
            }
        }
    } else if (fixture instanceof VerifyRuleFired) {
        final VerifyRuleFired verifyRuleFired = (VerifyRuleFired) fixture;
        addResourceReference(verifyRuleFired.getRuleName(), ResourceType.RULE);
    }
}
Also used : Field(org.drools.workbench.models.testscenarios.shared.Field) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) VerifyRuleFired(org.drools.workbench.models.testscenarios.shared.VerifyRuleFired) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) FactData(org.drools.workbench.models.testscenarios.shared.FactData) FixturesMap(org.drools.workbench.models.testscenarios.shared.FixturesMap) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) ResourceReference(org.kie.workbench.common.services.refactoring.ResourceReference) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) FixtureList(org.drools.workbench.models.testscenarios.shared.FixtureList)

Example 2 with FixtureList

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

FactData (org.drools.workbench.models.testscenarios.shared.FactData)2 Fixture (org.drools.workbench.models.testscenarios.shared.Fixture)2 FixtureList (org.drools.workbench.models.testscenarios.shared.FixtureList)2 FixturesMap (org.drools.workbench.models.testscenarios.shared.FixturesMap)2 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)2 VerifyRuleFired (org.drools.workbench.models.testscenarios.shared.VerifyRuleFired)2 ArrayList (java.util.ArrayList)1 ActivateRuleFlowGroup (org.drools.workbench.models.testscenarios.shared.ActivateRuleFlowGroup)1 CallFixtureMap (org.drools.workbench.models.testscenarios.shared.CallFixtureMap)1 CallMethod (org.drools.workbench.models.testscenarios.shared.CallMethod)1 ExecutionTrace (org.drools.workbench.models.testscenarios.shared.ExecutionTrace)1 Field (org.drools.workbench.models.testscenarios.shared.Field)1 RetractFact (org.drools.workbench.models.testscenarios.shared.RetractFact)1 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)1 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)1 ResourceReference (org.kie.workbench.common.services.refactoring.ResourceReference)1