Search in sources :

Example 6 with TypeResolver

use of org.kie.soup.project.datamodel.commons.types.TypeResolver in project drools by kiegroup.

the class FactPopulatorTest method getTypeResolver.

private TypeResolver getTypeResolver() {
    TypeResolver resolver = new ClassTypeResolver(new HashSet<String>(), getClassLoader());
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.MyCollectionWrapper");
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.Cheesery");
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.Cheese");
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.SqlDateWrapper");
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.CheeseType");
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.Person");
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.OuterFact");
    return resolver;
}
Also used : ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)

Example 7 with TypeResolver

use of org.kie.soup.project.datamodel.commons.types.TypeResolver in project drools by kiegroup.

the class GlobalFactPopulatorTest method testWithGlobals.

@Test
public void testWithGlobals() throws Exception {
    FactData global = new FactData("Cheese", "c", Arrays.<Field>asList(new FieldData("type", "cheddar")), false);
    TypeResolver resolver = new ClassTypeResolver(new HashSet<String>(), Thread.currentThread().getContextClassLoader());
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.Cheese");
    KieSession ksession = mock(KieSession.class);
    Map<String, Object> populatedData = new HashMap<String, Object>();
    Map<String, Object> globalData = new HashMap<String, Object>();
    GlobalFactPopulator globalFactPopulator = new GlobalFactPopulator(populatedData, resolver, global, globalData);
    globalFactPopulator.populate(ksession, new HashMap<String, FactHandle>());
    verify(ksession).setGlobal(eq(global.getName()), any(Object.class));
    assertEquals(1, globalData.size());
    assertEquals(0, populatedData.size());
}
Also used : HashMap(java.util.HashMap) FactHandle(org.kie.api.runtime.rule.FactHandle) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactData(org.drools.workbench.models.testscenarios.shared.FactData) KieSession(org.kie.api.runtime.KieSession) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) Test(org.junit.Test)

Example 8 with TypeResolver

use of org.kie.soup.project.datamodel.commons.types.TypeResolver in project drools by kiegroup.

the class FactFieldValueVerifierTest method testSQLDate.

public void testSQLDate() throws Exception {
    SqlDateWrapper sqlDateWrapper = new SqlDateWrapper();
    sqlDateWrapper.setSqlDate(new Date(2012 - 1900, 11, 12));
    HashMap<String, Object> populatedData = new HashMap<String, Object>();
    populatedData.put("sqlDateWrapper", sqlDateWrapper);
    TypeResolver typeResolver = mock(TypeResolver.class);
    FactFieldValueVerifier verifier = new FactFieldValueVerifier(populatedData, "sqlDateWrapper", sqlDateWrapper, typeResolver);
    List<VerifyField> fieldValues = new ArrayList<VerifyField>();
    VerifyField verifyField = new VerifyField("sqlDate", "12-DEC-2012", "==");
    fieldValues.add(verifyField);
    verifier.checkFields(fieldValues);
    assertTrue(verifyField.getSuccessResult());
}
Also used : HashMap(java.util.HashMap) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) ArrayList(java.util.ArrayList) SqlDateWrapper(org.drools.workbench.models.testscenarios.backend.SqlDateWrapper) Date(java.sql.Date)

Example 9 with TypeResolver

use of org.kie.soup.project.datamodel.commons.types.TypeResolver 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 10 with TypeResolver

use of org.kie.soup.project.datamodel.commons.types.TypeResolver 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)

Aggregations

TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)24 Test (org.junit.Test)16 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)14 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)8 Cheese (org.drools.workbench.models.testscenarios.backend.Cheese)7 FactData (org.drools.workbench.models.testscenarios.shared.FactData)7 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)7 HashMap (java.util.HashMap)6 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)6 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 CollectionFieldData (org.drools.workbench.models.testscenarios.shared.CollectionFieldData)5 Field (org.drools.workbench.models.testscenarios.shared.Field)4 HashSet (java.util.HashSet)3 FactAssignmentField (org.drools.workbench.models.testscenarios.shared.FactAssignmentField)3 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)2 Cheesery (org.drools.workbench.models.testscenarios.backend.Cheesery)2 Mouse (org.drools.workbench.models.testscenarios.backend.Mouse)2 OuterFact (org.drools.workbench.models.testscenarios.backend.OuterFact)2 KieSession (org.kie.api.runtime.KieSession)2