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()));
}
}
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));
}
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));
}
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;
}
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);
}
Aggregations