Search in sources :

Example 36 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData 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());
}
Also used : CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactData(org.drools.workbench.models.testscenarios.shared.FactData) Cheese(org.drools.workbench.models.testscenarios.backend.Cheese) Test(org.junit.Test)

Example 37 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData 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);
}
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) CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) Test(org.junit.Test)

Example 38 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData 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());
}
Also used : CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactData(org.drools.workbench.models.testscenarios.shared.FactData) SqlDateWrapper(org.drools.workbench.models.testscenarios.backend.SqlDateWrapper) Test(org.junit.Test)

Example 39 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData 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)

Example 40 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData 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());
}
Also used : CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactData(org.drools.workbench.models.testscenarios.shared.FactData) Person(org.drools.workbench.models.testscenarios.backend.Person) Test(org.junit.Test)

Aggregations

FactData (org.drools.workbench.models.testscenarios.shared.FactData)49 Test (org.junit.Test)36 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)29 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)24 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)19 ArrayList (java.util.ArrayList)17 ExecutionTrace (org.drools.workbench.models.testscenarios.shared.ExecutionTrace)16 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)15 CollectionFieldData (org.drools.workbench.models.testscenarios.shared.CollectionFieldData)13 Field (org.drools.workbench.models.testscenarios.shared.Field)12 Import (org.kie.soup.project.datamodel.imports.Import)11 VerifyRuleFired (org.drools.workbench.models.testscenarios.shared.VerifyRuleFired)9 KieSession (org.kie.api.runtime.KieSession)8 Cheese (org.drools.workbench.models.testscenarios.backend.Cheese)7 Expectation (org.drools.workbench.models.testscenarios.shared.Expectation)7 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)7 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)7 RetractFact (org.drools.workbench.models.testscenarios.shared.RetractFact)6 Fixture (org.drools.workbench.models.testscenarios.shared.Fixture)5 HashMap (java.util.HashMap)3