use of com.qcadoo.model.internal.types.DictionaryType 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]);
}
use of com.qcadoo.model.internal.types.DictionaryType in project qcadoo by qcadoo.
the class SelectComponentStateTest method init.
@Before
public void init() {
MockitoAnnotations.initMocks(this);
DictionaryType dictionaryType = new DictionaryType(DICTIONARY_NAME, dictionaryService, false);
TranslationService translationService = mock(TranslationService.class);
FieldDefinition fieldDefinition = mock(FieldDefinition.class);
when(fieldDefinition.getType()).thenReturn(dictionaryType);
when(fieldDefinition.isRequired()).thenReturn(true);
when(fieldDefinition.getDefaultValue()).thenReturn("asd");
ComponentDefinition definition = new ComponentDefinition();
definition.setName("selectComponent");
definition.setViewDefinition(mock(InternalViewDefinition.class));
SelectComponentPattern pattern = new SelectComponentPattern(definition);
setField(pattern, "fieldDefinition", fieldDefinition);
setField(pattern, "translationService", translationService);
componentState = new SelectComponentState(pattern, Lists.newArrayList());
setField(componentState, "locale", Locale.ENGLISH);
setField(pattern, "defaultRequired", true);
}
Aggregations