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