use of com.qcadoo.view.internal.api.InternalComponentState in project qcadoo by qcadoo.
the class AbstractContainerState method render.
@Override
public JSONObject render() throws JSONException {
JSONObject json = super.render();
JSONObject childerJson = new JSONObject();
for (Map.Entry<String, InternalComponentState> child : children.entrySet()) {
childerJson.put(child.getKey(), child.getValue().render());
}
json.put(JSON_CHILDREN, childerJson);
return json;
}
use of com.qcadoo.view.internal.api.InternalComponentState in project qcadoo by qcadoo.
the class CrudControllerTest method shouldPerformEvent.
@Test
public void shouldPerformEvent() throws Exception {
// given
InternalViewDefinitionState state = mock(InternalViewDefinitionState.class, Mockito.withSettings().extraInterfaces(InternalComponentState.class));
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
ViewDefinitionService viewDefinitionService = mock(ViewDefinitionService.class);
given(viewDefinitionService.get("testPlugin", "testView")).willReturn(viewDefinition);
JSONObject jsonBody = new JSONObject();
jsonBody.put("test", "testVal1");
JSONObject jsonResult = new JSONObject();
jsonResult.put("test", "testVal2");
CrudService crud = new CrudServiceImpl();
ReflectionTestUtils.setField(crud, "viewDefinitionService", viewDefinitionService);
given(viewDefinition.performEvent(jsonBody, Locale.ENGLISH)).willReturn(state);
given(((InternalComponentState) state).render()).willReturn(jsonResult);
// when
Object result = crud.invokeEventAndRenderView("testPlugin", "testView", jsonBody, Locale.ENGLISH);
// then
assertEquals(jsonResult, result);
}
use of com.qcadoo.view.internal.api.InternalComponentState in project qcadoo by qcadoo.
the class ViewDefinitionStateTest method shouldPerformEventOnAllComponent.
@Test
public void shouldPerformEventOnAllComponent() throws Exception {
// given
ViewDefinitionStateImpl viewDefinitionState = new ViewDefinitionStateImpl();
ContainerState state1 = mock(ContainerState.class);
given(state1.getName()).willReturn("name1");
InternalComponentState state2 = mock(InternalComponentState.class);
viewDefinitionState.addChild(state1);
given(state1.getChildren()).willReturn(Collections.singletonMap("name2", state2));
// when
viewDefinitionState.performEvent((String) null, "event", new String[] { "arg1", "arg2" });
// then
Mockito.verify(state1).performEvent(viewDefinitionState, "event", "arg1", "arg2");
Mockito.verify(state2).performEvent(viewDefinitionState, "event", "arg1", "arg2");
}
use of com.qcadoo.view.internal.api.InternalComponentState 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.InternalComponentState in project qcadoo by qcadoo.
the class FormComponentStateTest method shouldInitialeFormWithEntityId.
@Test
public void shouldInitialeFormWithEntityId() throws Exception {
// given
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
setField(pattern, "applicationContext", applicationContext);
InternalComponentState componentState = new FormComponentState(pattern);
JSONObject json = new JSONObject();
JSONObject jsonContent = new JSONObject();
jsonContent.put(FormComponentState.JSON_ENTITY_ID, 13L);
json.put(AbstractComponentState.JSON_CONTENT, jsonContent);
JSONObject jsonChildren = new JSONObject();
json.put(AbstractComponentState.JSON_CHILDREN, jsonChildren);
// when
componentState.initialize(json, Locale.ENGLISH);
// then
assertEquals(13L, componentState.getFieldValue());
}
Aggregations