use of org.drools.workbench.models.testscenarios.shared.VerifyField in project drools by kiegroup.
the class ScenarioRunnerTest method testIntgerationStateful.
@Test
public void testIntgerationStateful() 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", "1")), false));
ExecutionTrace ex = new ExecutionTrace();
sc.getFixtures().add(ex);
sc.getFixtures().add(new FactData("Cheese", "c2", Arrays.<Field>asList(new FieldData("price", "2")), false));
sc.getFixtures().add(new VerifyFact("c1", ls(new VerifyField("type", "rule1", "=="))));
ex = new ExecutionTrace();
sc.getFixtures().add(ex);
sc.getFixtures().add(new VerifyFact("c1", ls(new VerifyField("type", "rule2", "=="))));
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.VerifyField 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.VerifyField 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_);
}
use of org.drools.workbench.models.testscenarios.shared.VerifyField 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]);
}
use of org.drools.workbench.models.testscenarios.shared.VerifyField in project drools by kiegroup.
the class FactVerifierTest method testVerifyAnonymousFacts.
@Test
public void testVerifyAnonymousFacts() throws Exception {
TypeResolver typeResolver = mock(TypeResolver.class);
FactVerifier factVerifier = new FactVerifier(new HashMap<String, Object>(), typeResolver, ksession, new HashMap<String, Object>());
Cheese c = new Cheese();
c.setPrice(42);
c.setType("stilton");
// configure the mock to return the value
Set o = Collections.singleton((Object) c);
when(ksession.getObjects()).thenReturn(o);
VerifyFact vf = new VerifyFact("Cheese", new ArrayList<VerifyField>(), true);
vf.getFieldValues().add(new VerifyField("price", "42", "=="));
vf.getFieldValues().add(new VerifyField("type", "stilton", "=="));
factVerifier.verify(vf);
assertTrue(vf.wasSuccessful());
vf = new VerifyFact("Person", new ArrayList<VerifyField>(), true);
vf.getFieldValues().add(new VerifyField("age", "42", "=="));
factVerifier.verify(vf);
assertFalse(vf.wasSuccessful());
vf = new VerifyFact("Cheese", new ArrayList<VerifyField>(), true);
vf.getFieldValues().add(new VerifyField("price", "43", "=="));
vf.getFieldValues().add(new VerifyField("type", "stilton", "=="));
factVerifier.verify(vf);
assertFalse(vf.wasSuccessful());
assertEquals(Boolean.FALSE, vf.getFieldValues().get(0).getSuccessResult());
vf = new VerifyFact("Cell", new ArrayList<VerifyField>(), true);
vf.getFieldValues().add(new VerifyField("value", "43", "=="));
factVerifier.verify(vf);
assertFalse(vf.wasSuccessful());
assertEquals(Boolean.FALSE, vf.getFieldValues().get(0).getSuccessResult());
}
Aggregations