use of org.drools.workbench.models.testscenarios.shared.VerifyFact 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());
}
use of org.drools.workbench.models.testscenarios.shared.VerifyFact in project drools by kiegroup.
the class FactVerifierTest method testVerifyFactsWithOperator.
@Test
public void testVerifyFactsWithOperator() throws Exception {
TypeResolver typeResolver = mock(TypeResolver.class);
Cheese f1 = new Cheese("cheddar", 42);
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>());
// test all true
VerifyFact vf = new VerifyFact();
vf.setName("f1");
vf.getFieldValues().add(new VerifyField("type", "cheddar", "=="));
vf.getFieldValues().add(new VerifyField("price", "4777", "!="));
factVerifier.verify(vf);
for (int i = 0; i < vf.getFieldValues().size(); i++) {
assertTrue(vf.getFieldValues().get(i).getSuccessResult());
}
vf = new VerifyFact();
vf.setName("f1");
vf.getFieldValues().add(new VerifyField("type", "cheddar", "!="));
factVerifier.verify(vf);
assertFalse(vf.getFieldValues().get(0).getSuccessResult());
}
use of org.drools.workbench.models.testscenarios.shared.VerifyFact in project drools-wb by kiegroup.
the class TestScenarioFactory method makeTestScenarioWithGlobalVerifyGlobal.
public static Scenario makeTestScenarioWithGlobalVerifyGlobal(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.getGlobals().add(new FactData("Date", "day", new ArrayList<Field>(), false));
model.getFixtures().add(new VerifyFact("day", new ArrayList<VerifyField>() {
{
add(new VerifyField("minutes", "45", "=="));
}
}, false));
return model;
}
use of org.drools.workbench.models.testscenarios.shared.VerifyFact in project drools-wb by kiegroup.
the class ScenarioHelper method lumpyMap.
/**
* Called lumpy map - as this takes a flat list of fixtures, and groups
* things together. It will return a list - of which each element will
* either be a list - or a map. If its a map - then its a map of FactData to
* the fact type. If its a list, then it will be expectations or
* retractions.
* <p/>
* Man, this will be so much nicer with generics.
* @return List<List<VeryifyRuleFired or VerifyFact or RetractFact> OR
* Map<String, List<FactData>> OR ExecutionTrace>
*/
public List<Fixture> lumpyMap(final List<Fixture> fixtures) {
List<Fixture> output = new ArrayList<Fixture>();
FixturesMap dataInput = new FixturesMap();
CallFixtureMap callOnDataInput = new CallFixtureMap();
FixtureList verifyFact = new FixtureList();
FixtureList verifyRule = new FixtureList();
FixtureList retractFacts = new FixtureList();
for (Fixture fixture : fixtures) {
if (fixture instanceof FactData) {
accumulateDataForFactData(dataInput, (FactData) fixture);
} else if (fixture instanceof CallMethod) {
accumulateCallMethod(callOnDataInput, (CallMethod) fixture);
} else if (fixture instanceof ActivateRuleFlowGroup) {
accumulateDataForActivateRuleFlowGroup(dataInput, fixture);
} else if (fixture instanceof RetractFact) {
retractFacts.add(fixture);
} else if (fixture instanceof VerifyRuleFired) {
verifyRule.add(fixture);
} else if (fixture instanceof VerifyFact) {
verifyFact.add(fixture);
} else if (fixture instanceof ExecutionTrace) {
gatherFixtures(output, dataInput, callOnDataInput, verifyFact, verifyRule, retractFacts, false);
output.add(fixture);
verifyRule = new FixtureList();
verifyFact = new FixtureList();
retractFacts = new FixtureList();
callOnDataInput = new CallFixtureMap();
dataInput = new FixturesMap();
}
}
gatherFixtures(output, dataInput, callOnDataInput, verifyFact, verifyRule, retractFacts, true);
return output;
}
use of org.drools.workbench.models.testscenarios.shared.VerifyFact in project drools-wb by kiegroup.
the class ScenarioTestEditorServiceImplTest method loadScenario.
@Test
public void loadScenario() throws Exception {
final URL scenarioResource = getClass().getResource("Are they old enough.scenario");
final Path scenarioPath = PathFactory.newPath(scenarioResource.getFile(), scenarioResource.toURI().toString());
final Scenario loadedScenario = testEditorService.load(scenarioPath);
assertNotNull(loadedScenario);
assertEquals("mortgages.mortgages", loadedScenario.getPackageName());
assertEquals(5, loadedScenario.getFixtures().size());
assertTrue(loadedScenario.getFixtures().get(0) instanceof FactData);
assertTrue(loadedScenario.getFixtures().get(1) instanceof FactData);
assertTrue(loadedScenario.getFixtures().get(2) instanceof FactData);
assertTrue(loadedScenario.getFixtures().get(3) instanceof ExecutionTrace);
assertTrue(loadedScenario.getFixtures().get(4) instanceof VerifyFact);
}
Aggregations