Search in sources :

Example 56 with FieldDto

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));
}
Also used : InSet(org.motechproject.mds.annotations.InSet) Set(java.util.Set) NotInSet(org.motechproject.mds.annotations.NotInSet) Sample(org.motechproject.mds.annotations.internal.samples.Sample) RelatedSample(org.motechproject.mds.annotations.internal.samples.RelatedSample) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 57 with FieldDto

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());
}
Also used : FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 58 with FieldDto

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());
}
Also used : Sample(org.motechproject.mds.annotations.internal.samples.Sample) RelatedSample(org.motechproject.mds.annotations.internal.samples.RelatedSample) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 59 with FieldDto

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));
}
Also used : Sample(org.motechproject.mds.annotations.internal.samples.Sample) RelatedSample(org.motechproject.mds.annotations.internal.samples.RelatedSample) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 60 with FieldDto

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());
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Method(java.lang.reflect.Method) FieldTestHelper.lookupFieldDto(org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) 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