Search in sources :

Example 1 with DictionaryType

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]);
}
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)

Example 2 with DictionaryType

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);
}
Also used : TranslationService(com.qcadoo.localization.api.TranslationService) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DictionaryType(com.qcadoo.model.internal.types.DictionaryType) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) Before(org.junit.Before)

Aggregations

DictionaryType (com.qcadoo.model.internal.types.DictionaryType)2 TranslationService (com.qcadoo.localization.api.TranslationService)1 DictionaryService (com.qcadoo.model.api.DictionaryService)1 FieldDefinition (com.qcadoo.model.api.FieldDefinition)1 EnumeratedType (com.qcadoo.model.api.types.EnumeratedType)1 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)1 ValueAndError (com.qcadoo.model.internal.api.ValueAndError)1 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)1 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)1 Before (org.junit.Before)1 Test (org.junit.Test)1