Search in sources :

Example 21 with VerifyFact

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());
}
Also used : Set(java.util.Set) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) ArrayList(java.util.ArrayList) Cheese(org.drools.workbench.models.testscenarios.backend.Cheese) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) Test(org.junit.Test)

Example 22 with VerifyFact

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());
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) Cheese(org.drools.workbench.models.testscenarios.backend.Cheese) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) Test(org.junit.Test)

Example 23 with VerifyFact

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;
}
Also used : VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ArrayList(java.util.ArrayList) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario)

Example 24 with VerifyFact

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;
}
Also used : VerifyRuleFired(org.drools.workbench.models.testscenarios.shared.VerifyRuleFired) ArrayList(java.util.ArrayList) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) ActivateRuleFlowGroup(org.drools.workbench.models.testscenarios.shared.ActivateRuleFlowGroup) CallMethod(org.drools.workbench.models.testscenarios.shared.CallMethod) CallFixtureMap(org.drools.workbench.models.testscenarios.shared.CallFixtureMap) FactData(org.drools.workbench.models.testscenarios.shared.FactData) FixturesMap(org.drools.workbench.models.testscenarios.shared.FixturesMap) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) FixtureList(org.drools.workbench.models.testscenarios.shared.FixtureList) RetractFact(org.drools.workbench.models.testscenarios.shared.RetractFact)

Example 25 with VerifyFact

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);
}
Also used : Path(org.uberfire.backend.vfs.Path) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) URL(java.net.URL) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

Aggregations

VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)25 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)20 Test (org.junit.Test)20 FactData (org.drools.workbench.models.testscenarios.shared.FactData)19 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)17 ExecutionTrace (org.drools.workbench.models.testscenarios.shared.ExecutionTrace)13 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)11 Import (org.kie.soup.project.datamodel.imports.Import)11 ArrayList (java.util.ArrayList)10 VerifyRuleFired (org.drools.workbench.models.testscenarios.shared.VerifyRuleFired)9 KieSession (org.kie.api.runtime.KieSession)8 Expectation (org.drools.workbench.models.testscenarios.shared.Expectation)7 Field (org.drools.workbench.models.testscenarios.shared.Field)6 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)6 Set (java.util.Set)5 Cheese (org.drools.workbench.models.testscenarios.backend.Cheese)5 HashMap (java.util.HashMap)4 RetractFact (org.drools.workbench.models.testscenarios.shared.RetractFact)4 Fixture (org.drools.workbench.models.testscenarios.shared.Fixture)3 HashSet (java.util.HashSet)2