Search in sources :

Example 16 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class ViewDefinitionTest method shouldReturnPattern.

@Test
public void shouldReturnPattern() throws Exception {
    // given
    InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
    ComponentPattern pattern = Mockito.mock(ComponentPattern.class);
    viewDefinition.registerComponent("reference", "path", pattern);
    // when
    ComponentPattern actualPattern = viewDefinition.getComponentByReference("reference");
    // then
    Assert.assertEquals(pattern, actualPattern);
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

Example 17 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class ViewDefinitionTest method shouldThrowCyclicDependencyOnInitialize.

@Test(expected = IllegalStateException.class)
public void shouldThrowCyclicDependencyOnInitialize() throws Exception {
    // given
    InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
    ComponentPattern pattern1 = Mockito.mock(ComponentPattern.class);
    given(pattern1.getName()).willReturn("test1");
    given(pattern1.initialize()).willReturn(false, false, false);
    ComponentPattern pattern2 = Mockito.mock(ComponentPattern.class);
    given(pattern2.getName()).willReturn("test2");
    given(pattern2.initialize()).willReturn(false, false, false);
    ComponentPattern pattern3 = Mockito.mock(ComponentPattern.class);
    given(pattern3.getName()).willReturn("test3");
    given(pattern3.initialize()).willReturn(false, true);
    ComponentPattern pattern4 = Mockito.mock(ComponentPattern.class);
    given(pattern3.getName()).willReturn("test4");
    given(pattern3.initialize()).willReturn(true);
    viewDefinition.addComponentPattern(pattern1);
    viewDefinition.addComponentPattern(pattern2);
    viewDefinition.addComponentPattern(pattern3);
    viewDefinition.addComponentPattern(pattern4);
    // when
    viewDefinition.initialize();
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

Example 18 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class ViewDefinitionTest method shouldCallEvent.

@Test
public void shouldCallEvent() throws Exception {
    // given
    InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
    TestEvent event = mock(TestEvent.class);
    ComponentStateMock state = new ComponentStateMock(new JSONObject(of("asd", "123")));
    state.registerTestEvent("eventName", event);
    ComponentPatternMock pattern = new ComponentPatternMock(getComponentDefinition("componentName", viewDefinition), state);
    viewDefinition.addComponentPattern(pattern);
    JSONObject eventJson = new JSONObject();
    eventJson.put(InternalViewDefinition.JSON_EVENT_NAME, "eventName");
    eventJson.put(InternalViewDefinition.JSON_EVENT_COMPONENT, "componentName");
    eventJson.put(InternalViewDefinition.JSON_EVENT_ARGS, new JSONArray(newArrayList("arg1", "arg2")));
    JSONObject contentJson = new JSONObject();
    contentJson.put("asd", "qwe");
    JSONObject componentJson = new JSONObject();
    componentJson.put(AbstractComponentState.JSON_CONTENT, contentJson);
    JSONObject json = new JSONObject();
    json.put(InternalViewDefinition.JSON_EVENT, eventJson);
    json.put(InternalViewDefinition.JSON_COMPONENTS, new JSONObject(of("componentName", componentJson)));
    // when
    JSONObject result = ((InternalComponentState) viewDefinition.performEvent(json, Locale.ENGLISH)).render();
    // then
    assertEquals(contentJson, state.getContent());
    verify(event).invoke(new String[] { "arg1", "arg2" });
    Assert.assertEquals("123", result.getJSONObject("components").getJSONObject("componentName").getJSONObject("content").get("asd"));
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) JSONObject(org.json.JSONObject) TestEvent(com.qcadoo.view.internal.states.ComponentStateMock.TestEvent) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) JSONArray(org.json.JSONArray) ComponentPatternMock(com.qcadoo.view.internal.patterns.ComponentPatternMock) DataDefinition(com.qcadoo.model.api.DataDefinition) ComponentStateMock(com.qcadoo.view.internal.states.ComponentStateMock) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

Example 19 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class ViewDefinitionTest method shouldReturnNullWhenPatternNotExists.

@Test
public void shouldReturnNullWhenPatternNotExists() throws Exception {
    // given
    InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
    // when
    ComponentPattern actualPattern = viewDefinition.getComponentByReference("xxx");
    // then
    assertNull(actualPattern);
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

Example 20 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class ViewGridColumnModule method getGrid.

private GridComponentPattern getGrid() {
    InternalViewDefinition viewDefinition = viewDefinitionService.getWithoutSession(extendsViewPlugin, extendsViewName);
    if (viewDefinition == null) {
        throw new ModuleException(pluginIdentifier, "view", "reference to view which not exists");
    }
    ComponentPattern component = viewDefinition.getComponentByReference(extendsComponentName);
    if (component == null) {
        throw new ModuleException(pluginIdentifier, "view", "reference to component which not exists in " + extendsViewPlugin + "/" + extendsViewName);
    }
    if (!(component instanceof GridComponentPattern)) {
        throw new ModuleException(pluginIdentifier, "view", "component '" + extendsComponentName + "' in " + extendsViewPlugin + "/" + extendsViewName + " is not a grid");
    }
    return (GridComponentPattern) component;
}
Also used : GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) ModuleException(com.qcadoo.plugin.api.ModuleException)

Aggregations

InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)49 Test (org.junit.Test)40 DataDefinition (com.qcadoo.model.api.DataDefinition)25 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)21 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)15 FieldDefinition (com.qcadoo.model.api.FieldDefinition)14 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)14 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)13 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)11 JSONObject (org.json.JSONObject)10 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)9 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)9 ComponentOption (com.qcadoo.view.internal.ComponentOption)8 ComponentState (com.qcadoo.view.api.ComponentState)7 ViewDefinitionImpl (com.qcadoo.view.internal.internal.ViewDefinitionImpl)7 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)6 BelongsToType (com.qcadoo.model.api.types.BelongsToType)5 HasManyType (com.qcadoo.model.api.types.HasManyType)5 ModuleException (com.qcadoo.plugin.api.ModuleException)4 EnumType (com.qcadoo.model.internal.types.EnumType)3