Search in sources :

Example 16 with VerifyFact

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

the class ScenarioRunnerTest method testIntegrationWithRetract.

@Test
public void testIntegrationWithRetract() throws Exception {
    Scenario sc = new Scenario();
    sc.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Cheese"));
    sc.getFixtures().add(new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("price", "46"), new FieldData("type", "XXX")), false));
    sc.getFixtures().add(new FactData("Cheese", "c2", Arrays.<Field>asList(new FieldData("price", "42")), false));
    sc.getFixtures().add(new ExecutionTrace());
    sc.getFixtures().add(new VerifyFact("c1", ls(new VerifyField("type", "XXX", "=="))));
    sc.getFixtures().add(new RetractFact("c2"));
    sc.getFixtures().add(new ExecutionTrace());
    sc.getFixtures().add(new VerifyFact("c1", ls(new VerifyField("type", "rule4", "=="))));
    KieSession ksession = getKieSession("test_stateful.drl");
    ScenarioRunner run = new ScenarioRunner(ksession);
    run.run(sc);
    assertTrue(sc.wasSuccessful());
}
Also used : FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) Field(org.drools.workbench.models.testscenarios.shared.Field) Import(org.kie.soup.project.datamodel.imports.Import) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) KieSession(org.kie.api.runtime.KieSession) 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 17 with VerifyFact

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

the class ScenarioRunnerTest method testIntegrationWithDeclaredTypes.

@Test
public void testIntegrationWithDeclaredTypes() throws Exception {
    Scenario scenario = new Scenario();
    scenario.getImports().addImport(new Import("foo.bar.Coolness"));
    FactData[] facts = new FactData[] { new FactData("Coolness", "c", Arrays.<Field>asList(new FieldData("num", "42"), new FieldData("name", "mic")), false) };
    scenario.getFixtures().addAll(Arrays.asList(facts));
    ExecutionTrace executionTrace = new ExecutionTrace();
    scenario.getRules().add("rule1");
    scenario.setInclusive(true);
    scenario.getFixtures().add(executionTrace);
    Expectation[] assertions = new Expectation[2];
    assertions[0] = new VerifyFact("c", ls(new VerifyField("num", "42", "==")));
    assertions[1] = new VerifyRuleFired("rule1", 1, null);
    scenario.getFixtures().addAll(Arrays.asList(assertions));
    KieSession ksession = getKieSession("test_rules3.drl");
    ClassLoader cl = ((KnowledgeBaseImpl) ksession.getKieBase()).getRootClassLoader();
    HashSet<String> imports = new HashSet<String>();
    imports.add("foo.bar.*");
    assertNotNull(cl.loadClass("foo.bar.Coolness"));
    ClassLoader cl_ = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(cl);
    // resolver will need to have generated beans in it - possibly using a composite classloader from the package,
    // including whatever CL has the generated beans...
    ScenarioRunner run = new ScenarioRunner(ksession);
    run.run(scenario);
    assertEquals(1, executionTrace.getNumberOfRulesFired().intValue());
    assertTrue(scenario.wasSuccessful());
    Thread.currentThread().setContextClassLoader(cl_);
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) VerifyRuleFired(org.drools.workbench.models.testscenarios.shared.VerifyRuleFired) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ProjectClassLoader(org.drools.core.common.ProjectClassLoader) KieSession(org.kie.api.runtime.KieSession) Expectation(org.drools.workbench.models.testscenarios.shared.Expectation) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with VerifyFact

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

the class ScenarioTest method testExecutionTrace.

@Test
public void testExecutionTrace() {
    Scenario sc = new Scenario();
    sc.getGlobals().add(new FactData("A", "A", new ArrayList(), false));
    sc.getFixtures().add(new FactData("B", "B", new ArrayList(), true));
    sc.getFixtures().add(new FactData("C", "C", new ArrayList(), true));
    ExecutionTrace ex1 = new ExecutionTrace();
    sc.getFixtures().add(ex1);
    sc.getFixtures().add(new VerifyFact());
    sc.getFixtures().add(new RetractFact());
    sc.getFixtures().add(new FactData("D", "D", new ArrayList(), false));
    sc.getFixtures().add(new FactData("E", "E", new ArrayList(), false));
    ExecutionTrace ex2 = new ExecutionTrace();
    sc.getFixtures().add(ex2);
    sc.getFixtures().add(new VerifyFact());
    sc.getFixtures().add(new FactData("F", "F", new ArrayList(), false));
    ExecutionTrace ex3 = new ExecutionTrace();
    sc.getFixtures().add(ex3);
    assertEquals(11, sc.getFixtures().size());
    sc.removeExecutionTrace(ex2);
    assertEquals(6, sc.getFixtures().size());
    assertTrue(sc.isFactNameReserved("A"));
    assertTrue(sc.isFactNameReserved("B"));
    assertTrue(sc.isFactNameReserved("C"));
    assertFalse(sc.isFactNameReserved("D"));
    assertFalse(sc.isFactNameReserved("E"));
    assertTrue(sc.isFactNameReserved("F"));
}
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 19 with VerifyFact

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

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

Aggregations

VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)25 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)20 Test (org.junit.Test)20 FactData (org.drools.workbench.models.testscenarios.shared.FactData)19 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)17 ExecutionTrace (org.drools.workbench.models.testscenarios.shared.ExecutionTrace)13 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)11 Import (org.kie.soup.project.datamodel.imports.Import)11 ArrayList (java.util.ArrayList)10 VerifyRuleFired (org.drools.workbench.models.testscenarios.shared.VerifyRuleFired)9 KieSession (org.kie.api.runtime.KieSession)8 Expectation (org.drools.workbench.models.testscenarios.shared.Expectation)7 Field (org.drools.workbench.models.testscenarios.shared.Field)6 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)6 Set (java.util.Set)5 Cheese (org.drools.workbench.models.testscenarios.backend.Cheese)5 HashMap (java.util.HashMap)4 RetractFact (org.drools.workbench.models.testscenarios.shared.RetractFact)4 Fixture (org.drools.workbench.models.testscenarios.shared.Fixture)3 HashSet (java.util.HashSet)2