Search in sources :

Example 31 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.

the class ScenarioTest method testCountSuccessFailures.

@Test
public void testCountSuccessFailures() {
    Scenario sc = new Scenario();
    sc.getFixtures().add(new FactData());
    sc.getFixtures().add(new ExecutionTrace());
    VerifyRuleFired vr = new VerifyRuleFired();
    vr.setSuccessResult(false);
    sc.getFixtures().add(vr);
    VerifyField vf = new VerifyField();
    vf.setSuccessResult(true);
    VerifyField vf2 = new VerifyField();
    vf2.setSuccessResult(false);
    VerifyFact vfact = new VerifyFact();
    vfact.getFieldValues().add(vf);
    vfact.getFieldValues().add(vf2);
    sc.getFixtures().add(vfact);
    int[] totals = sc.countFailuresTotal();
    assertEquals(2, totals[0]);
    assertEquals(3, totals[1]);
}
Also used : VerifyRuleFired(org.drools.workbench.models.testscenarios.shared.VerifyRuleFired) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

Example 32 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.

the class ScenarioTest method testAllowRemoveFact.

@Test
public void testAllowRemoveFact() {
    Scenario sc = new Scenario();
    FactData fd1 = new FactData("X", "x", new ArrayList(), false);
    sc.getFixtures().add(fd1);
    FactData fd2 = new FactData("Q", "q", new ArrayList(), false);
    sc.getFixtures().add(fd2);
    FactData fd3 = new FactData("Z", "z", new ArrayList(), false);
    sc.getFixtures().add(fd3);
    ExecutionTrace ex1 = new ExecutionTrace();
    FactData fd4 = new FactData("I", "i", new ArrayList(), false);
    sc.getGlobals().add(fd4);
    sc.getFixtures().add(ex1);
    sc.getFixtures().add(new RetractFact("z"));
    sc.getFixtures().add(new FactData("Z", "z", new ArrayList(), true));
    sc.getFixtures().add(new VerifyFact("q", new ArrayList()));
    assertFalse(sc.isFactDataReferenced(fd1));
    assertTrue(sc.isFactDataReferenced(fd2));
    assertTrue(sc.isFactDataReferenced(fd3));
    assertFalse(sc.isFactDataReferenced(fd4));
}
Also used : FactData(org.drools.workbench.models.testscenarios.shared.FactData) ArrayList(java.util.ArrayList) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) RetractFact(org.drools.workbench.models.testscenarios.shared.RetractFact) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

Example 33 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.

the class ScenarioTest method testRemoveFixture.

@Test
public void testRemoveFixture() {
    Scenario sc = new Scenario();
    VerifyRuleFired vf1 = new VerifyRuleFired();
    VerifyRuleFired vf2 = new VerifyRuleFired();
    VerifyRuleFired vf3 = new VerifyRuleFired();
    FactData fd = new FactData();
    sc.getFixtures().add(vf1);
    sc.getFixtures().add(vf2);
    sc.getFixtures().add(vf3);
    sc.getGlobals().add(fd);
    sc.removeFixture(vf2);
    assertEquals(2, sc.getFixtures().size());
    assertEquals(vf1, sc.getFixtures().get(0));
    assertEquals(vf3, sc.getFixtures().get(1));
    assertEquals(1, sc.getGlobals().size());
    sc.removeFixture(fd);
    assertEquals(0, sc.getGlobals().size());
    assertEquals(2, sc.getFixtures().size());
}
Also used : VerifyRuleFired(org.drools.workbench.models.testscenarios.shared.VerifyRuleFired) FactData(org.drools.workbench.models.testscenarios.shared.FactData) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

Example 34 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.

the class FactPopulatorTest method testPopulateNested.

@Test
public void testPopulateNested() throws Exception {
    TypeResolver typeResolver = getTypeResolver();
    FactData cheeseFactData = new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("type", "cheddar"), new FieldData("price", "42")), false);
    factPopulator.add(new NewFactPopulator(populatedData, typeResolver, cheeseFactData));
    FactData outerFactData = new FactData("OuterFact", "p1", Arrays.<Field>asList(new FieldData("name", "mic"), new FieldData("innerFact", "=c1")), false);
    factPopulator.add(new NewFactPopulator(populatedData, typeResolver, outerFactData));
    factPopulator.populate();
    assertTrue(populatedData.containsKey("c1"));
    assertTrue(populatedData.containsKey("p1"));
    OuterFact o = (OuterFact) populatedData.get("p1");
    assertEquals(populatedData.get("c1"), o.getInnerFact());
}
Also used : CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) 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) OuterFact(org.drools.workbench.models.testscenarios.backend.OuterFact) Test(org.junit.Test)

Example 35 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.

the class FactPopulatorTest method testCollectionSums.

@Test
public void testCollectionSums() throws Exception {
    TypeResolver typeResolver = getTypeResolver();
    List<Field> fieldData = new ArrayList<Field>();
    CollectionFieldData collectionFieldData = new CollectionFieldData();
    collectionFieldData.setName("list");
    fieldData.add(collectionFieldData);
    collectionFieldData.getCollectionFieldList().add(new FieldData("list", "=1+3"));
    FactData wrapperFactData = new FactData("MyCollectionWrapper", "wrapper", fieldData, false);
    factPopulator.add(new NewFactPopulator(populatedData, typeResolver, wrapperFactData));
    factPopulator.populate();
    assertTrue(populatedData.containsKey("wrapper"));
    MyCollectionWrapper wrapper = (MyCollectionWrapper) populatedData.get("wrapper");
    assertNotNull(wrapper);
    assertEquals(1, wrapper.getList().size());
    assertNotNull(wrapper.getList().get(0));
    assertEquals(4, wrapper.getList().get(0));
}
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) MyCollectionWrapper(org.drools.workbench.models.testscenarios.backend.MyCollectionWrapper) 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) CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) 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