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;
}
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());
}
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());
}
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());
}
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());
}
Aggregations