use of org.drools.workbench.models.testscenarios.backend.Cheesery 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));
}
Aggregations