Search in sources :

Example 41 with FactData

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

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

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

the class TestScenarioFactory method makeTestScenarioWithGlobalVerifyGlobal.

public static Scenario makeTestScenarioWithGlobalVerifyGlobal(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.getGlobals().add(new FactData("Date", "day", new ArrayList<Field>(), false));
    model.getFixtures().add(new VerifyFact("day", new ArrayList<VerifyField>() {

        {
            add(new VerifyField("minutes", "45", "=="));
        }
    }, false));
    return model;
}
Also used : VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ArrayList(java.util.ArrayList) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario)

Example 44 with FactData

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

the class DataInputWidget method renderEditor.

public void renderEditor() {
    clear();
    if (definitionList.size() == 0) {
        parent.renderEditor();
    }
    // This will work out what row is for what field, adding labels and remove icons
    FactDataWidgetFactory factDataWidgetFactory = new FactDataWidgetFactory(scenario, oracle, definitionList, executionTrace, this, this);
    for (Fixture fixture : definitionList) {
        if (fixture instanceof FactData) {
            factDataWidgetFactory.build(headerText, (FactData) fixture);
        }
    }
    getFlexCellFormatter().setHorizontalAlignment(factDataWidgetFactory.amountOrRows() + 1, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    if (factDataWidgetFactory.amountOrRows() == 0) {
        setWidget(1, 1, new ClickableLabel(TestScenarioConstants.INSTANCE.AddAField(), new AddFieldToFactDataClickHandler(definitionList, oracle, parent)));
    }
    ScenarioUtils.addBottomAndRightPaddingToTableCells(this);
}
Also used : FactData(org.drools.workbench.models.testscenarios.shared.FactData) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture)

Example 45 with FactData

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

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