use of org.motechproject.mds.dto.TypeDto in project motech by motech.
the class TypeMatcherTest method matchTypes.
private void matchTypes(String term, int matchedCount, int noMatchedCount) {
TypeMatcher matcher = new TypeMatcher(term, messageSource);
int falseCout = 0;
int trueCount = 0;
for (TypeDto entity : TYPES) {
if (matcher.evaluate(entity)) {
++trueCount;
} else {
++falseCout;
}
}
assertEquals("The number of matched types is incorrect", matchedCount, trueCount);
assertEquals("The number of no matched types is incorrect", noMatchedCount, falseCout);
}
use of org.motechproject.mds.dto.TypeDto in project motech by motech.
the class LookupProcessor method setUseGenericParam.
private void setUseGenericParam(EntityDto entity, Class<?> methodParameterType, LookupFieldDto lookupField) {
FieldDto field = findEntityFieldByName(entity.getClassName(), lookupField.getName());
TypeDto fieldType = field.getType();
EntityDto relatedEntity = null;
if (fieldType.isRelationship()) {
relatedEntity = findEntityByClassName(field.getMetadata(Constants.MetadataKeys.RELATED_CLASS).getValue());
field = findEntityFieldByName(field.getMetadata(Constants.MetadataKeys.RELATED_CLASS).getValue(), lookupField.getRelatedName());
}
if (fieldType.isCombobox()) {
ComboboxHolder holder = new ComboboxHolder(relatedEntity == null ? entity : relatedEntity, field);
boolean isCollection = holder.isCollection();
boolean isCollectionParam = Collection.class.isAssignableFrom(methodParameterType);
lookupField.setUseGenericParam(isCollection && !isCollectionParam);
}
}
use of org.motechproject.mds.dto.TypeDto 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.TypeDto 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);
}
use of org.motechproject.mds.dto.TypeDto in project motech by motech.
the class TypeServiceImplContextIT method testFindType.
private void testFindType(Class<?> request, Class<?> expected) {
TypeDto type = typeService.findType(request);
assertNotNull(type);
assertEquals(expected.getName(), type.getTypeClass());
}
Aggregations