Search in sources :

Example 1 with CollectionFieldData

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

the class CollectionFieldPopulator method createExpression.

private String createExpression(CollectionFieldData field) {
    String result = "[";
    int index = 1;
    for (FieldData fieldData : field.getCollectionFieldList()) {
        result += fieldData.getValue().replace("=", "");
        if (index < field.getCollectionFieldList().size()) {
            result += ",";
        }
        index++;
    }
    return result + "]";
}
Also used : CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData)

Example 2 with CollectionFieldData

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

the class FieldConstraintHelper method replaceFieldWith.

public void replaceFieldWith(final Field newField) {
    for (Field factsField : fact.getFieldData()) {
        if (factsField instanceof CollectionFieldData) {
            CollectionFieldData fData = (CollectionFieldData) factsField;
            List<FieldData> list = fData.getCollectionFieldList();
            boolean aNewItem = true;
            for (FieldData aField : list) {
                if (aField.getNature() == 0) {
                    aNewItem = false;
                    aField.setNature(((FieldData) newField).getNature());
                }
            }
            if (aNewItem && list.contains(field)) {
                list.set(list.indexOf(field), (FieldData) newField);
            }
        }
    }
    if (fact.getFieldData().contains(field)) {
        fact.getFieldData().set(fact.getFieldData().indexOf(field), newField);
        field = newField;
    }
}
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) CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData)

Example 3 with CollectionFieldData

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

the class FactPopulatorTest method testCollectionSums.

@Test
public void testCollectionSums() throws Exception {
    TypeResolver typeResolver = getTypeResolver();
    List<Field> fieldData = new ArrayList<Field>();
    CollectionFieldData collectionFieldData = new CollectionFieldData();
    collectionFieldData.setName("list");
    fieldData.add(collectionFieldData);
    collectionFieldData.getCollectionFieldList().add(new FieldData("list", "=1+3"));
    FactData wrapperFactData = new FactData("MyCollectionWrapper", "wrapper", fieldData, false);
    factPopulator.add(new NewFactPopulator(populatedData, typeResolver, wrapperFactData));
    factPopulator.populate();
    assertTrue(populatedData.containsKey("wrapper"));
    MyCollectionWrapper wrapper = (MyCollectionWrapper) populatedData.get("wrapper");
    assertNotNull(wrapper);
    assertEquals(1, wrapper.getList().size());
    assertNotNull(wrapper.getList().get(0));
    assertEquals(4, wrapper.getList().get(0));
}
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) MyCollectionWrapper(org.drools.workbench.models.testscenarios.backend.MyCollectionWrapper) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ArrayList(java.util.ArrayList) CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) Test(org.junit.Test)

Example 4 with CollectionFieldData

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

the class FactPopulatorTest method testCollection.

@Test
public void testCollection() throws Exception {
    TypeResolver typeResolver = getTypeResolver();
    List<Field> fieldData = new ArrayList<Field>();
    CollectionFieldData collectionFieldData = new CollectionFieldData();
    collectionFieldData.setName("cheeses");
    fieldData.add(collectionFieldData);
    collectionFieldData.getCollectionFieldList().add(new FieldData("cheeses", "=cheese1"));
    collectionFieldData.getCollectionFieldList().add(new FieldData("cheeses", "=cheese2"));
    FactData cheeseryFactData = new FactData("Cheesery", "cheesery", fieldData, false);
    FactData cheeseFactData1 = new FactData("Cheese", "cheese1", Collections.<Field>emptyList(), false);
    FactData cheeseFactData2 = new FactData("Cheese", "cheese2", Collections.<Field>emptyList(), false);
    factPopulator.add(new NewFactPopulator(populatedData, typeResolver, cheeseryFactData));
    factPopulator.add(new NewFactPopulator(populatedData, typeResolver, cheeseFactData1));
    factPopulator.add(new NewFactPopulator(populatedData, typeResolver, cheeseFactData2));
    factPopulator.populate();
    assertTrue(populatedData.containsKey("cheesery"));
    Cheesery cheesery = (Cheesery) populatedData.get("cheesery");
    assertNotNull(cheesery);
    assertEquals(2, cheesery.getCheeses().size());
    assertNotNull(cheesery.getCheeses().get(0));
    assertTrue(cheesery.getCheeses().get(0) instanceof Cheese);
    assertNotNull(cheesery.getCheeses().get(1));
    assertTrue(cheesery.getCheeses().get(1) instanceof Cheese);
}
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) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ArrayList(java.util.ArrayList) Cheese(org.drools.workbench.models.testscenarios.backend.Cheese) Cheesery(org.drools.workbench.models.testscenarios.backend.Cheesery) CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) Test(org.junit.Test)

Example 5 with CollectionFieldData

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

CollectionFieldData (org.drools.workbench.models.testscenarios.shared.CollectionFieldData)5 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)5 Field (org.drools.workbench.models.testscenarios.shared.Field)3 ArrayList (java.util.ArrayList)2 FactData (org.drools.workbench.models.testscenarios.shared.FactData)2 Test (org.junit.Test)2 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)2 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)2 Cheese (org.drools.workbench.models.testscenarios.backend.Cheese)1 Cheesery (org.drools.workbench.models.testscenarios.backend.Cheesery)1 MyCollectionWrapper (org.drools.workbench.models.testscenarios.backend.MyCollectionWrapper)1 FactAssignmentField (org.drools.workbench.models.testscenarios.shared.FactAssignmentField)1