Search in sources :

Example 1 with RetractFact

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

the class ScenarioTest method testVariablesInScope.

@Test
public void testVariablesInScope() {
    Scenario sc = new Scenario();
    sc.getGlobals().add(new FactData("X", "x", new ArrayList(), false));
    sc.getFixtures().add(new FactData("Q", "q", new ArrayList(), true));
    sc.getFixtures().add(new FactData("Z", "z", new ArrayList(), false));
    ExecutionTrace ex1 = new ExecutionTrace();
    sc.getFixtures().add(ex1);
    sc.getFixtures().add(new RetractFact("z"));
    sc.getFixtures().add(new FactData("Y", "y", new ArrayList(), false));
    ExecutionTrace ex2 = new ExecutionTrace();
    sc.getFixtures().add(ex2);
    List l = sc.getFactNamesInScope(ex1, true);
    assertEquals(3, l.size());
    assertEquals("q", l.get(0));
    assertEquals("z", l.get(1));
    assertEquals("x", l.get(2));
    l = sc.getFactNamesInScope(ex1, false);
    assertEquals(2, l.size());
    assertFalse(l.contains(sc.getGlobals().get(0)));
    l = sc.getFactNamesInScope(ex2, true);
    assertEquals(3, l.size());
    assertEquals("q", l.get(0));
    assertEquals("y", l.get(1));
    assertEquals("x", l.get(2));
    l = sc.getFactNamesInScope(null, true);
    assertEquals(0, l.size());
}
Also used : FactData(org.drools.workbench.models.testscenarios.shared.FactData) ArrayList(java.util.ArrayList) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) ArrayList(java.util.ArrayList) List(java.util.List) RetractFact(org.drools.workbench.models.testscenarios.shared.RetractFact) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

Example 2 with RetractFact

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

the class ScenarioRunner method applyFixtures.

private void applyFixtures(final List<Fixture> fixtures, final ScenarioSettings scenarioSettings) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InvalidClockTypeException {
    for (Iterator<Fixture> iterator = fixtures.iterator(); iterator.hasNext(); ) {
        Fixture fixture = iterator.next();
        if (fixture instanceof FactData) {
            factPopulator.add(factPopulatorFactory.createFactPopulator((FactData) fixture));
        } else if (fixture instanceof RetractFact) {
            factPopulator.retractFact(((RetractFact) fixture).getName());
        } else if (fixture instanceof CallMethod) {
            workingMemoryWrapper.executeMethod((CallMethod) fixture);
        } else if (fixture instanceof ActivateRuleFlowGroup) {
            workingMemoryWrapper.activateRuleFlowGroup(((ActivateRuleFlowGroup) fixture).getName());
        } else if (fixture instanceof ExecutionTrace) {
            factPopulator.populate();
            workingMemoryWrapper.executeSubScenario((ExecutionTrace) fixture, scenarioSettings);
        } else if (fixture instanceof Expectation) {
            factPopulator.populate();
            workingMemoryWrapper.verifyExpectation((Expectation) fixture);
        } else {
            throw new IllegalArgumentException("Not sure what to do with " + fixture);
        }
    }
    factPopulator.populate();
}
Also used : FactData(org.drools.workbench.models.testscenarios.shared.FactData) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) ActivateRuleFlowGroup(org.drools.workbench.models.testscenarios.shared.ActivateRuleFlowGroup) Expectation(org.drools.workbench.models.testscenarios.shared.Expectation) RetractFact(org.drools.workbench.models.testscenarios.shared.RetractFact) CallMethod(org.drools.workbench.models.testscenarios.shared.CallMethod)

Example 3 with RetractFact

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

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

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

RetractFact (org.drools.workbench.models.testscenarios.shared.RetractFact)7 ExecutionTrace (org.drools.workbench.models.testscenarios.shared.ExecutionTrace)6 FactData (org.drools.workbench.models.testscenarios.shared.FactData)6 ArrayList (java.util.ArrayList)4 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)4 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)4 Test (org.junit.Test)4 Fixture (org.drools.workbench.models.testscenarios.shared.Fixture)3 ActivateRuleFlowGroup (org.drools.workbench.models.testscenarios.shared.ActivateRuleFlowGroup)2 CallMethod (org.drools.workbench.models.testscenarios.shared.CallMethod)2 List (java.util.List)1 CallFixtureMap (org.drools.workbench.models.testscenarios.shared.CallFixtureMap)1 Expectation (org.drools.workbench.models.testscenarios.shared.Expectation)1 Field (org.drools.workbench.models.testscenarios.shared.Field)1 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)1 FixtureList (org.drools.workbench.models.testscenarios.shared.FixtureList)1 FixturesMap (org.drools.workbench.models.testscenarios.shared.FixturesMap)1 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)1 VerifyRuleFired (org.drools.workbench.models.testscenarios.shared.VerifyRuleFired)1 KieSession (org.kie.api.runtime.KieSession)1