use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class FieldProcessorTest method shouldProcessComboboxFields.
@Test
public void shouldProcessComboboxFields() throws NoSuchFieldException {
processor.process(Sample.class.getDeclaredField("enumSet"));
processor.process(Sample.class.getDeclaredField("stringSet"));
Collection<FieldDto> fields = processor.getElements();
assertEquals(2, fields.size());
FieldDto field = findFieldWithName(fields, "enumSet");
assertEquals(2, field.getMetadata().size());
assertEquals(Set.class.getName(), field.getMetadata(Constants.MetadataKeys.ENUM_COLLECTION_TYPE).getValue());
assertEquals("org.motechproject.mds.annotations.internal.samples.Sample$TestEnum", field.getMetadata(Constants.MetadataKeys.ENUM_CLASS_NAME).getValue());
assertEquals(3, field.getSettings().size());
assertTrue(Boolean.parseBoolean(field.getSettingsValueAsString(Constants.Settings.ALLOW_MULTIPLE_SELECTIONS)));
assertFalse(Boolean.parseBoolean(field.getSettingsValueAsString(Constants.Settings.ALLOW_USER_SUPPLIED)));
assertEquals("{ONE=one, TWO=two, THREE=three}", field.getSettingsValueAsString(Constants.Settings.COMBOBOX_VALUES));
field = findFieldWithName(fields, "stringSet");
assertEquals(1, field.getMetadata().size());
assertEquals(Set.class.getName(), field.getMetadata(Constants.MetadataKeys.ENUM_COLLECTION_TYPE).getValue());
assertEquals(3, field.getSettings().size());
assertTrue(Boolean.parseBoolean(field.getSettingsValueAsString(Constants.Settings.ALLOW_MULTIPLE_SELECTIONS)));
assertTrue(Boolean.parseBoolean(field.getSettingsValueAsString(Constants.Settings.ALLOW_USER_SUPPLIED)));
assertEquals("{}", field.getSettingsValueAsString(Constants.Settings.COMBOBOX_VALUES));
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class FieldProcessorTest method shouldProcessField.
@Test
public void shouldProcessField() throws Exception {
java.lang.reflect.Field world = getDeclaredField(Sample.class, "world", true);
processor.process(world);
verify(schemaHolder).getType(Boolean.class);
Collection<FieldDto> fields = processor.getElements();
assertEquals(1, fields.size());
FieldDto field = fields.iterator().next();
assertEquals(entity.getId(), field.getEntityId());
assertEquals("World", field.getBasic().getDisplayName());
assertEquals(world.getName(), field.getBasic().getName());
assertFalse(field.getBasic().isRequired());
assertEquals("", field.getBasic().getDefaultValue());
assertEquals("", field.getBasic().getTooltip());
assertEquals("", field.getBasic().getPlaceholder());
assertEquals(entity.getId(), field.getEntityId());
assertEquals(TypeDto.BOOLEAN, field.getType());
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class FieldProcessorTest method shouldRecognizeUniqueFields.
@Test
public void shouldRecognizeUniqueFields() throws NoSuchFieldException {
processor.process(Sample.class.getDeclaredField("unique"));
Collection<FieldDto> fields = processor.getElements();
assertEquals(1, fields.size());
FieldDto field = fields.iterator().next();
assertNotNull(field);
assertEquals("unique", field.getBasic().getName());
assertTrue(field.getBasic().isUnique());
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class FieldProcessorTest method shouldProcessComboboxFieldsForSingleEnumInstance.
@Test
public void shouldProcessComboboxFieldsForSingleEnumInstance() throws NoSuchFieldException {
processor.process(Sample.class.getDeclaredField("singleEnum"));
Collection<FieldDto> fields = processor.getElements();
assertEquals(1, fields.size());
FieldDto field = findFieldWithName(fields, "singleEnum");
assertEquals(1, field.getMetadata().size());
assertEquals("org.motechproject.mds.annotations.internal.samples.Sample$TestEnum", field.getMetadata(Constants.MetadataKeys.ENUM_CLASS_NAME).getValue());
assertEquals(3, field.getSettings().size());
assertFalse(Boolean.parseBoolean(field.getSettingsValueAsString(Constants.Settings.ALLOW_MULTIPLE_SELECTIONS)));
assertFalse(Boolean.parseBoolean(field.getSettingsValueAsString(Constants.Settings.ALLOW_USER_SUPPLIED)));
assertEquals("{ONE=one, TWO=two, THREE=three}", field.getSettingsValueAsString(Constants.Settings.COMBOBOX_VALUES));
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class LookupProcessorTest method shouldBreakProcessingWhenEntityNotFound.
@Test
public void shouldBreakProcessingWhenEntityNotFound() throws NoSuchMethodException {
when(paranamer.lookupParameterNames(getTestMethod(4))).thenReturn(argNames);
EntityProcessorOutput eop = mockEntityProcessorOutput(new EntityDto(TestClass.class.getName()), Arrays.asList(new FieldDto("aaa", "bbb", TypeDto.STRING)));
lookupProcessor.setEntityProcessingResult(Arrays.asList(eop));
Method method = getTestMethod(4);
lookupProcessor.process(method);
assertTrue(lookupProcessor.getProcessingResult().isEmpty());
}
Aggregations