Search in sources :

Example 1 with TranslationService

use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.

the class ComponentStateTest method shouldHaveRequestUpdateStateFlag.

@Test
public void shouldHaveRequestUpdateStateFlag() throws Exception {
    // given
    new ExpressionServiceImpl().init();
    TranslationService translationService = mock(TranslationService.class);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn("2");
    ApplicationContext applicationContext = mock(ApplicationContext.class);
    setField(pattern, "applicationContext", applicationContext);
    AbstractComponentState componentState = new FormComponentState(pattern);
    componentState.setTranslationService(translationService);
    componentState.setDataDefinition(dataDefinition);
    componentState.setFieldValue(13L);
    componentState.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
    // when
    JSONObject json = componentState.render();
    // then
    assertTrue(json.getBoolean(AbstractComponentState.JSON_UPDATE_STATE));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) JSONObject(org.json.JSONObject) TranslationService(com.qcadoo.localization.api.TranslationService) ExpressionServiceImpl(com.qcadoo.model.internal.ExpressionServiceImpl) DataDefinition(com.qcadoo.model.api.DataDefinition) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Example 2 with TranslationService

use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.

the class AbstractPatternTest method getComponentDefinition.

public ComponentDefinition getComponentDefinition(final String name, final String fieldPath, final String sourceFieldPath, final ContainerPattern parent, final ViewDefinition viewDefinition) {
    ComponentDefinition componentDefinition = new ComponentDefinition();
    componentDefinition.setName(name);
    componentDefinition.setFieldPath(fieldPath);
    componentDefinition.setSourceFieldPath(sourceFieldPath);
    componentDefinition.setParent(parent);
    TranslationService translationService = mock(TranslationService.class);
    componentDefinition.setTranslationService(translationService);
    ContextualHelpService contextualHelpService = mock(ContextualHelpService.class);
    componentDefinition.setContextualHelpService(contextualHelpService);
    if (viewDefinition != null) {
        componentDefinition.setViewDefinition(viewDefinition);
    } else {
        componentDefinition.setViewDefinition(mock(InternalViewDefinition.class));
    }
    return componentDefinition;
}
Also used : TranslationService(com.qcadoo.localization.api.TranslationService) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ContextualHelpService(com.qcadoo.view.internal.api.ContextualHelpService) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition)

Example 3 with TranslationService

use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.

the class ComponentPatternTest method shouldHaveListenersOnEmptyOptions.

@Test
public void shouldHaveListenersOnEmptyOptions() throws Exception {
    // given
    TranslationService translationService = mock(TranslationService.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    ComponentDefinition componentDefinition = getComponentDefinition("testName", null);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setViewDefinition(viewDefinition);
    AbstractComponentPattern pattern = new TextInputComponentPattern(componentDefinition);
    // when
    Map<String, Object> model = pattern.prepareView(Locale.ENGLISH);
    // then
    JSONObject options = (JSONObject) model.get("jsOptions");
    assertEquals(7, options.length());
}
Also used : JSONObject(org.json.JSONObject) TranslationService(com.qcadoo.localization.api.TranslationService) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) JSONObject(org.json.JSONObject) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 4 with TranslationService

use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.

the class TranslationUtilsServiceTest method init.

@Before
public final void init() {
    translationService = mock(TranslationService.class);
    item = mock(Entity.class);
    category = mock(Entity.class);
    locale = Locale.getDefault();
    when(item.getStringField("pluginIdentifier")).thenReturn(PLUGIN_IDENTIFIER);
    when(category.getStringField("pluginIdentifier")).thenReturn(PLUGIN_IDENTIFIER);
    when(item.getStringField("name")).thenReturn(ITEM_NAME);
    when(category.getStringField("name")).thenReturn(CATEGORY_NAME);
    when(item.getBelongsToField("category")).thenReturn(category);
    translationUtilsService = new TranslationUtilsService();
    ReflectionTestUtils.setField(translationUtilsService, "translationService", translationService);
}
Also used : Entity(com.qcadoo.model.api.Entity) TranslationUtilsService(com.qcadoo.view.api.utils.TranslationUtilsService) TranslationService(com.qcadoo.localization.api.TranslationService) Before(org.junit.Before)

Example 5 with TranslationService

use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.

the class FormComponentStateTest method init.

@Before
public void init() throws Exception {
    entity = mock(Entity.class);
    given(entity.getField("name")).willReturn("text");
    viewDefinitionState = mock(ViewDefinitionState.class);
    translationService = mock(TranslationService.class);
    fieldDefinition = mock(FieldDefinition.class);
    given(fieldDefinition.getType()).willReturn(new StringType());
    given(fieldDefinition.getName()).willReturn("name");
    dataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
    given(dataDefinition.get(12L)).willReturn(null);
    given(dataDefinition.get(13L)).willReturn(entity);
    given(dataDefinition.getPluginIdentifier()).willReturn("plugin");
    given(dataDefinition.getName()).willReturn("name");
    given(dataDefinition.getField("name")).willReturn(fieldDefinition);
    given(dataDefinition.delete(any(Long.class))).willReturn(EntityOpResult.successfull());
    given(dataDefinition.create(anyLong())).willAnswer(new Answer<Entity>() {

        @Override
        public Entity answer(final InvocationOnMock invocation) throws Throwable {
            Long id = (Long) invocation.getArguments()[0];
            return new DefaultEntity(dataDefinition, id);
        }
    });
    FieldComponentPattern namePattern = mock(FieldComponentPattern.class);
    given(namePattern.isRequired()).willReturn(false);
    given(namePattern.isPersistent()).willReturn(true);
    name = new FieldComponentState(namePattern);
    name.setTranslationService(translationService);
    name.setName("name");
    name.initialize(new JSONObject(), Locale.ENGLISH);
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn("'static expression'");
    applicationContext = mock(ApplicationContext.class);
    setField(pattern, "applicationContext", applicationContext);
    SecurityRolesService securityRolesService = mock(SecurityRolesService.class);
    given(applicationContext.getBean(SecurityRolesService.class)).willReturn(securityRolesService);
    form = new FormComponentState(pattern);
    form.setDataDefinition(dataDefinition);
    form.setTranslationService(translationService);
    form.addFieldEntityIdChangeListener("name", name);
    form.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
    new ExpressionServiceImpl().init();
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) StringType(com.qcadoo.model.internal.types.StringType) FieldComponentPattern(com.qcadoo.view.internal.components.FieldComponentPattern) FieldDefinition(com.qcadoo.model.api.FieldDefinition) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) DataDefinition(com.qcadoo.model.api.DataDefinition) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) TranslationService(com.qcadoo.localization.api.TranslationService) FieldComponentState(com.qcadoo.view.internal.components.FieldComponentState) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) SecurityRolesService(com.qcadoo.security.api.SecurityRolesService) Matchers.anyLong(org.mockito.Matchers.anyLong) ExpressionServiceImpl(com.qcadoo.model.internal.ExpressionServiceImpl) Before(org.junit.Before)

Aggregations

TranslationService (com.qcadoo.localization.api.TranslationService)16 JSONObject (org.json.JSONObject)7 Test (org.junit.Test)7 ApplicationContext (org.springframework.context.ApplicationContext)7 DataDefinition (com.qcadoo.model.api.DataDefinition)6 Before (org.junit.Before)6 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)5 Entity (com.qcadoo.model.api.Entity)4 FieldDefinition (com.qcadoo.model.api.FieldDefinition)4 ExpressionServiceImpl (com.qcadoo.model.internal.ExpressionServiceImpl)4 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)4 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)4 FormComponentState (com.qcadoo.view.internal.components.form.FormComponentState)4 SecurityRolesService (com.qcadoo.security.api.SecurityRolesService)3 HasManyType (com.qcadoo.model.api.types.HasManyType)2 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)2 StringType (com.qcadoo.model.internal.types.StringType)2 SecurityRole (com.qcadoo.security.api.SecurityRole)2 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)2 Map (java.util.Map)2