Search in sources :

Example 31 with FieldData

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

the class FactPopulatorTest method testDateField.

@Test
public void testDateField() throws Exception {
    factPopulator.add(new NewFactPopulator(populatedData, getTypeResolver(), new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("type", "cheddar"), new FieldData("usedBy", "10-Jul-2008")), false)));
    factPopulator.add(new NewFactPopulator(populatedData, getTypeResolver(), new FactData("OuterFact", "p1", Arrays.<Field>asList(new FieldData("name", "mic"), new FieldData("innerFact", "=c1")), false)));
    factPopulator.populate();
    assertTrue(populatedData.containsKey("c1"));
    assertTrue(populatedData.containsKey("p1"));
    Cheese c = (Cheese) populatedData.get("c1");
    assertNotNull(c.getUsedBy());
}
Also used : CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactData(org.drools.workbench.models.testscenarios.shared.FactData) Cheese(org.drools.workbench.models.testscenarios.backend.Cheese) Test(org.junit.Test)

Example 32 with FieldData

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

the class NewFactPopulatorTest method testDummyRunNoRules.

@Test
public void testDummyRunNoRules() throws Exception {
    typeResolver.addImport("org.drools.workbench.models.testscenarios.backend.Cheese");
    List<Field> fieldData = new ArrayList<Field>();
    fieldData.add(new FieldData("type", "cheddar"));
    fieldData.add(new FieldData("price", "42"));
    FactData fact = new FactData("Cheese", "c1", fieldData, false);
    NewFactPopulator newFactPopulator = new NewFactPopulator(populatedData, typeResolver, fact);
    newFactPopulator.populate(workingMemory, new HashMap<String, FactHandle>());
    assertTrue(populatedData.containsKey("c1"));
    assertNotNull(populatedData.get("c1"));
    verify(workingMemory).insert(populatedData.get("c1"));
}
Also used : FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) Field(org.drools.workbench.models.testscenarios.shared.Field) FactHandle(org.kie.api.runtime.rule.FactHandle) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 33 with FieldData

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

the class FactDataWidgetFactory method build.

public void build(final String headerText, final Fact fact) {
    if (fact instanceof FactData) {
        FactData factData = (FactData) fact;
        widget.setWidget(0, ++col, new SmallLabel("[" + factData.getName() + "]"));
    } else {
        col++;
    }
    widget.setWidget(0, 0, new ClickableLabel(headerText, createAddFieldButton(fact)));
    Map<FieldData, FieldDataConstraintEditor> enumEditorMap = new HashMap<FieldData, FieldDataConstraintEditor>();
    // Sets row name and delete button.
    for (final Field field : fact.getFieldData()) {
        // Avoid duplicate field rows, only one for each name.
        if (rowIndexByFieldName.doesNotContain(field.getName())) {
            newRow(fact, field.getName());
        }
        // Sets row data
        int fieldRowIndex = rowIndexByFieldName.getRowIndex(field.getName());
        IsWidget editableCell = editableCell(field, fact, fact.getType());
        widget.setWidget(fieldRowIndex, col, editableCell);
        if (field instanceof FieldData) {
            FieldData fieldData = (FieldData) field;
            if (fieldData.getNature() == FieldData.TYPE_ENUM) {
                enumEditorMap.put(fieldData, (FieldDataConstraintEditor) editableCell);
            }
        }
    }
    for (FieldDataConstraintEditor outerEnumEditor : enumEditorMap.values()) {
        for (FieldDataConstraintEditor innerEnumEditor : enumEditorMap.values()) {
            if (outerEnumEditor != innerEnumEditor) {
                outerEnumEditor.addIfDependentEnumEditor(innerEnumEditor);
            }
        }
    }
    if (fact instanceof FactData) {
        DeleteFactColumnButton deleteFactColumnButton = new DeleteFactColumnButton((FactData) fact);
        widget.setWidget(rowIndexByFieldName.amountOrRows() + 1, col, deleteFactColumnButton);
    }
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) IsWidget(com.google.gwt.user.client.ui.IsWidget) FactAssignmentField(org.drools.workbench.models.testscenarios.shared.FactAssignmentField) Field(org.drools.workbench.models.testscenarios.shared.Field) HashMap(java.util.HashMap) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel)

Example 34 with FieldData

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

the class FieldConstraintHelper method getEnums.

DropDownData getEnums() {
    Map<String, String> currentValueMap = new HashMap<String, String>();
    for (Field f : fact.getFieldData()) {
        if (f instanceof FieldData) {
            FieldData otherFieldData = (FieldData) f;
            currentValueMap.put(otherFieldData.getName(), otherFieldData.getValue());
        }
    }
    return oracle.getEnums(factType, field.getName(), currentValueMap);
}
Also used : CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) Field(org.drools.workbench.models.testscenarios.shared.Field) HashMap(java.util.HashMap)

Example 35 with FieldData

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

the class FieldSelectorWidget method createField.

private Field createField(final SelectionEvent<Integer> selectionEvent) {
    if (selectionEvent.getSelectedItem() == FieldData.TYPE_FACT) {
        return new FactAssignmentField(field.getName(), helper.getFieldType());
    } else {
        if (selectionEvent.getSelectedItem() == FieldData.TYPE_COLLECTION) {
            CollectionFieldData collectionFieldData = new CollectionFieldData();
            collectionFieldData.setName(field.getName());
            return collectionFieldData;
        } else {
            FieldData fieldData = new FieldData(field.getName(), "");
            fieldData.setNature(selectionEvent.getSelectedItem());
            return fieldData;
        }
    }
}
Also used : CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactAssignmentField(org.drools.workbench.models.testscenarios.shared.FactAssignmentField) CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData)

Aggregations

FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)37 FactData (org.drools.workbench.models.testscenarios.shared.FactData)29 Test (org.junit.Test)26 CollectionFieldData (org.drools.workbench.models.testscenarios.shared.CollectionFieldData)20 Field (org.drools.workbench.models.testscenarios.shared.Field)13 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)12 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)11 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)11 ArrayList (java.util.ArrayList)10 Import (org.kie.soup.project.datamodel.imports.Import)9 ExecutionTrace (org.drools.workbench.models.testscenarios.shared.ExecutionTrace)8 KieSession (org.kie.api.runtime.KieSession)8 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)8 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)8 Cheese (org.drools.workbench.models.testscenarios.backend.Cheese)7 Expectation (org.drools.workbench.models.testscenarios.shared.Expectation)5 VerifyRuleFired (org.drools.workbench.models.testscenarios.shared.VerifyRuleFired)5 HashMap (java.util.HashMap)4 UiHandler (com.google.gwt.uibinder.client.UiHandler)3 FactAssignmentField (org.drools.workbench.models.testscenarios.shared.FactAssignmentField)3