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