use of org.drools.workbench.models.testscenarios.shared.FactData 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.FactData 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.FactData in project drools-wb by kiegroup.
the class TestScenarioIndexVisitor method visit.
private void visit(final Fixture fixture) {
if (fixture instanceof FixtureList) {
for (Fixture child : ((FixtureList) fixture)) {
visit(child);
}
} else if (fixture instanceof FixturesMap) {
for (Fixture child : ((FixturesMap) fixture).values()) {
visit(child);
}
} else if (fixture instanceof FactData) {
final FactData factData = (FactData) fixture;
final String typeName = factData.getType();
final String fullyQualifiedClassName = getFullyQualifiedClassName(typeName);
ResourceReference resRef = addResourceReference(fullyQualifiedClassName, ResourceType.JAVA);
factDataToFullyQualifiedClassNameMap.put(factData.getName(), fullyQualifiedClassName);
for (Field field : factData.getFieldData()) {
final String fieldName = field.getName();
final String fieldFullyQualifiedClassName = getFieldFullyQualifiedClassName(fullyQualifiedClassName, fieldName);
resRef.addPartReference(fieldName, PartType.FIELD);
addResourceReference(fieldFullyQualifiedClassName, ResourceType.JAVA);
}
} else if (fixture instanceof VerifyFact) {
final VerifyFact verifyFact = (VerifyFact) fixture;
final String typeName = verifyFact.getName();
// If VerifyFact is not anonymous lookup FQCN from previous FactData elements
String fullyQualifiedClassName = null;
if (!verifyFact.anonymous) {
fullyQualifiedClassName = factDataToFullyQualifiedClassNameMap.get(verifyFact.getName());
} else {
fullyQualifiedClassName = getFullyQualifiedClassName(typeName);
}
ResourceReference resRef = null;
if (fullyQualifiedClassName != null) {
resRef = addResourceReference(fullyQualifiedClassName, ResourceType.JAVA);
for (VerifyField field : verifyFact.getFieldValues()) {
final String fieldName = field.getFieldName();
final String fieldFullyQualifiedClassName = getFieldFullyQualifiedClassName(fullyQualifiedClassName, fieldName);
resRef.addPartReference(fieldName, PartType.FIELD);
addResourceReference(fieldFullyQualifiedClassName, ResourceType.JAVA);
}
}
} else if (fixture instanceof VerifyRuleFired) {
final VerifyRuleFired verifyRuleFired = (VerifyRuleFired) fixture;
addResourceReference(verifyRuleFired.getRuleName(), ResourceType.RULE);
}
}
use of org.drools.workbench.models.testscenarios.shared.FactData in project drools-wb by kiegroup.
the class VerifyFieldConstraintEditor method variableEditor.
private Widget variableEditor() {
List<String> vars = this.scenario.getFactNamesInScope(this.executionTrace, true);
final ListBox box = new ListBox();
if (this.field.getExpected() == null) {
box.addItem(CommonConstants.INSTANCE.Choose());
}
int j = 0;
for (int i = 0; i < vars.size(); i++) {
String var = vars.get(i);
FactData f = scenario.getFactTypes().get(var);
String fieldType = oracle.getFieldType(this.factType, field.getFieldName());
if (f.getType().equals(fieldType)) {
if (box.getItemCount() == 0) {
box.addItem("...");
j++;
}
box.addItem("=" + var);
if (this.field.getExpected() != null && this.field.getExpected().equals("=" + var)) {
box.setSelectedIndex(j);
}
j++;
}
}
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
field.setExpected(box.getItemText(box.getSelectedIndex()));
}
});
return box;
}
use of org.drools.workbench.models.testscenarios.shared.FactData 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;
}
Aggregations