use of com.qcadoo.model.api.DictionaryService in project qcadoo by qcadoo.
the class FieldTypeFactoryTest method shouldReturnDictionaryType.
@Test
public void shouldReturnDictionaryType() throws Exception {
// given
DictionaryService dictionaryService = mock(DictionaryService.class);
given(dictionaryService.getActiveValues("dictionary", Locale.ENGLISH)).willReturn(ImmutableMap.of("val1", "val1", "val2", "val2", "val3", "val3"));
given(dictionaryService.getKeys("dictionary")).willReturn(Lists.newArrayList("val1", "val2", "val3"));
// when
EnumeratedType fieldType = new DictionaryType("dictionary", dictionaryService, true);
// then
assertEquals(fieldType.activeValues(Locale.ENGLISH).keySet(), Sets.newHashSet("val1", "val2", "val3"));
assertEquals(Lists.newArrayList(fieldType.activeValues(Locale.ENGLISH).values()), Lists.newArrayList("val1", "val2", "val3"));
assertEquals(String.class, fieldType.getType());
ValueAndError valueAndError1 = fieldType.toObject(fieldDefinition, "val1");
ValueAndError valueAndError2 = fieldType.toObject(fieldDefinition, "val4");
assertNotNull(valueAndError1.getValue());
assertNull(valueAndError2.getValue());
assertEquals("qcadooView.validate.field.error.invalidDictionaryItem", valueAndError2.getMessage());
assertEquals("[val1, val2, val3]", valueAndError2.getArgs()[0]);
}
Aggregations