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 + "]";
}
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;
}
}
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));
}
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);
}
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;
}
}
}
Aggregations