Search in sources :

Example 6 with Cheesery

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));
}
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) Test(org.junit.Test)

Aggregations

Cheesery (org.drools.workbench.models.testscenarios.backend.Cheesery)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 CallMethod (org.drools.workbench.models.testscenarios.shared.CallMethod)4 CallFieldValue (org.drools.workbench.models.testscenarios.shared.CallFieldValue)3 ArrayList (java.util.ArrayList)2 Cheese (org.drools.workbench.models.testscenarios.backend.Cheese)2 CollectionFieldData (org.drools.workbench.models.testscenarios.shared.CollectionFieldData)2 FactData (org.drools.workbench.models.testscenarios.shared.FactData)2 Field (org.drools.workbench.models.testscenarios.shared.Field)2 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)2 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)2 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)2