Search in sources :

Example 6 with VerifyFact

use of org.drools.workbench.models.testscenarios.shared.VerifyFact in project drools by kiegroup.

the class ScenarioRunnerTest method testVerifyFactsWithEnum.

@Test
public void testVerifyFactsWithEnum() throws Exception {
    FieldData fieldData = new FieldData("cheeseType", "CheeseType.CHEDDAR");
    fieldData.setNature(FieldData.TYPE_ENUM);
    FactData cheeseFactData = new FactData("Cheese", "c1", Arrays.<Field>asList(fieldData), false);
    FieldData cheeseType = new FieldData("cheeseType", "CheeseType.CHEDDAR");
    cheeseType.setNature(FieldData.TYPE_ENUM);
    FactData f1 = new FactData("Cheese", "f1", Arrays.<Field>asList(cheeseType), false);
    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.CheeseType"));
    scenario.getFixtures().add(cheeseFactData);
    scenario.getFixtures().add(f1);
    ScenarioRunner runner = new ScenarioRunner(ksession);
    VerifyFact vf = new VerifyFact();
    vf.setName("f1");
    VerifyField verifyField = new VerifyField("cheeseType", "CheeseType.CHEDDAR", "==");
    verifyField.setNature(VerifyField.TYPE_ENUM);
    vf.setFieldValues(ls(verifyField));
    scenario.getFixtures().add(vf);
    runner.run(scenario);
    for (VerifyField field : vf.getFieldValues()) {
        assertTrue(field.getSuccessResult());
    }
}
Also used : FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) Import(org.kie.soup.project.datamodel.imports.Import) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) FactData(org.drools.workbench.models.testscenarios.shared.FactData) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

Example 7 with VerifyFact

use of org.drools.workbench.models.testscenarios.shared.VerifyFact in project drools by kiegroup.

the class ScenarioRunnerTest method testVerifyFacts.

@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());
    }
    for (VerifyField verifyField : michaelVerifyFact.getFieldValues()) {
        assertTrue(verifyField.getSuccessResult());
    }
    assertFalse((markVerifyFact.getFieldValues().get(0)).getSuccessResult());
    assertTrue((markVerifyFact.getFieldValues().get(1)).getSuccessResult());
    assertEquals("michael", markVerifyFact.getFieldValues().get(0).getActualResult());
    assertEquals("mark", markVerifyFact.getFieldValues().get(0).getExpected());
    assertFalse((mark2VerifyFact.getFieldValues().get(0)).getSuccessResult());
    assertFalse((mark2VerifyFact.getFieldValues().get(1)).getSuccessResult());
    assertEquals("michael", mark2VerifyFact.getFieldValues().get(0).getActualResult());
    assertEquals("mark", mark2VerifyFact.getFieldValues().get(0).getExpected());
    assertEquals("33", mark2VerifyFact.getFieldValues().get(1).getActualResult());
    assertEquals("32", mark2VerifyFact.getFieldValues().get(1).getExpected());
}
Also used : FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) Field(org.drools.workbench.models.testscenarios.shared.Field) Import(org.kie.soup.project.datamodel.imports.Import) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) FactData(org.drools.workbench.models.testscenarios.shared.FactData) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

Example 8 with VerifyFact

use of org.drools.workbench.models.testscenarios.shared.VerifyFact in project drools by kiegroup.

the class FactVerifierTest method testVerifyFactsWithExpression.

@Test
public void testVerifyFactsWithExpression() throws Exception {
    TypeResolver typeResolver = mock(TypeResolver.class);
    Cheese f1 = new Cheese("cheddar", 42);
    f1.setPrice(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("price", "= 40 + 2", "=="));
    factVerifier.verify(vf);
    assertTrue(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 9 with VerifyFact

use of org.drools.workbench.models.testscenarios.shared.VerifyFact in project drools by kiegroup.

the class FactVerifierTest method testVerifyFieldAndActualIsNull.

@Test
public void testVerifyFieldAndActualIsNull() 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 [] expected [boo].", vfl.getExplanation());
    assertEquals("boo", vfl.getExpected());
    assertEquals("", vfl.getActualResult());
}
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 10 with VerifyFact

use of org.drools.workbench.models.testscenarios.shared.VerifyFact 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());
}
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)

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