use of org.drools.workbench.models.testscenarios.shared.FieldData in project drools by kiegroup.
the class FactPopulatorTest method testPopulatingExistingFact.
@Test
public void testPopulatingExistingFact() throws Exception {
Cheese cheese = new Cheese();
cheese.setType("whee");
cheese.setPrice(1);
Map<String, Object> populatedData = new HashMap<String, Object>();
populatedData.put("x", cheese);
factPopulator.add(new ExistingFactPopulator(populatedData, getTypeResolver(), new FactData("Cheese", "x", Arrays.<Field>asList(new FieldData("type", null), new FieldData("price", "42")), false)));
factPopulator.populate();
assertEquals("whee", cheese.getType());
assertEquals(42, cheese.getPrice());
}
use of org.drools.workbench.models.testscenarios.shared.FieldData in project drools by kiegroup.
the class FactPopulatorTest method testPopulateFactsWithExpressions.
@Test
public void testPopulateFactsWithExpressions() throws Exception {
factPopulator.add(new NewFactPopulator(populatedData, getTypeResolver(), new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("type", "cheddar"), new FieldData("price", "42")), false)));
factPopulator.add(new NewFactPopulator(populatedData, getTypeResolver(), new FactData("Cheese", "c2", Arrays.<Field>asList(new FieldData("type", "= c1.type")), false)));
factPopulator.populate();
assertTrue(populatedData.containsKey("c1"));
assertTrue(populatedData.containsKey("c2"));
Cheese c = (Cheese) populatedData.get("c1");
assertEquals("cheddar", c.getType());
assertEquals(42, c.getPrice());
Cheese c2 = (Cheese) populatedData.get("c2");
assertEquals(c.getType(), c2.getType());
}
use of org.drools.workbench.models.testscenarios.shared.FieldData 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.drools.workbench.models.testscenarios.shared.FieldData in project drools-wb by kiegroup.
the class TestScenarioFactory method makeTestScenarioWithVerifyFact.
public static Scenario makeTestScenarioWithVerifyFact(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.getFixtures().add(new FactData("Applicant", "$a", new ArrayList<Field>() {
{
add(new FieldData("age", "33"));
}
}, false));
model.getFixtures().add(new VerifyFact("Mortgage", new ArrayList<VerifyField>() {
{
add(new VerifyField("amount", "10000", "=="));
}
}, true));
return model;
}
use of org.drools.workbench.models.testscenarios.shared.FieldData in project drools-wb by kiegroup.
the class TestScenarioFactory method makeTestScenarioWithoutVerifyFact.
public static Scenario makeTestScenarioWithoutVerifyFact(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.getFixtures().add(new FactData("Applicant", "$a", new ArrayList<Field>() {
{
add(new FieldData("age", "33"));
}
}, false));
return model;
}
Aggregations