Search in sources :

Example 1 with ViewLifecycleHook

use of com.qcadoo.view.internal.hooks.ViewLifecycleHook in project qcadoo by qcadoo.

the class ViewDefinitionTest method mockLifecycleHook.

private ViewLifecycleHook mockLifecycleHook(final HookType type) {
    ViewLifecycleHook preInitializeHook = mock(ViewLifecycleHook.class);
    given(preInitializeHook.getType()).willReturn(type);
    return preInitializeHook;
}
Also used : ViewLifecycleHook(com.qcadoo.view.internal.hooks.ViewLifecycleHook)

Example 2 with ViewLifecycleHook

use of com.qcadoo.view.internal.hooks.ViewLifecycleHook in project qcadoo by qcadoo.

the class ViewDefinitionTest method shouldCallHooks.

@Test
public void shouldCallHooks() throws Exception {
    // given
    ViewDefinitionImpl viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
    ViewLifecycleHook preInitializeHook = mockLifecycleHook(HookType.BEFORE_INITIALIZE);
    viewDefinition.addHook(preInitializeHook);
    ViewLifecycleHook postInitializeHook1 = mockLifecycleHook(HookType.AFTER_INITIALIZE);
    viewDefinition.addHook(postInitializeHook1);
    ViewLifecycleHook postInitializeHook2 = mockLifecycleHook(HookType.AFTER_INITIALIZE);
    viewDefinition.addHook(postInitializeHook2);
    ViewLifecycleHook preRenderHook = mockLifecycleHook(HookType.BEFORE_RENDER);
    viewDefinition.addHook(preRenderHook);
    JSONObject eventJson = new JSONObject();
    eventJson.put(InternalViewDefinition.JSON_EVENT_NAME, "eventName");
    eventJson.put(InternalViewDefinition.JSON_EVENT_ARGS, new JSONArray(newArrayList("arg1", "arg2")));
    JSONObject json = new JSONObject();
    json.put(InternalViewDefinition.JSON_EVENT, eventJson);
    json.put(InternalViewDefinition.JSON_COMPONENTS, new JSONObject());
    // when
    viewDefinition.performEvent(json, Locale.ENGLISH);
    // then
    verify(preInitializeHook).callWithViewState(any(ViewDefinitionState.class));
    verify(postInitializeHook1).callWithViewState(any(ViewDefinitionState.class));
    verify(postInitializeHook2).callWithViewState(any(ViewDefinitionState.class));
    verify(preRenderHook).callWithViewState(any(ViewDefinitionState.class));
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) ViewLifecycleHook(com.qcadoo.view.internal.hooks.ViewLifecycleHook) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

Aggregations

ViewLifecycleHook (com.qcadoo.view.internal.hooks.ViewLifecycleHook)2 DataDefinition (com.qcadoo.model.api.DataDefinition)1 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)1 ViewDefinitionImpl (com.qcadoo.view.internal.internal.ViewDefinitionImpl)1 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1