Search in sources :

Example 11 with VerifyRuleFired

use of org.drools.workbench.models.testscenarios.shared.VerifyRuleFired 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 12 with VerifyRuleFired

use of org.drools.workbench.models.testscenarios.shared.VerifyRuleFired 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 13 with VerifyRuleFired

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

the class RuleFiredVerifierTest method testRuleFiredWithEnum.

@Test
public void testRuleFiredWithEnum() throws Exception {
    Map<String, Integer> firingCounts = new HashMap<String, Integer>();
    firingCounts.put("foo", 2);
    firingCounts.put("bar", 1);
    // and baz, we leave out
    RuleFiredVerifier ruleFiredVerifier = new RuleFiredVerifier();
    ruleFiredVerifier.setFireCounter(firingCounts);
    VerifyRuleFired v = new VerifyRuleFired();
    v.setRuleName("foo");
    v.setExpectedFire(true);
    ruleFiredVerifier.verifyFiringCounts(v);
    assertTrue(v.getSuccessResult());
    assertEquals(2, v.getActualResult().intValue());
}
Also used : VerifyRuleFired(org.drools.workbench.models.testscenarios.shared.VerifyRuleFired) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 14 with VerifyRuleFired

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

the class RuleFiredVerifierTest method testVerifyRuleFired.

@Test
public void testVerifyRuleFired() throws Exception {
    RuleFiredVerifier ruleFiredVerifier = new RuleFiredVerifier();
    VerifyRuleFired vr = new VerifyRuleFired("qqq", 42, null);
    Map<String, Integer> f = new HashMap<String, Integer>();
    f.put("qqq", 42);
    f.put("qaz", 1);
    ruleFiredVerifier.setFireCounter(f);
    ruleFiredVerifier.verifyFiringCounts(vr);
    assertTrue(vr.wasSuccessful());
    assertEquals(42, vr.getActualResult().intValue());
    vr = new VerifyRuleFired("qqq", 41, null);
    ruleFiredVerifier.setFireCounter(f);
    ruleFiredVerifier.verifyFiringCounts(vr);
    assertFalse(vr.wasSuccessful());
    assertEquals(42, vr.getActualResult().intValue());
    vr = new VerifyRuleFired("qaz", 1, null);
    ruleFiredVerifier.setFireCounter(f);
    ruleFiredVerifier.verifyFiringCounts(vr);
    assertTrue(vr.wasSuccessful());
    assertEquals(1, vr.getActualResult().intValue());
    vr = new VerifyRuleFired("XXX", null, false);
    ruleFiredVerifier.setFireCounter(f);
    ruleFiredVerifier.verifyFiringCounts(vr);
    assertTrue(vr.wasSuccessful());
    assertEquals(0, vr.getActualResult().intValue());
    vr = new VerifyRuleFired("qqq", null, true);
    ruleFiredVerifier.setFireCounter(f);
    ruleFiredVerifier.verifyFiringCounts(vr);
    assertTrue(vr.wasSuccessful());
    assertEquals(42, vr.getActualResult().intValue());
    vr = new VerifyRuleFired("qqq", null, false);
    ruleFiredVerifier.setFireCounter(f);
    ruleFiredVerifier.verifyFiringCounts(vr);
    assertFalse(vr.wasSuccessful());
    assertEquals(42, vr.getActualResult().intValue());
}
Also used : VerifyRuleFired(org.drools.workbench.models.testscenarios.shared.VerifyRuleFired) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 15 with VerifyRuleFired

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

the class RuleFiredVerifierTest method testCountVerification.

@Test
public void testCountVerification() throws Exception {
    Map<String, Integer> firingCounts = new HashMap<String, Integer>();
    firingCounts.put("foo", 2);
    firingCounts.put("bar", 1);
    // and baz, we leave out
    RuleFiredVerifier ruleFiredVerifier = new RuleFiredVerifier();
    ruleFiredVerifier.setFireCounter(firingCounts);
    VerifyRuleFired v = new VerifyRuleFired();
    v.setRuleName("foo");
    v.setExpectedFire(true);
    ruleFiredVerifier.verifyFiringCounts(v);
    assertTrue(v.getSuccessResult());
    assertEquals(2, v.getActualResult().intValue());
    v = new VerifyRuleFired();
    v.setRuleName("foo");
    v.setExpectedFire(false);
    ruleFiredVerifier.verifyFiringCounts(v);
    assertFalse(v.getSuccessResult());
    assertEquals(2, v.getActualResult().intValue());
    assertNotNull(v.getExplanation());
    v = new VerifyRuleFired();
    v.setRuleName("foo");
    v.setExpectedCount(2);
    ruleFiredVerifier.verifyFiringCounts(v);
    assertTrue(v.getSuccessResult());
    assertEquals(2, v.getActualResult().intValue());
}
Also used : VerifyRuleFired(org.drools.workbench.models.testscenarios.shared.VerifyRuleFired) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

VerifyRuleFired (org.drools.workbench.models.testscenarios.shared.VerifyRuleFired)16 Test (org.junit.Test)11 FactData (org.drools.workbench.models.testscenarios.shared.FactData)9 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)9 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)9 ExecutionTrace (org.drools.workbench.models.testscenarios.shared.ExecutionTrace)8 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)7 Expectation (org.drools.workbench.models.testscenarios.shared.Expectation)6 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)5 KieSession (org.kie.api.runtime.KieSession)5 Import (org.kie.soup.project.datamodel.imports.Import)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 Fixture (org.drools.workbench.models.testscenarios.shared.Fixture)3 HashSet (java.util.HashSet)2 ProjectClassLoader (org.drools.core.common.ProjectClassLoader)2 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)2 ActivateRuleFlowGroup (org.drools.workbench.models.testscenarios.shared.ActivateRuleFlowGroup)2 Field (org.drools.workbench.models.testscenarios.shared.Field)2 FixtureList (org.drools.workbench.models.testscenarios.shared.FixtureList)2