use of org.drools.workbench.models.testscenarios.shared.VerifyField in project drools by kiegroup.
the class FactVerifierTest method testVerifyFactExplanation.
@Test
public void testVerifyFactExplanation() throws Exception {
Cheese f1 = new Cheese();
f1.setType(null);
TypeResolver typeResolver = mock(TypeResolver.class);
HashMap<String, Object> populatedData = new HashMap<String, Object>();
populatedData.put("f1", f1);
// configure the mock to return the value
Set o = Collections.singleton((Object) f1);
when(ksession.getObjects()).thenReturn(o);
FactVerifier factVerifier = new FactVerifier(populatedData, typeResolver, ksession, new HashMap<String, Object>());
VerifyFact vf = new VerifyFact();
vf.setName("f1");
vf.getFieldValues().add(new VerifyField("type", "boo", "!="));
factVerifier.verify(vf);
VerifyField vfl = vf.getFieldValues().get(0);
assertEquals("[f1] field [type] was not [boo].", vfl.getExplanation());
}
use of org.drools.workbench.models.testscenarios.shared.VerifyField in project drools-wb by kiegroup.
the class TestScenarioIndexVisitor method visit.
private void visit(final Fixture fixture) {
if (fixture instanceof FixtureList) {
for (Fixture child : ((FixtureList) fixture)) {
visit(child);
}
} else if (fixture instanceof FixturesMap) {
for (Fixture child : ((FixturesMap) fixture).values()) {
visit(child);
}
} else if (fixture instanceof FactData) {
final FactData factData = (FactData) fixture;
final String typeName = factData.getType();
final String fullyQualifiedClassName = getFullyQualifiedClassName(typeName);
ResourceReference resRef = addResourceReference(fullyQualifiedClassName, ResourceType.JAVA);
factDataToFullyQualifiedClassNameMap.put(factData.getName(), fullyQualifiedClassName);
for (Field field : factData.getFieldData()) {
final String fieldName = field.getName();
final String fieldFullyQualifiedClassName = getFieldFullyQualifiedClassName(fullyQualifiedClassName, fieldName);
resRef.addPartReference(fieldName, PartType.FIELD);
addResourceReference(fieldFullyQualifiedClassName, ResourceType.JAVA);
}
} else if (fixture instanceof VerifyFact) {
final VerifyFact verifyFact = (VerifyFact) fixture;
final String typeName = verifyFact.getName();
// If VerifyFact is not anonymous lookup FQCN from previous FactData elements
String fullyQualifiedClassName = null;
if (!verifyFact.anonymous) {
fullyQualifiedClassName = factDataToFullyQualifiedClassNameMap.get(verifyFact.getName());
} else {
fullyQualifiedClassName = getFullyQualifiedClassName(typeName);
}
ResourceReference resRef = null;
if (fullyQualifiedClassName != null) {
resRef = addResourceReference(fullyQualifiedClassName, ResourceType.JAVA);
for (VerifyField field : verifyFact.getFieldValues()) {
final String fieldName = field.getFieldName();
final String fieldFullyQualifiedClassName = getFieldFullyQualifiedClassName(fullyQualifiedClassName, fieldName);
resRef.addPartReference(fieldName, PartType.FIELD);
addResourceReference(fieldFullyQualifiedClassName, ResourceType.JAVA);
}
}
} else if (fixture instanceof VerifyRuleFired) {
final VerifyRuleFired verifyRuleFired = (VerifyRuleFired) fixture;
addResourceReference(verifyRuleFired.getRuleName(), ResourceType.RULE);
}
}
use of org.drools.workbench.models.testscenarios.shared.VerifyField in project drools-wb by kiegroup.
the class TestScenarioFactory method makeTestScenarioWithVerifyFact.
public static Scenario makeTestScenarioWithVerifyFact(final String packageName, final Collection<Import> imports, final String name) {
final Scenario model = new Scenario();
model.getImports().getImports().addAll(imports);
model.setPackageName(packageName);
model.setName(name);
model.getFixtures().add(new FactData("Applicant", "$a", new ArrayList<Field>() {
{
add(new FieldData("age", "33"));
}
}, false));
model.getFixtures().add(new VerifyFact("Mortgage", new ArrayList<VerifyField>() {
{
add(new VerifyField("amount", "10000", "=="));
}
}, true));
return model;
}
use of org.drools.workbench.models.testscenarios.shared.VerifyField in project drools by kiegroup.
the class FactVerifier method verify.
public void verify(VerifyFact verifyFact) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
// Clear existing results
for (VerifyField vf : verifyFact.getFieldValues()) {
vf.setSuccessResult(null);
vf.setExplanation("Fact of type [" + verifyFact.getName() + "] was not found in the results.");
}
if (!verifyFact.anonymous) {
FactFieldValueVerifier fieldVerifier = new FactFieldValueVerifier(populatedData, verifyFact.getName(), getFactObject(verifyFact.getName(), populatedData, globalData), resolver);
fieldVerifier.checkFields(verifyFact.getFieldValues());
} else {
for (Object object : ksession.getObjects()) {
if (verifyFact(object, verifyFact, populatedData, resolver)) {
return;
}
}
for (VerifyField verifyField : verifyFact.getFieldValues()) {
if (verifyField.getSuccessResult() == null) {
verifyField.setSuccessResult(Boolean.FALSE);
verifyField.setActualResult("No match");
}
}
}
}
use of org.drools.workbench.models.testscenarios.shared.VerifyField in project drools by kiegroup.
the class ScenarioRunnerTest method testIntegrationWithModify.
@Test
public void testIntegrationWithModify() 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));
sc.getFixtures().add(new ExecutionTrace());
sc.getFixtures().add(new VerifyFact("c1", ls(new VerifyField("type", "rule1", "=="))));
sc.getFixtures().add(new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("price", "42")), true));
sc.getFixtures().add(new ExecutionTrace());
sc.getFixtures().add(new VerifyFact("c1", ls(new VerifyField("type", "rule3", "=="))));
KieSession ksession = getKieSession("test_stateful.drl");
ScenarioRunner run = new ScenarioRunner(ksession);
run.run(sc);
assertTrue(sc.wasSuccessful());
}
Aggregations