Search in sources :

Example 16 with TranslationService

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

the class ComponentPatternTest method shouldHaveValidInstance.

@Test
@SuppressWarnings("unchecked")
public void shouldHaveValidInstance() throws Exception {
    // given
    InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
    TranslationService translationService = mock(TranslationService.class);
    ApplicationContext applicationContext = mock(ApplicationContext.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    ComponentDefinition componentDefinition = getComponentDefinition("testName", null);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    componentDefinition.setViewDefinition(viewDefinition);
    AbstractComponentPattern pattern = new FormComponentPattern(componentDefinition);
    ViewEventListenerHook viewEventListenerHook = mock(ViewEventListenerHook.class);
    given(viewEventListenerHook.getEventName()).willReturn("save");
    pattern.addCustomEvent(viewEventListenerHook);
    // when
    ComponentState state = pattern.createComponentState(viewDefinitionState);
    // then
    assertTrue(state instanceof FormComponent);
    EventHandlerHolder eventHandlerHolder = (EventHandlerHolder) getField(state, "eventHandlerHolder");
    Map<String, List<EventHandlerHolder.EventHandler>> eventHandlers = (Map<String, List<EventHandlerHolder.EventHandler>>) getField(eventHandlerHolder, "eventHandlers");
    List<EventHandlerHolder.EventHandler> handlers = eventHandlers.get("save");
    assertNotNull(handlers);
    assertEquals(2, handlers.size());
    assertEquals(viewEventListenerHook, handlers.get(1));
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) EventHandlerHolder(com.qcadoo.view.internal.internal.EventHandlerHolder) ApplicationContext(org.springframework.context.ApplicationContext) ViewEventListenerHook(com.qcadoo.view.internal.hooks.ViewEventListenerHook) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) TranslationService(com.qcadoo.localization.api.TranslationService) List(java.util.List) Map(java.util.Map) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) ComponentState(com.qcadoo.view.api.ComponentState) Test(org.junit.Test)

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