Search in sources :

Example 6 with FieldBasicDto

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

the class EntityServiceContextIT method shouldNotAddFieldsWithTheSameNameToAnEntity.

@Test
public void shouldNotAddFieldsWithTheSameNameToAnEntity() throws IOException {
    EntityDto entityDto = new EntityDto();
    entityDto.setName("SameFieldTest");
    entityDto = entityService.createEntity(entityDto);
    FieldDto field1 = new FieldDto();
    field1.setBasic(new FieldBasicDto("disp", "name"));
    field1.setType(typeService.findType(Boolean.class));
    FieldDto field2 = new FieldDto();
    field2.setBasic(new FieldBasicDto("dispName2", "name"));
    field2.setType(typeService.findType(Integer.class));
    entityService.addFields(entityDto, asList(field1, field2));
    List<FieldDto> fieldsFromDb = entityService.getFields(entityDto.getId());
    assertNotNull(fieldsFromDb);
    assertEquals(7, fieldsFromDb.size());
    assertEquals(asList("Id", "Created By", "Owner", "Modified By", "Creation Date", "Modification Date", "dispName2"), extract(fieldsFromDb, on(FieldDto.class).getBasic().getDisplayName()));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 7 with FieldBasicDto

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

the class FieldHelperTest method fieldDto.

private FieldDto fieldDto() {
    TypeDto type = new TypeDto("typeDispName", "typeDesc", "typeDefaultName", "typeClass");
    FieldBasicDto basic = new FieldBasicDto("fieldDispName", "fieldName", true, false, "defVal", "tooltip", "placeholder");
    MetadataDto metadata = new MetadataDto("key", "val");
    ValidationCriterionDto criterion = new ValidationCriterionDto("criterionDispName", type);
    FieldValidationDto validation = new FieldValidationDto(criterion);
    return new FieldDto(1L, 100L, type, basic, false, new ArrayList<>(asList(metadata)), validation, null, null);
}
Also used : FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) ValidationCriterionDto(org.motechproject.mds.dto.ValidationCriterionDto) FieldValidationDto(org.motechproject.mds.dto.FieldValidationDto) TypeDto(org.motechproject.mds.dto.TypeDto) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 8 with FieldBasicDto

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

the class FieldTestHelper method fieldDto.

public static FieldDto fieldDto(Long id, String name, String className, String displayName, Object defValue) {
    FieldDto fieldDto = new FieldDto();
    fieldDto.setType(new TypeDto(className, "", "", className));
    fieldDto.setBasic(new FieldBasicDto(displayName, name));
    fieldDto.getBasic().setDefaultValue(defValue);
    fieldDto.setId(id);
    return fieldDto;
}
Also used : FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) TypeDto(org.motechproject.mds.dto.TypeDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 9 with FieldBasicDto

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

the class EntityServiceImplTest method shouldAddNewField.

@Test
public void shouldAddNewField() {
    // given
    long entityId = 1L;
    EntityDto dto = new EntityDto(entityId, CLASS_NAME);
    TypeDto type = TypeDto.INTEGER;
    Type integerType = new Type(Integer.class);
    FieldBasicDto basic = new FieldBasicDto();
    basic.setDisplayName("pi");
    basic.setName("pi");
    basic.setRequired(true);
    basic.setDefaultValue("3.14");
    basic.setTooltip("Sets the value of the PI number");
    basic.setPlaceholder("3.14");
    FieldDto fieldDto = new FieldDto();
    fieldDto.setEntityId(dto.getId());
    fieldDto.setType(type);
    fieldDto.setBasic(basic);
    // when
    doReturn(entity).when(allEntities).retrieveById(dto.getId());
    doReturn(entityId).when(entity).getId();
    doReturn(integerType).when(allTypes).retrieveByClassName(type.getTypeClass());
    entityService.addFields(dto, asList(fieldDto));
    // then
    verify(allEntities).retrieveById(dto.getId());
    verify(entity).addField(fieldCaptor.capture());
    Field field = fieldCaptor.getValue();
    assertEquals(basic.getName(), field.getName());
    assertEquals(basic.getDisplayName(), field.getDisplayName());
    assertEquals(basic.isRequired(), field.isRequired());
    assertEquals(basic.getDefaultValue(), field.getDefaultValue());
    assertEquals(basic.getTooltip(), field.getTooltip());
    assertEquals(basic.getPlaceholder(), field.getPlaceholder());
    assertEquals(fieldDto.getType().getTypeClass(), field.getType().getTypeClass().getName());
    assertEquals(fieldDto.getEntityId(), field.getEntity().getId());
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Field(org.motechproject.mds.domain.Field) Type(org.motechproject.mds.domain.Type) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) TypeDto(org.motechproject.mds.dto.TypeDto) FieldTestHelper.lookupFieldDto(org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 10 with FieldBasicDto

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

the class EntityServiceImplTest method shouldUpdateExistingField.

@Test
public void shouldUpdateExistingField() {
    // given
    long entityId = 1L;
    EntityDto dto = new EntityDto(entityId, CLASS_NAME);
    TypeDto type = TypeDto.INTEGER;
    Field field = mock(Field.class);
    FieldBasicDto basic = new FieldBasicDto();
    basic.setDisplayName("pi");
    basic.setName("pi");
    basic.setRequired(true);
    basic.setDefaultValue("3.14");
    basic.setTooltip("Sets the value of the PI number");
    basic.setPlaceholder("3.14");
    FieldDto fieldDto = new FieldDto();
    fieldDto.setEntityId(dto.getId());
    fieldDto.setType(type);
    fieldDto.setBasic(basic);
    // when
    doReturn(entity).when(allEntities).retrieveById(dto.getId());
    doReturn(entityId).when(entity).getId();
    doReturn(field).when(entity).getField(basic.getName());
    entityService.addFields(dto, asList(fieldDto));
    // then
    verify(allEntities).retrieveById(dto.getId());
    verify(entity).getField(basic.getName());
    verify(entity, never()).addField(any(Field.class));
    verify(field).update(fieldDto);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Field(org.motechproject.mds.domain.Field) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) TypeDto(org.motechproject.mds.dto.TypeDto) FieldTestHelper.lookupFieldDto(org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Aggregations

FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)20 FieldDto (org.motechproject.mds.dto.FieldDto)19 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)11 EntityDto (org.motechproject.mds.dto.EntityDto)9 TypeDto (org.motechproject.mds.dto.TypeDto)9 MetadataDto (org.motechproject.mds.dto.MetadataDto)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 LookupDto (org.motechproject.mds.dto.LookupDto)5 LinkedList (java.util.LinkedList)4 SettingDto (org.motechproject.mds.dto.SettingDto)4 Field (org.motechproject.mds.domain.Field)3 FieldValidationDto (org.motechproject.mds.dto.FieldValidationDto)3 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 Type (org.motechproject.mds.domain.Type)2 RestOptionsDto (org.motechproject.mds.dto.RestOptionsDto)2 ValidationCriterionDto (org.motechproject.mds.dto.ValidationCriterionDto)2 FieldTestHelper.lookupFieldDto (org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto)2 ResultActions (org.springframework.test.web.server.ResultActions)2