Search in sources :

Example 21 with VerifyField

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

the class FactVerifierTest method testVerifyFactsWithOperator.

@Test
public void testVerifyFactsWithOperator() throws Exception {
    TypeResolver typeResolver = mock(TypeResolver.class);
    Cheese f1 = new Cheese("cheddar", 42);
    HashMap<String, Object> populatedData = new HashMap<String, Object>();
    populatedData.put("f1", f1);
    // configure the mock to return the value
    Set o = Collections.singleton((Object) f1);
    when(ksession.getObjects()).thenReturn(o);
    FactVerifier factVerifier = new FactVerifier(populatedData, typeResolver, ksession, new HashMap<String, Object>());
    // test all true
    VerifyFact vf = new VerifyFact();
    vf.setName("f1");
    vf.getFieldValues().add(new VerifyField("type", "cheddar", "=="));
    vf.getFieldValues().add(new VerifyField("price", "4777", "!="));
    factVerifier.verify(vf);
    for (int i = 0; i < vf.getFieldValues().size(); i++) {
        assertTrue(vf.getFieldValues().get(i).getSuccessResult());
    }
    vf = new VerifyFact();
    vf.setName("f1");
    vf.getFieldValues().add(new VerifyField("type", "cheddar", "!="));
    factVerifier.verify(vf);
    assertFalse(vf.getFieldValues().get(0).getSuccessResult());
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) Cheese(org.drools.workbench.models.testscenarios.backend.Cheese) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) Test(org.junit.Test)

Example 22 with VerifyField

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

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

the class VerifyFactWidget method render.

private FlexTable render(final VerifyFact vf) {
    FlexTable data = new FlexTable();
    for (int i = 0; i < vf.getFieldValues().size(); i++) {
        final VerifyField fld = (VerifyField) vf.getFieldValues().get(i);
        data.setWidget(i, 1, new SmallLabel(fld.getFieldName() + ":"));
        data.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_RIGHT);
        final ListBox opr = new ListBox();
        opr.addItem(TestScenarioConstants.INSTANCE.equalsScenario(), "==");
        opr.addItem(TestScenarioConstants.INSTANCE.doesNotEqualScenario(), "!=");
        if (fld.getOperator().equals("==")) {
            opr.setSelectedIndex(0);
        } else {
            opr.setSelectedIndex(1);
        }
        opr.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent event) {
                fld.setOperator(opr.getValue(opr.getSelectedIndex()));
            }
        });
        data.setWidget(i, 2, opr);
        Widget cellEditor = new VerifyFieldConstraintEditor(type, new ValueChanged() {

            public void valueChanged(String newValue) {
                fld.setExpected(newValue);
            }
        }, fld, oracle, this.scenario, this.executionTrace);
        data.setWidget(i, 3, cellEditor);
        Button deleteButton = new Button();
        deleteButton.setIcon(IconType.TRASH);
        deleteButton.setTitle(TestScenarioConstants.INSTANCE.RemoveThisFieldExpectation());
        deleteButton.addClickHandler(clickEvent -> {
            if (Window.confirm(TestScenarioConstants.INSTANCE.AreYouSureYouWantToRemoveThisFieldExpectation(fld.getFieldName()))) {
                vf.getFieldValues().remove(fld);
                FlexTable renderedTableAfterDelete = render(vf);
                outer.setWidget(1, 0, renderedTableAfterDelete);
            }
        });
        data.setWidget(i, 4, deleteButton);
        if (showResults && fld.getSuccessResult() != null) {
            if (!fld.getSuccessResult().booleanValue()) {
                data.setWidget(i, 0, new Image(CommonImages.INSTANCE.warning()));
                data.setWidget(i, 5, new HTML(TestScenarioConstants.INSTANCE.ActualResult(fld.getActualResult())));
                data.getCellFormatter().addStyleName(i, 5, // NON-NLS
                "testErrorValue");
            } else {
                data.setWidget(i, 0, new Image(TestScenarioImages.INSTANCE.testPassed()));
            }
        }
    }
    ScenarioUtils.addBottomAndRightPaddingToTableCells(data);
    return data;
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) FlexTable(com.google.gwt.user.client.ui.FlexTable) Widget(com.google.gwt.user.client.ui.Widget) HTML(com.google.gwt.user.client.ui.HTML) Image(com.google.gwt.user.client.ui.Image) ValueChanged(org.uberfire.ext.widgets.common.client.common.ValueChanged) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) Button(org.gwtbootstrap3.client.ui.Button) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Aggregations

VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)23 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)20 Test (org.junit.Test)16 FactData (org.drools.workbench.models.testscenarios.shared.FactData)15 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)13 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)11 Import (org.kie.soup.project.datamodel.imports.Import)10 ExecutionTrace (org.drools.workbench.models.testscenarios.shared.ExecutionTrace)9 ArrayList (java.util.ArrayList)8 VerifyRuleFired (org.drools.workbench.models.testscenarios.shared.VerifyRuleFired)7 KieSession (org.kie.api.runtime.KieSession)7 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)7 Expectation (org.drools.workbench.models.testscenarios.shared.Expectation)6 Field (org.drools.workbench.models.testscenarios.shared.Field)6 HashMap (java.util.HashMap)5 Set (java.util.Set)5 Cheese (org.drools.workbench.models.testscenarios.backend.Cheese)5 HashSet (java.util.HashSet)2 ProjectClassLoader (org.drools.core.common.ProjectClassLoader)2 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)2