Search in sources :

Example 1 with TFormClass

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()));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) XForm(org.activityinfo.io.xform.form.XForm) TFormClass(org.activityinfo.model.form.TFormClass) Test(org.junit.Test)

Example 2 with TFormClass

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()));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) XForm(org.activityinfo.io.xform.form.XForm) TFormClass(org.activityinfo.model.form.TFormClass) Test(org.junit.Test)

Example 3 with TFormClass

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);
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) FormClass(org.activityinfo.model.form.FormClass) TFormClass(org.activityinfo.model.form.TFormClass) TFormClass(org.activityinfo.model.form.TFormClass) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) FormField(org.activityinfo.model.form.FormField)

Example 4 with TFormClass

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()));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) XForm(org.activityinfo.io.xform.form.XForm) TFormClass(org.activityinfo.model.form.TFormClass) Test(org.junit.Test)

Aggregations

TFormClass (org.activityinfo.model.form.TFormClass)4 XForm (org.activityinfo.io.xform.form.XForm)3 ResourceId (org.activityinfo.model.resource.ResourceId)3 Test (org.junit.Test)3 FormClass (org.activityinfo.model.form.FormClass)1 FormField (org.activityinfo.model.form.FormField)1 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)1 EnumType (org.activityinfo.model.type.enumerated.EnumType)1