use of org.drools.workbench.models.testscenarios.shared.Field 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.Field in project drools by kiegroup.
the class FactPopulatorTest method testCollectionFieldInFacts.
@Test
public void testCollectionFieldInFacts() throws Exception {
TypeResolver typeResolver = getTypeResolver();
FactData fd1 = new FactData("Cheese", "f1", Arrays.<Field>asList(new FieldData("type", ""), new FieldData("price", "42")), false);
factPopulator.add(new NewFactPopulator(populatedData, typeResolver, fd1));
FactData fd2 = new FactData("Cheese", "f2", Arrays.<Field>asList(new FieldData("type", ""), new FieldData("price", "43")), false);
factPopulator.add(new NewFactPopulator(populatedData, typeResolver, fd2));
FactData fd3 = new FactData("Cheese", "f3", Arrays.<Field>asList(new FieldData("type", ""), new FieldData("price", "45")), false);
factPopulator.add(new NewFactPopulator(populatedData, typeResolver, fd3));
FieldData field = new FieldData();
field.setName("cheeses");
field.setNature(FieldData.TYPE_COLLECTION);
field.setValue("=[f1,f2,f3]");
List<Field> lstField = new ArrayList<Field>();
lstField.add(field);
FactData lst = new FactData("Cheesery", "listChesse", lstField, false);
factPopulator.add(new NewFactPopulator(populatedData, typeResolver, lst));
factPopulator.populate();
Cheesery listChesse = (Cheesery) populatedData.get("listChesse");
Cheese f1 = (Cheese) populatedData.get("f1");
Cheese f2 = (Cheese) populatedData.get("f2");
Cheese f3 = (Cheese) populatedData.get("f3");
assertEquals(3, listChesse.getCheeses().size());
assertTrue(listChesse.getCheeses().contains(f1));
assertTrue(listChesse.getCheeses().contains(f2));
assertTrue(listChesse.getCheeses().contains(f3));
}
use of org.drools.workbench.models.testscenarios.shared.Field 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"));
}
use of org.drools.workbench.models.testscenarios.shared.Field 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);
}
}
use of org.drools.workbench.models.testscenarios.shared.Field in project drools-wb by kiegroup.
the class FieldConstraintHelper method getEnums.
DropDownData getEnums() {
Map<String, String> currentValueMap = new HashMap<String, String>();
for (Field f : fact.getFieldData()) {
if (f instanceof FieldData) {
FieldData otherFieldData = (FieldData) f;
currentValueMap.put(otherFieldData.getName(), otherFieldData.getValue());
}
}
return oracle.getEnums(factType, field.getName(), currentValueMap);
}
Aggregations