Search in sources :

Example 51 with FieldDto

use of org.motechproject.mds.dto.FieldDto in project motech by motech.

the class DisplayHelperTest method shouldDisplayCbSingleSelectUserSupplied.

@Test
public void shouldDisplayCbSingleSelectUserSupplied() {
    FieldDto field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", false, true, null);
    assertEquals("Something", DisplayHelper.getDisplayValueForField(field, "Something"));
    field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", false, true, null);
    assertEquals(null, DisplayHelper.getDisplayValueForField(field, null));
}
Also used : FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 52 with FieldDto

use of org.motechproject.mds.dto.FieldDto in project motech by motech.

the class DisplayHelperTest method shouldDisplayCbSingleSelectNoUserSupplied.

@Test
public void shouldDisplayCbSingleSelectNoUserSupplied() {
    FieldDto field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", false, false, DisplayTestEnum.valuesMap());
    assertEquals("Monday", DisplayHelper.getDisplayValueForField(field, DisplayTestEnum.MONDAY));
    field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", false, false, DisplayTestEnum.valuesMap());
    assertNull(DisplayHelper.getDisplayValueForField(field, null));
    field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", false, false, null);
    assertEquals(DisplayTestEnum.MONDAY, DisplayHelper.getDisplayValueForField(field, DisplayTestEnum.MONDAY));
}
Also used : FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 53 with FieldDto

use of org.motechproject.mds.dto.FieldDto in project motech by motech.

the class DisplayHelperTest method testSingleObjectRelationshipDisplay.

private void testSingleObjectRelationshipDisplay(Class<? extends Relationship> relClass) {
    FieldDto field = FieldTestHelper.fieldDto("relField", relClass);
    assertEquals("Value", DisplayHelper.getDisplayValueForField(field, new ToStringTestClass(1, "Value")));
    assertEquals("Value", DisplayHelper.getDisplayValueForField(field, new UIRepresentationTestClass(1, "Value")));
}
Also used : UIRepresentationTestClass(org.motechproject.mds.testutil.records.display.UIRepresentationTestClass) ToStringTestClass(org.motechproject.mds.testutil.records.display.ToStringTestClass) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 54 with FieldDto

use of org.motechproject.mds.dto.FieldDto in project motech by motech.

the class FieldProcessorTest method shouldAssignFieldValidation.

@Test
public void shouldAssignFieldValidation() throws Exception {
    TypeValidationDto intMinValue = new TypeValidationDto("mds.field.validation.minValue", Integer.class.getName());
    TypeValidationDto intMaxValue = new TypeValidationDto("mds.field.validation.maxValue", Integer.class.getName());
    TypeValidationDto intMustBeInSet = new TypeValidationDto("mds.field.validation.mustBeInSet", String.class.getName());
    TypeValidationDto intCannotBeInSet = new TypeValidationDto("mds.field.validation.cannotBeInSet", String.class.getName());
    TypeValidationDto decMinValue = new TypeValidationDto("mds.field.validation.minValue", Double.class.getName());
    TypeValidationDto decMaxValue = new TypeValidationDto("mds.field.validation.maxValue", Double.class.getName());
    TypeValidationDto decMustBeInSet = new TypeValidationDto("mds.field.validation.mustBeInSet", String.class.getName());
    TypeValidationDto decCannotBeInSet = new TypeValidationDto("mds.field.validation.cannotBeInSet", String.class.getName());
    TypeValidationDto regex = new TypeValidationDto("mds.field.validation.regex", String.class.getName());
    TypeValidationDto minLength = new TypeValidationDto("mds.field.validation.minLength", Integer.class.getName());
    TypeValidationDto maxLength = new TypeValidationDto("mds.field.validation.maxLength", Integer.class.getName());
    doReturn(singletonList(intMinValue)).when(schemaHolder).findValidations(Integer.class.getName(), DecimalMin.class);
    doReturn(singletonList(intMaxValue)).when(schemaHolder).findValidations(Integer.class.getName(), DecimalMax.class);
    doReturn(singletonList(intMustBeInSet)).when(schemaHolder).findValidations(Integer.class.getName(), InSet.class);
    doReturn(singletonList(intCannotBeInSet)).when(schemaHolder).findValidations(Integer.class.getName(), NotInSet.class);
    doReturn(singletonList(intMinValue)).when(schemaHolder).findValidations(Integer.class.getName(), Min.class);
    doReturn(singletonList(intMaxValue)).when(schemaHolder).findValidations(Integer.class.getName(), Max.class);
    doReturn(singletonList(decMinValue)).when(schemaHolder).findValidations(Double.class.getName(), DecimalMin.class);
    doReturn(singletonList(decMaxValue)).when(schemaHolder).findValidations(Double.class.getName(), DecimalMax.class);
    doReturn(singletonList(decMustBeInSet)).when(schemaHolder).findValidations(Double.class.getName(), InSet.class);
    doReturn(singletonList(decCannotBeInSet)).when(schemaHolder).findValidations(Double.class.getName(), NotInSet.class);
    doReturn(singletonList(decMinValue)).when(schemaHolder).findValidations(Double.class.getName(), Min.class);
    doReturn(singletonList(decMaxValue)).when(schemaHolder).findValidations(Double.class.getName(), Max.class);
    doReturn(singletonList(regex)).when(schemaHolder).findValidations(String.class.getName(), Pattern.class);
    doReturn(asList(minLength, maxLength)).when(schemaHolder).findValidations(String.class.getName(), Size.class);
    doReturn(singletonList(minLength)).when(schemaHolder).findValidations(String.class.getName(), DecimalMin.class);
    doReturn(singletonList(maxLength)).when(schemaHolder).findValidations(String.class.getName(), DecimalMax.class);
    processor.execute(bundle, schemaHolder);
    Collection<FieldDto> fields = processor.getElements();
    FieldDto pi = findFieldWithName(fields, "pi");
    assertCriterion(pi, "mds.field.validation.minValue", "3");
    assertCriterion(pi, "mds.field.validation.maxValue", "4");
    assertCriterion(pi, "mds.field.validation.mustBeInSet", "3,3.14,4");
    assertCriterion(pi, "mds.field.validation.cannotBeInSet", "1,2,5");
    FieldDto epsilon = findFieldWithName(fields, "epsilon");
    assertCriterion(epsilon, "mds.field.validation.minValue", "0.0");
    assertCriterion(epsilon, "mds.field.validation.maxValue", "1.0");
    assertCriterion(epsilon, "mds.field.validation.mustBeInSet", "1,0.75,0.5,0.25,0");
    assertCriterion(epsilon, "mds.field.validation.cannotBeInSet", "-1,2,3");
    FieldDto random = findFieldWithName(fields, "random");
    assertCriterion(random, "mds.field.validation.minValue", "0");
    assertCriterion(random, "mds.field.validation.maxValue", "10");
    FieldDto gaussian = findFieldWithName(fields, "gaussian");
    assertCriterion(gaussian, "mds.field.validation.minValue", "0.0");
    assertCriterion(gaussian, "mds.field.validation.maxValue", "1.0");
    FieldDto poem = findFieldWithName(fields, "poem");
    assertCriterion(poem, "mds.field.validation.regex", "[A-Z][a-z]{9}");
    assertCriterion(poem, "mds.field.validation.minLength", "10");
    assertCriterion(poem, "mds.field.validation.maxLength", "20");
    FieldDto article = findFieldWithName(fields, "article");
    assertCriterion(article, "mds.field.validation.minLength", "100");
    assertCriterion(article, "mds.field.validation.maxLength", "500");
}
Also used : TypeValidationDto(org.motechproject.mds.dto.TypeValidationDto) Matchers.anyString(org.mockito.Matchers.anyString) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 55 with FieldDto

use of org.motechproject.mds.dto.FieldDto in project motech by motech.

the class FieldProcessorTest method shouldNotProcessPublicFieldWithIgnoreAnnotation.

@Test
public void shouldNotProcessPublicFieldWithIgnoreAnnotation() {
    AnnotatedElement ignored = getDeclaredField(Sample.class, "ignored", true);
    processor.process(ignored);
    Collection<FieldDto> fields = processor.getElements();
    assertEquals(1, fields.size());
    List<AnnotatedElement> actual = new ArrayList<>();
    actual.addAll(processor.getElementsToProcess());
    assertEquals(Sample.FIELD_COUNT, actual.size());
    assertFalse(actual.contains(ignored));
}
Also used : AnnotatedElement(java.lang.reflect.AnnotatedElement) ArrayList(java.util.ArrayList) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Aggregations

FieldDto (org.motechproject.mds.dto.FieldDto)158 Test (org.junit.Test)61 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)60 EntityDto (org.motechproject.mds.dto.EntityDto)53 ArrayList (java.util.ArrayList)47 LookupDto (org.motechproject.mds.dto.LookupDto)29 List (java.util.List)23 MetadataDto (org.motechproject.mds.dto.MetadataDto)22 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)19 TypeDto (org.motechproject.mds.dto.TypeDto)17 Method (java.lang.reflect.Method)14 MotechDataService (org.motechproject.mds.service.MotechDataService)14 HashMap (java.util.HashMap)12 Field (org.motechproject.mds.domain.Field)12 FieldTestHelper.lookupFieldDto (org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto)12 Arrays.asList (java.util.Arrays.asList)11 SettingDto (org.motechproject.mds.dto.SettingDto)11 Before (org.junit.Before)7 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)7 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)7