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());
}
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();
}
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());
}
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"));
}
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));
}
Aggregations