use of org.activityinfo.model.form.TFormClass in project activityinfo by bedatadriven.
the class XPathBuilderTest method containsAny.
@Test
public void containsAny() {
TFormClass formClass = createFormClass();
ResourceId male = formClass.getEnumValueByLabel("Male").getId();
ResourceId female = formClass.getEnumValueByLabel("Female").getId();
formClass.getFormClass().getField(GENDER_FIELD_ID).setRelevanceConditionExpression(String.format("containsAny({%s},{%s})", GENDER_FIELD_ID.asString(), male.asString()));
XForm xForm = xForm(formClass.getFormClass());
assertEquals(bindByFieldId(GENDER_FIELD_ID, xForm).getRelevant(), String.format("selected(/data/field_%s, '%s')", GENDER_FIELD_ID.asString(), male.asString()));
formClass.getFormClass().getField(GENDER_FIELD_ID).setRelevanceConditionExpression(String.format("containsAny({%s},{%s},{%s})", GENDER_FIELD_ID.asString(), male.asString(), female.asString()));
xForm = xForm(formClass.getFormClass());
assertEquals(bindByFieldId(GENDER_FIELD_ID, xForm).getRelevant(), String.format("selected(/data/field_%s, '%s') or selected(/data/field_%s, '%s')", GENDER_FIELD_ID.asString(), male.asString(), GENDER_FIELD_ID.asString(), female.asString()));
}
use of org.activityinfo.model.form.TFormClass in project activityinfo by bedatadriven.
the class XPathBuilderTest method equals.
@Test
public void equals() {
TFormClass formClass = createFormClass();
ResourceId male = formClass.getEnumValueByLabel("Male").getId();
formClass.getFormClass().getField(GENDER_FIELD_ID).setRelevanceConditionExpression(String.format("{%s}==\"%s\"", GENDER_FIELD_ID.asString(), male.asString()));
XForm xForm = xForm(formClass.getFormClass());
assertEquals(bindByFieldId(GENDER_FIELD_ID, xForm).getRelevant(), String.format("selected(/data/field_%s, '%s')", GENDER_FIELD_ID.asString(), male.asString()));
}
use of org.activityinfo.model.form.TFormClass in project activityinfo by bedatadriven.
the class XPathBuilderTest method createFormClass.
private static TFormClass createFormClass() {
EnumItem male = new EnumItem(ResourceId.generateId(), "Male");
EnumItem female = new EnumItem(ResourceId.generateId(), "Female");
EnumItem pregnantYes = new EnumItem(ResourceId.generateId(), "Yes");
EnumItem pregnantNo = new EnumItem(ResourceId.generateId(), "No");
FormField genderField = new FormField(GENDER_FIELD_ID);
genderField.setLabel("Gender");
genderField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(male, female)));
FormField pregnantField = new FormField(PREGNANT_FIELD_ID);
pregnantField.setLabel("are you currently pregnant?");
pregnantField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(pregnantYes, pregnantNo)));
FormField textField = new FormField(TEXT_FIELD_ID);
textField.setLabel("Text");
textField.setType(TextType.SIMPLE);
FormField quantityField = new FormField(QUANTITY_FIELD_ID);
quantityField.setLabel("Quantity");
quantityField.setType(QuantityType.TYPE_CLASS.createType());
final FormClass formClass = new FormClass(CuidAdapter.activityFormClass(1));
formClass.addElement(genderField);
formClass.addElement(pregnantField);
formClass.addElement(textField);
formClass.addElement(quantityField);
return new TFormClass(formClass);
}
use of org.activityinfo.model.form.TFormClass in project activityinfo by bedatadriven.
the class XPathBuilderTest method containsAll.
@Test
public void containsAll() {
TFormClass formClass = createFormClass();
ResourceId male = formClass.getEnumValueByLabel("Male").getId();
ResourceId female = formClass.getEnumValueByLabel("Female").getId();
formClass.getFormClass().getField(GENDER_FIELD_ID).setRelevanceConditionExpression(String.format("containsAll({%s},{%s})", GENDER_FIELD_ID.asString(), male.asString()));
XForm xForm = xForm(formClass.getFormClass());
assertEquals(bindByFieldId(GENDER_FIELD_ID, xForm).getRelevant(), String.format("selected(/data/field_%s, '%s')", GENDER_FIELD_ID.asString(), male.asString()));
formClass.getFormClass().getField(GENDER_FIELD_ID).setRelevanceConditionExpression(String.format("containsAll({%s},{%s},{%s})", GENDER_FIELD_ID.asString(), male.asString(), female.asString()));
xForm = xForm(formClass.getFormClass());
assertEquals(bindByFieldId(GENDER_FIELD_ID, xForm).getRelevant(), String.format("selected(/data/field_%s, '%s') and selected(/data/field_%s, '%s')", GENDER_FIELD_ID.asString(), male.asString(), GENDER_FIELD_ID.asString(), female.asString()));
}
Aggregations