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