Search in sources :

Example 1 with DictionaryService

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]);
}
Also used : DictionaryService(com.qcadoo.model.api.DictionaryService) ValueAndError(com.qcadoo.model.internal.api.ValueAndError) EnumeratedType(com.qcadoo.model.api.types.EnumeratedType) DictionaryType(com.qcadoo.model.internal.types.DictionaryType) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Aggregations

DictionaryService (com.qcadoo.model.api.DictionaryService)1 EnumeratedType (com.qcadoo.model.api.types.EnumeratedType)1 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)1 ValueAndError (com.qcadoo.model.internal.api.ValueAndError)1 DictionaryType (com.qcadoo.model.internal.types.DictionaryType)1 Test (org.junit.Test)1