use of org.drools.workbench.models.testscenarios.shared.FieldData in project drools by kiegroup.
the class FactPopulatorTest method testPopulateEmptyString.
@Test
public void testPopulateEmptyString() throws Exception {
Cheese cheese = new Cheese();
cheese.setType("whee");
cheese.setPrice(1);
populatedData.put("x", cheese);
assertEquals(1, cheese.getPrice());
// An empty String is a 'value' as opposed to null
factPopulator.add(new ExistingFactPopulator(populatedData, getTypeResolver(), new FactData("Cheese", "x", Arrays.<Field>asList(new FieldData("type", ""), new FieldData("price", "42")), false)));
factPopulator.populate();
assertEquals("", cheese.getType());
assertEquals(42, cheese.getPrice());
}
use of org.drools.workbench.models.testscenarios.shared.FieldData 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.FieldData in project drools by kiegroup.
the class FactPopulatorTest method testSQLDateField.
@Test
public void testSQLDateField() throws Exception {
factPopulator.add(new NewFactPopulator(populatedData, getTypeResolver(), new FactData("SqlDateWrapper", "c1", Arrays.<Field>asList(new FieldData("sqlDate", "10-Jul-2008")), false)));
factPopulator.populate();
assertTrue(populatedData.containsKey("c1"));
SqlDateWrapper sqlDateWrapper = (SqlDateWrapper) populatedData.get("c1");
assertNotNull(sqlDateWrapper.getSqlDate());
}
use of org.drools.workbench.models.testscenarios.shared.FieldData 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.FieldData in project drools by kiegroup.
the class FactPopulatorTest method testPopulateFacts.
@Test
public void testPopulateFacts() throws Exception {
FactData factData = new FactData("Person", "p1", Arrays.<Field>asList(new FieldData("name", "mic"), new FieldData("age", "=30 + 3")), false);
factPopulator.add(new NewFactPopulator(populatedData, getTypeResolver(), factData));
factPopulator.populate();
assertTrue(populatedData.containsKey("p1"));
Person person = (Person) populatedData.get("p1");
assertEquals("mic", person.getName());
assertEquals(33, person.getAge());
}
Aggregations