Search in sources :

Example 11 with FieldDto

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

the class DefaultCsvExportCustomizerTest method shouldFormatRelationships.

@Test
public void shouldFormatRelationships() {
    // these two relationship types should be handled the same way
    for (Class clazz : asList(OneToOneRelationship.class, ManyToOneRelationship.class)) {
        FieldDto relField = FieldTestHelper.fieldDto("name", clazz);
        assertEquals("something", exportCustomizer.formatField(relField, new UIRepresentationTestClass(1, "something")));
        assertEquals("something", exportCustomizer.formatField(relField, new ToStringTestClass(1, "something")));
        assertEquals("4", exportCustomizer.formatField(relField, new NoToString(4)));
        assertEquals("", exportCustomizer.formatField(relField, null));
    }
    // these two as well
    for (Class clazz : asList(OneToManyRelationship.class, ManyToManyRelationship.class)) {
        FieldDto relField = FieldTestHelper.fieldDto("name", clazz);
        assertEquals("first,second", exportCustomizer.formatField(relField, asList(new UIRepresentationTestClass(1, "first"), new UIRepresentationTestClass(2, "second"))));
        assertEquals("first,second", exportCustomizer.formatField(relField, asList(new ToStringTestClass(1, "first"), new ToStringTestClass(2, "second"))));
        assertEquals("7,8", exportCustomizer.formatField(relField, asList(new NoToString(7), new NoToString(8))));
        assertEquals("", exportCustomizer.formatField(relField, null));
        assertEquals("", exportCustomizer.formatField(relField, Collections.emptySet()));
    }
}
Also used : NoToString(org.motechproject.mds.testutil.records.display.NoToString) UIRepresentationTestClass(org.motechproject.mds.testutil.records.display.UIRepresentationTestClass) ToStringTestClass(org.motechproject.mds.testutil.records.display.ToStringTestClass) UIRepresentationTestClass(org.motechproject.mds.testutil.records.display.UIRepresentationTestClass) ToStringTestClass(org.motechproject.mds.testutil.records.display.ToStringTestClass) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 12 with FieldDto

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

the class DefaultCsvExportCustomizerTest method shouldFormatComboboxFields.

@Test
public void shouldFormatComboboxFields() {
    FieldDto cbField = FieldTestHelper.comboboxFieldDto("cbSingleNonUS", false, false, DisplayTestEnum.valuesMap());
    assertEquals("Monday", exportCustomizer.formatField(cbField, DisplayTestEnum.MONDAY));
    assertEquals("", exportCustomizer.formatField(cbField, null));
    cbField = FieldTestHelper.comboboxFieldDto("cbSingleUS", false, true, null);
    assertEquals("something", exportCustomizer.formatField(cbField, "something"));
    assertEquals("", exportCustomizer.formatField(cbField, null));
    cbField = FieldTestHelper.comboboxFieldDto("cbMultiNonUS", true, false, DisplayTestEnum.valuesMap());
    assertEquals("Wednesday,Monday", exportCustomizer.formatField(cbField, asList(DisplayTestEnum.WEDNESDAY, DisplayTestEnum.MONDAY)));
    assertEquals("", exportCustomizer.formatField(cbField, null));
    assertEquals("", exportCustomizer.formatField(cbField, emptyList()));
    cbField = FieldTestHelper.comboboxFieldDto("cbMultiUS", true, true, "one,two,three");
    assertEquals("test1,test2", exportCustomizer.formatField(cbField, asList("test1", "test2")));
    assertEquals("", exportCustomizer.formatField(cbField, emptyList()));
    assertEquals("", exportCustomizer.formatField(cbField, null));
}
Also used : FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 13 with FieldDto

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

the class DefaultCsvExportCustomizerTest method shouldFormatRegularFields.

@Test
public void shouldFormatRegularFields() {
    FieldDto strField = FieldTestHelper.fieldDto("name", String.class);
    assertEquals("test string", exportCustomizer.formatField(strField, "test string"));
    FieldDto intField = FieldTestHelper.fieldDto("name", Integer.class);
    assertEquals("20", exportCustomizer.formatField(intField, 20));
    FieldDto lcField = FieldTestHelper.fieldDto("name", Locale.class);
    assertEquals(Locale.ENGLISH.toString(), exportCustomizer.formatField(lcField, Locale.ENGLISH));
    final DateTime now = DateUtil.now();
    FieldDto dtField = FieldTestHelper.fieldDto("name", DateTime.class);
    assertEquals(now.toString(), exportCustomizer.formatField(dtField, now));
    final LocalDate today = DateUtil.today();
    FieldDto ldField = FieldTestHelper.fieldDto("name", LocalDate.class);
    assertEquals(today.toString(), exportCustomizer.formatField(ldField, today));
}
Also used : LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 14 with FieldDto

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

the class FieldTestHelper method requiredFieldDto.

public static FieldDto requiredFieldDto(Long id, String name, Class clazz) {
    FieldDto field = fieldDto(id, name, clazz);
    field.getBasic().setRequired(true);
    return field;
}
Also used : FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Example 15 with FieldDto

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

the class DefaultCsvImportCustomizerTest method setUp.

@Before
public void setUp() {
    fields = new ArrayList<>();
    field1 = new FieldDto("name", "Display Name", TypeDto.STRING);
    field2 = new FieldDto("name2", "Display Name 2", TypeDto.STRING);
    field3 = new FieldDto("name3", "Display Name 3", TypeDto.STRING);
    field4 = new FieldDto("DisplayName", "Display Name 4", TypeDto.STRING);
    fields.add(field1);
    fields.add(field2);
    fields.add(field3);
    fields.add(field4);
}
Also used : FieldDto(org.motechproject.mds.dto.FieldDto) Before(org.junit.Before)

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