Search in sources :

Example 6 with ExecutionTrace

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

the class ScenarioRunnerTest method testSimulatedDate.

@SuppressWarnings("deprecation")
@Test
public void testSimulatedDate() throws Exception {
    Scenario sc = new Scenario();
    PseudoClockScheduler clock = new PseudoClockScheduler();
    long time = new Date().getTime();
    clock.setStartupTime(time);
    when(ksession.getSessionClock()).thenReturn(clock);
    ScenarioRunner run = new ScenarioRunner(ksession);
    run.run(sc);
    assertEquals(time, ksession.getSessionClock().getCurrentTime());
    ExecutionTrace ext = new ExecutionTrace();
    ext.setScenarioSimulatedDate(new Date("10-Jul-1974"));
    sc.getFixtures().add(ext);
    run = new ScenarioRunner(ksession);
    run.run(sc);
    long expected = ext.getScenarioSimulatedDate().getTime();
    assertEquals(expected, ksession.getSessionClock().getCurrentTime());
}
Also used : ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) PseudoClockScheduler(org.drools.core.time.impl.PseudoClockScheduler) Date(java.util.Date) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

Example 7 with ExecutionTrace

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

the class ScenarioTest method testIsFactNameUsed.

@Test
public void testIsFactNameUsed() {
    Scenario sc = new Scenario();
    sc.getGlobals().add(new FactData("X", "x", null, false));
    sc.getFixtures().add(new FactData("Q", "q", null, false));
    sc.getFixtures().add(new ExecutionTrace());
    assertTrue(sc.isFactNameReserved("x"));
    assertTrue(sc.isFactNameReserved("q"));
    assertFalse(sc.isFactNameReserved("w"));
    sc = new Scenario();
    assertFalse(sc.isFactNameReserved("w"));
}
Also used : FactData(org.drools.workbench.models.testscenarios.shared.FactData) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

Example 8 with ExecutionTrace

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

the class ScenarioTest method testInsertBetween.

@Test
public void testInsertBetween() {
    Scenario sc = new Scenario();
    VerifyRuleFired vf = new VerifyRuleFired();
    sc.insertBetween(null, vf);
    assertEquals(1, sc.getFixtures().size());
    assertEquals(vf, sc.getFixtures().get(0));
    VerifyRuleFired vf2 = new VerifyRuleFired();
    sc.getFixtures().add(vf2);
    VerifyRuleFired vf3 = new VerifyRuleFired();
    sc.insertBetween(vf, vf3);
    assertEquals(3, sc.getFixtures().size());
    assertEquals(vf, sc.getFixtures().get(0));
    assertEquals(vf2, sc.getFixtures().get(1));
    assertEquals(vf3, sc.getFixtures().get(2));
    VerifyRuleFired vf4 = new VerifyRuleFired();
    sc.insertBetween(vf2, vf4);
    assertEquals(4, sc.getFixtures().size());
    assertEquals(3, sc.getFixtures().indexOf(vf4));
    assertEquals(2, sc.getFixtures().indexOf(vf3));
    // assertEquals(vf4, sc.fixtures.get(3));
    assertEquals(1, sc.getFixtures().indexOf(vf2));
    // assertEquals(vf2, sc.fixtures.get(2));
    assertEquals(0, sc.getFixtures().indexOf(vf));
    VerifyRuleFired vf5 = new VerifyRuleFired();
    sc.insertBetween(null, vf5);
    assertEquals(5, sc.getFixtures().size());
    assertEquals(4, sc.getFixtures().indexOf(vf5));
    sc = new Scenario();
    sc.getFixtures().add(vf);
    ExecutionTrace ex = new ExecutionTrace();
    sc.getFixtures().add(ex);
    sc.insertBetween(null, vf2);
    assertEquals(0, sc.getFixtures().indexOf(vf));
    assertEquals(1, sc.getFixtures().indexOf(vf2));
    assertEquals(2, sc.getFixtures().indexOf(ex));
    assertEquals(3, sc.getFixtures().size());
    sc.insertBetween(ex, vf3);
    assertEquals(4, sc.getFixtures().size());
    assertEquals(0, sc.getFixtures().indexOf(vf));
    assertEquals(1, sc.getFixtures().indexOf(vf2));
    assertEquals(2, sc.getFixtures().indexOf(ex));
    assertEquals(3, sc.getFixtures().indexOf(vf3));
    ExecutionTrace ex2 = new ExecutionTrace();
    sc.getFixtures().add(ex2);
    sc.insertBetween(ex, vf4);
    assertEquals(6, sc.getFixtures().size());
    assertEquals(0, sc.getFixtures().indexOf(vf));
    assertEquals(1, sc.getFixtures().indexOf(vf2));
    assertEquals(2, sc.getFixtures().indexOf(ex));
    assertEquals(3, sc.getFixtures().indexOf(vf3));
    assertEquals(4, sc.getFixtures().indexOf(vf4));
    assertEquals(5, sc.getFixtures().indexOf(ex2));
    sc.insertBetween(ex2, vf5);
    assertEquals(7, sc.getFixtures().size());
    assertEquals(0, sc.getFixtures().indexOf(vf));
    assertEquals(1, sc.getFixtures().indexOf(vf2));
    assertEquals(2, sc.getFixtures().indexOf(ex));
    assertEquals(3, sc.getFixtures().indexOf(vf3));
    assertEquals(4, sc.getFixtures().indexOf(vf4));
    assertEquals(5, sc.getFixtures().indexOf(ex2));
    assertEquals(6, sc.getFixtures().indexOf(vf5));
    sc = new Scenario();
    sc.getFixtures().add(ex);
    sc.insertBetween(null, vf);
    assertEquals(2, sc.getFixtures().size());
    assertEquals(0, sc.getFixtures().indexOf(vf));
    assertEquals(1, sc.getFixtures().indexOf(ex));
}
Also used : VerifyRuleFired(org.drools.workbench.models.testscenarios.shared.VerifyRuleFired) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

Example 9 with ExecutionTrace

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

use of org.drools.workbench.models.testscenarios.shared.ExecutionTrace in project drools-wb by kiegroup.

the class AuditPageViewImplTest method testFiredRules.

@Test
public void testFiredRules() throws Exception {
    final ExecutionTrace executionTrace = new ExecutionTrace();
    final String[] rulesFired = new String[] { "rule 1", "rule 2" };
    executionTrace.setRulesFired(rulesFired);
    testedView.showFiredRules(executionTrace);
    verify(firedRulesTable).showItems(collectionCaptor.capture());
    Assertions.assertThat(collectionCaptor.getValue()).contains(rulesFired);
}
Also used : ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) Test(org.junit.Test)

Aggregations

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