use of com.qcadoo.view.internal.internal.ViewDefinitionImpl in project qcadoo by qcadoo.
the class ViewDefinitionParserImpl method parseViewDefinition.
private InternalViewDefinition parseViewDefinition(final Node viewNode, final String pluginIdentifier) throws ViewDefinitionParserNodeException {
currentIndexOrder = 1;
String name = getStringAttribute(viewNode, "name");
Preconditions.checkState(name != null && !"".equals(name.trim()), "Name attribute cannot be empty");
LOG.info("Reading view " + name + " for plugin " + pluginIdentifier);
boolean menuAccessible = getBooleanAttribute(viewNode, "menuAccessible", false);
String windowWidthStr = getStringAttribute(viewNode, "windowWidth");
String windowHeightStr = getStringAttribute(viewNode, "windowHeight");
Integer windowWidth = null;
Integer windowHeight = null;
if (windowWidthStr != null) {
windowWidth = Integer.parseInt(windowWidthStr);
}
if (windowHeightStr != null) {
windowHeight = Integer.parseInt(windowHeightStr);
}
SecurityRole role = getAuthorizationRole(viewNode);
DataDefinition dataDefinition = getDataDefinition(viewNode, pluginIdentifier);
ViewDefinitionImpl viewDefinition = new ViewDefinitionImpl(name, pluginIdentifier, role, dataDefinition, menuAccessible, translationService);
viewDefinition.setWindowDimmension(windowWidth, windowHeight);
ComponentPattern root = null;
NodeList childNodes = viewNode.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node child = childNodes.item(i);
if (Node.ELEMENT_NODE != child.getNodeType()) {
continue;
}
if ("component".equals(child.getNodeName())) {
root = parseComponent(child, viewDefinition, null, pluginIdentifier);
} else if ("hooks".equals(child.getNodeName())) {
parseViewHooks(child, viewDefinition);
} else {
throw new ViewDefinitionParserNodeException(child, "Unknown node: " + child.getNodeName());
}
}
viewDefinition.addComponentPattern(root);
viewDefinition.initialize();
viewDefinition.registerViews(viewDefinitionService);
return viewDefinition;
}
use of com.qcadoo.view.internal.internal.ViewDefinitionImpl 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.internal.ViewDefinitionImpl 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.internal.ViewDefinitionImpl 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.internal.ViewDefinitionImpl 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);
}
Aggregations