}
@Test
public void testVerifyFacts() throws Exception {
Scenario scenario = new Scenario();
scenario.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Cheese"));
scenario.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Person"));
ScenarioRunner runner = new ScenarioRunner(ksession);
scenario.getFixtures().add(
new FactData(
"Cheese",
"f1",
Arrays.<Field>asList(
new FieldData(
"type",
"cheddar"),
new FieldData(
"price",
"42")),
false
));
scenario.getFixtures().add(
new FactData(
"Person",
"f2",
Arrays.<Field>asList(
new FieldData(
"name",
"michael"),
new FieldData(
"age",
"33")),
false
));
// test all true
VerifyFact verifyCheddar = new VerifyFact();
verifyCheddar.setName("f1");
verifyCheddar.setFieldValues(
asList(
new VerifyField(
"type",
"cheddar",
"=="),
new VerifyField(
"price",
"42",
"==")));
scenario.getFixtures().add(verifyCheddar);
VerifyFact michaelVerifyFact = new VerifyFact();
michaelVerifyFact.setName("f2");
michaelVerifyFact.setFieldValues(
asList(
new VerifyField(
"name",
"michael",
"=="),
new VerifyField(
"age",
"33",
"==")));
scenario.getFixtures().add(michaelVerifyFact);
// test one false
VerifyFact markVerifyFact = new VerifyFact();
markVerifyFact.setName("f2");
markVerifyFact.setFieldValues(
asList(
new VerifyField(
"name",
"mark",
"=="),
new VerifyField(
"age",
"33",
"==")));
scenario.getFixtures().add(markVerifyFact);
// test 2 false
VerifyFact mark2VerifyFact = new VerifyFact();
mark2VerifyFact.setName("f2");
mark2VerifyFact.setFieldValues(
asList(
new VerifyField(
"name",
"mark",
"=="),
new VerifyField(
"age",
"32",
"==")));
scenario.getFixtures().add(mark2VerifyFact);
runner.run(scenario);
for (VerifyField verifyField : verifyCheddar.getFieldValues()) {
assertTrue(verifyField.getSuccessResult());