use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class DisplayHelperTest method shouldDisplayCbSingleSelectUserSupplied.
@Test
public void shouldDisplayCbSingleSelectUserSupplied() {
FieldDto field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", false, true, null);
assertEquals("Something", DisplayHelper.getDisplayValueForField(field, "Something"));
field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", false, true, null);
assertEquals(null, DisplayHelper.getDisplayValueForField(field, null));
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class DisplayHelperTest method shouldDisplayCbSingleSelectNoUserSupplied.
@Test
public void shouldDisplayCbSingleSelectNoUserSupplied() {
FieldDto field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", false, false, DisplayTestEnum.valuesMap());
assertEquals("Monday", DisplayHelper.getDisplayValueForField(field, DisplayTestEnum.MONDAY));
field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", false, false, DisplayTestEnum.valuesMap());
assertNull(DisplayHelper.getDisplayValueForField(field, null));
field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", false, false, null);
assertEquals(DisplayTestEnum.MONDAY, DisplayHelper.getDisplayValueForField(field, DisplayTestEnum.MONDAY));
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class DisplayHelperTest method testSingleObjectRelationshipDisplay.
private void testSingleObjectRelationshipDisplay(Class<? extends Relationship> relClass) {
FieldDto field = FieldTestHelper.fieldDto("relField", relClass);
assertEquals("Value", DisplayHelper.getDisplayValueForField(field, new ToStringTestClass(1, "Value")));
assertEquals("Value", DisplayHelper.getDisplayValueForField(field, new UIRepresentationTestClass(1, "Value")));
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class FieldProcessorTest method shouldAssignFieldValidation.
@Test
public void shouldAssignFieldValidation() throws Exception {
TypeValidationDto intMinValue = new TypeValidationDto("mds.field.validation.minValue", Integer.class.getName());
TypeValidationDto intMaxValue = new TypeValidationDto("mds.field.validation.maxValue", Integer.class.getName());
TypeValidationDto intMustBeInSet = new TypeValidationDto("mds.field.validation.mustBeInSet", String.class.getName());
TypeValidationDto intCannotBeInSet = new TypeValidationDto("mds.field.validation.cannotBeInSet", String.class.getName());
TypeValidationDto decMinValue = new TypeValidationDto("mds.field.validation.minValue", Double.class.getName());
TypeValidationDto decMaxValue = new TypeValidationDto("mds.field.validation.maxValue", Double.class.getName());
TypeValidationDto decMustBeInSet = new TypeValidationDto("mds.field.validation.mustBeInSet", String.class.getName());
TypeValidationDto decCannotBeInSet = new TypeValidationDto("mds.field.validation.cannotBeInSet", String.class.getName());
TypeValidationDto regex = new TypeValidationDto("mds.field.validation.regex", String.class.getName());
TypeValidationDto minLength = new TypeValidationDto("mds.field.validation.minLength", Integer.class.getName());
TypeValidationDto maxLength = new TypeValidationDto("mds.field.validation.maxLength", Integer.class.getName());
doReturn(singletonList(intMinValue)).when(schemaHolder).findValidations(Integer.class.getName(), DecimalMin.class);
doReturn(singletonList(intMaxValue)).when(schemaHolder).findValidations(Integer.class.getName(), DecimalMax.class);
doReturn(singletonList(intMustBeInSet)).when(schemaHolder).findValidations(Integer.class.getName(), InSet.class);
doReturn(singletonList(intCannotBeInSet)).when(schemaHolder).findValidations(Integer.class.getName(), NotInSet.class);
doReturn(singletonList(intMinValue)).when(schemaHolder).findValidations(Integer.class.getName(), Min.class);
doReturn(singletonList(intMaxValue)).when(schemaHolder).findValidations(Integer.class.getName(), Max.class);
doReturn(singletonList(decMinValue)).when(schemaHolder).findValidations(Double.class.getName(), DecimalMin.class);
doReturn(singletonList(decMaxValue)).when(schemaHolder).findValidations(Double.class.getName(), DecimalMax.class);
doReturn(singletonList(decMustBeInSet)).when(schemaHolder).findValidations(Double.class.getName(), InSet.class);
doReturn(singletonList(decCannotBeInSet)).when(schemaHolder).findValidations(Double.class.getName(), NotInSet.class);
doReturn(singletonList(decMinValue)).when(schemaHolder).findValidations(Double.class.getName(), Min.class);
doReturn(singletonList(decMaxValue)).when(schemaHolder).findValidations(Double.class.getName(), Max.class);
doReturn(singletonList(regex)).when(schemaHolder).findValidations(String.class.getName(), Pattern.class);
doReturn(asList(minLength, maxLength)).when(schemaHolder).findValidations(String.class.getName(), Size.class);
doReturn(singletonList(minLength)).when(schemaHolder).findValidations(String.class.getName(), DecimalMin.class);
doReturn(singletonList(maxLength)).when(schemaHolder).findValidations(String.class.getName(), DecimalMax.class);
processor.execute(bundle, schemaHolder);
Collection<FieldDto> fields = processor.getElements();
FieldDto pi = findFieldWithName(fields, "pi");
assertCriterion(pi, "mds.field.validation.minValue", "3");
assertCriterion(pi, "mds.field.validation.maxValue", "4");
assertCriterion(pi, "mds.field.validation.mustBeInSet", "3,3.14,4");
assertCriterion(pi, "mds.field.validation.cannotBeInSet", "1,2,5");
FieldDto epsilon = findFieldWithName(fields, "epsilon");
assertCriterion(epsilon, "mds.field.validation.minValue", "0.0");
assertCriterion(epsilon, "mds.field.validation.maxValue", "1.0");
assertCriterion(epsilon, "mds.field.validation.mustBeInSet", "1,0.75,0.5,0.25,0");
assertCriterion(epsilon, "mds.field.validation.cannotBeInSet", "-1,2,3");
FieldDto random = findFieldWithName(fields, "random");
assertCriterion(random, "mds.field.validation.minValue", "0");
assertCriterion(random, "mds.field.validation.maxValue", "10");
FieldDto gaussian = findFieldWithName(fields, "gaussian");
assertCriterion(gaussian, "mds.field.validation.minValue", "0.0");
assertCriterion(gaussian, "mds.field.validation.maxValue", "1.0");
FieldDto poem = findFieldWithName(fields, "poem");
assertCriterion(poem, "mds.field.validation.regex", "[A-Z][a-z]{9}");
assertCriterion(poem, "mds.field.validation.minLength", "10");
assertCriterion(poem, "mds.field.validation.maxLength", "20");
FieldDto article = findFieldWithName(fields, "article");
assertCriterion(article, "mds.field.validation.minLength", "100");
assertCriterion(article, "mds.field.validation.maxLength", "500");
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class FieldProcessorTest method shouldNotProcessPublicFieldWithIgnoreAnnotation.
@Test
public void shouldNotProcessPublicFieldWithIgnoreAnnotation() {
AnnotatedElement ignored = getDeclaredField(Sample.class, "ignored", true);
processor.process(ignored);
Collection<FieldDto> fields = processor.getElements();
assertEquals(1, fields.size());
List<AnnotatedElement> actual = new ArrayList<>();
actual.addAll(processor.getElementsToProcess());
assertEquals(Sample.FIELD_COUNT, actual.size());
assertFalse(actual.contains(ignored));
}
Aggregations