Search in sources :

Example 16 with FactData

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

the class FactPopulatorTest method testPopulateFactsWithExpressions.

@Test
public void testPopulateFactsWithExpressions() throws Exception {
    factPopulator.add(new NewFactPopulator(populatedData, getTypeResolver(), new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("type", "cheddar"), new FieldData("price", "42")), false)));
    factPopulator.add(new NewFactPopulator(populatedData, getTypeResolver(), new FactData("Cheese", "c2", Arrays.<Field>asList(new FieldData("type", "= c1.type")), false)));
    factPopulator.populate();
    assertTrue(populatedData.containsKey("c1"));
    assertTrue(populatedData.containsKey("c2"));
    Cheese c = (Cheese) populatedData.get("c1");
    assertEquals("cheddar", c.getType());
    assertEquals(42, c.getPrice());
    Cheese c2 = (Cheese) populatedData.get("c2");
    assertEquals(c.getType(), c2.getType());
}
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 17 with FactData

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

the class GlobalFactPopulatorTest method testWithGlobals.

@Test
public void testWithGlobals() throws Exception {
    FactData global = new FactData("Cheese", "c", Arrays.<Field>asList(new FieldData("type", "cheddar")), false);
    TypeResolver resolver = new ClassTypeResolver(new HashSet<String>(), Thread.currentThread().getContextClassLoader());
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.Cheese");
    KieSession ksession = mock(KieSession.class);
    Map<String, Object> populatedData = new HashMap<String, Object>();
    Map<String, Object> globalData = new HashMap<String, Object>();
    GlobalFactPopulator globalFactPopulator = new GlobalFactPopulator(populatedData, resolver, global, globalData);
    globalFactPopulator.populate(ksession, new HashMap<String, FactHandle>());
    verify(ksession).setGlobal(eq(global.getName()), any(Object.class));
    assertEquals(1, globalData.size());
    assertEquals(0, populatedData.size());
}
Also used : HashMap(java.util.HashMap) FactHandle(org.kie.api.runtime.rule.FactHandle) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactData(org.drools.workbench.models.testscenarios.shared.FactData) KieSession(org.kie.api.runtime.KieSession) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) Test(org.junit.Test)

Example 18 with FactData

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

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

the class VerifyFieldConstraintEditor method variableEditor.

private Widget variableEditor() {
    List<String> vars = this.scenario.getFactNamesInScope(this.executionTrace, true);
    final ListBox box = new ListBox();
    if (this.field.getExpected() == null) {
        box.addItem(CommonConstants.INSTANCE.Choose());
    }
    int j = 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)) {
            if (box.getItemCount() == 0) {
                box.addItem("...");
                j++;
            }
            box.addItem("=" + var);
            if (this.field.getExpected() != null && this.field.getExpected().equals("=" + var)) {
                box.setSelectedIndex(j);
            }
            j++;
        }
    }
    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            field.setExpected(box.getItemText(box.getSelectedIndex()));
        }
    });
    return box;
}
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 20 with FactData

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

the class TestScenarioFactory method makeTestScenarioWithVerifyFact.

public static Scenario makeTestScenarioWithVerifyFact(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.getFixtures().add(new FactData("Applicant", "$a", new ArrayList<Field>() {

        {
            add(new FieldData("age", "33"));
        }
    }, false));
    model.getFixtures().add(new VerifyFact("Mortgage", new ArrayList<VerifyField>() {

        {
            add(new VerifyField("amount", "10000", "=="));
        }
    }, true));
    return model;
}
Also used : FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) 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)

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