use of com.servoy.j2db.server.ngclient.IWebFormController in project servoy-client by Servoy.
the class FoundsetTest method foundsetViewportChangeData.
@Test
public // change rows in/near viewport
void foundsetViewportChangeData() throws // change rows in/near viewport
JSONException, // change rows in/near viewport
ServoyException {
IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
Assert.assertNotNull(form);
WebFormComponent wc = form.getFormUI().getWebComponent("mycustombean");
FoundsetTypeSabloValue rawPropertyValue = (FoundsetTypeSabloValue) wc.getRawPropertyValue("myfoundset");
// right now the viewport change monitor will NOT ignore updates because the value is directly sent to the client (through the updateController code)
FoundsetTypeViewport viewPort = rawPropertyValue.getViewPort();
viewPort.setBounds(1, 1);
viewPort.changeMonitor.clearChanges();
rawPropertyValue.getFoundset().getRecord(0).startEditing();
rawPropertyValue.getFoundset().getRecord(0).setValue("test1", "not test1 any more");
rawPropertyValue.getFoundset().getRecord(0).stopEditing();
Assert.assertEquals(0, viewPort.changeMonitor.viewPortDataChangeMonitor.getViewPortChanges().length);
rawPropertyValue.getFoundset().getRecord(1).startEditing();
rawPropertyValue.getFoundset().getRecord(1).setValue("test2", "not test2 any more");
rawPropertyValue.getFoundset().getRecord(1).stopEditing();
Assert.assertEquals(1, viewPort.changeMonitor.viewPortDataChangeMonitor.getViewPortChanges().length);
// now simulate a send to client
rawPropertyValue.toJSON(new JSONStringer(), new DataConversion(), new BrowserConverterContext(wc, PushToServerEnum.allow));
rawPropertyValue.getFoundset().getRecord(0).startEditing();
rawPropertyValue.getFoundset().getRecord(0).setValue("test1", "not test1 any more nor not test1 any more");
rawPropertyValue.getFoundset().getRecord(0).stopEditing();
Assert.assertEquals(0, viewPort.changeMonitor.viewPortDataChangeMonitor.getViewPortChanges().length);
rawPropertyValue.getFoundset().getRecord(1).startEditing();
rawPropertyValue.getFoundset().getRecord(1).setValue("test2", "not test2 any more nor not test2 any more");
rawPropertyValue.getFoundset().getRecord(1).stopEditing();
Assert.assertEquals(1, viewPort.changeMonitor.viewPortDataChangeMonitor.getViewPortChanges().length);
}
use of com.servoy.j2db.server.ngclient.IWebFormController in project servoy-client by Servoy.
the class FoundsetTest method foundsetReadByDataprovidersPushToServerReject.
@Test
public void foundsetReadByDataprovidersPushToServerReject() throws JSONException {
IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
Assert.assertNotNull(form);
String full = NGUtils.formComponentPropertiesToString(form.getFormUI(), FullValueToJSONConverter.INSTANCE);
JSONObject object = new JSONObject(full);
JSONObject bean = object.getJSONObject("mycustombean");
JSONObject foundset = bean.getJSONObject("myfoundset");
Assert.assertEquals(18, foundset.getInt("serverSize"));
JSONObject viewPort = foundset.getJSONObject("viewPort");
Assert.assertEquals(0, viewPort.getInt("startIndex"));
// 15 is default preferredViewPortSize
Assert.assertEquals(15, viewPort.getInt("size"));
Assert.assertEquals(15, viewPort.getJSONArray("rows").length());
// fake incomming request for view port change.
endpoint.incoming("{\"methodname\":\"dataPush\",\"args\":{\"beanname\":\"mycustombean\",\"formname\":\"test\",\"changes\":{\"myfoundset\":[{\"newViewPort\":{\"startIndex\":0,\"size\":18}, \"id\": 4321}]}},\"service\":\"formService\"}", true);
String changes = NGUtils.formChangesToString(((Container) form.getFormUI()), FullValueToJSONConverter.INSTANCE);
object = new JSONObject(changes).getJSONObject("changes");
bean = object.getJSONObject("mycustombean");
foundset = bean.getJSONObject("myfoundset");
Assert.assertEquals(18, foundset.getInt("serverSize"));
viewPort = foundset.getJSONObject("viewPort");
Assert.assertEquals(0, viewPort.getInt("startIndex"));
Assert.assertEquals(18, viewPort.getInt("size"));
JSONArray rows = viewPort.getJSONArray("rows");
Assert.assertEquals(18, rows.length());
JSONArray handledClientReqIds = foundset.getJSONArray("handledClientReqIds");
Assert.assertEquals(1, handledClientReqIds.length());
Assert.assertEquals(4321, handledClientReqIds.getJSONObject(0).getInt("id"));
Assert.assertTrue(handledClientReqIds.getJSONObject(0).getBoolean("value"));
JSONObject row0 = rows.getJSONObject(0);
Assert.assertEquals("value1", row0.getString("firstname"));
Assert.assertEquals("value2", row0.getString("lastname"));
JSONObject row1 = rows.getJSONObject(1);
Assert.assertEquals("value3", row1.getString("firstname"));
Assert.assertEquals("value4", row1.getString("lastname"));
// fake an update
endpoint.incoming("{\"methodname\":\"dataPush\",\"args\":{\"beanname\":\"mycustombean\",\"formname\":\"test\",\"changes\":{\"myfoundset\":[{\"viewportDataChanged\":{\"_svyRowId\":\"" + row1.getString("_svyRowId") + "\",\"value\":\"value5\",\"dp\":\"lastname\"}}]}},\"service\":\"formService\"}", true);
// not value 5 cause pushToServer is rejected!
Assert.assertEquals("value4", form.getFormModel().getRecord(1).getValue("test2"));
}
use of com.servoy.j2db.server.ngclient.IWebFormController in project servoy-client by Servoy.
the class FoundsetTest method setPreferredViewport.
@Test
public // change selected index in main foundset and related foundset should change
void setPreferredViewport() throws // change selected index in main foundset and related foundset should change
JSONException {
IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
Assert.assertNotNull(form);
WebFormComponent wc1 = form.getFormUI().getWebComponent("mycustombean");
WebFormComponent wc2 = form.getFormUI().getWebComponent("mydynamiccustombean");
FoundsetTypeSabloValue customBeanFoundSet = (FoundsetTypeSabloValue) wc1.getRawPropertyValue("myfoundset");
FoundsetTypeSabloValue dynamicBeanRelatedFoundset = (FoundsetTypeSabloValue) wc2.getRawPropertyValue("myfoundset");
BrowserConverterContext allowBrowserConverterContext2 = new BrowserConverterContext(wc1, PushToServerEnum.allow);
dynamicBeanRelatedFoundset.getViewPort().setPreferredViewportSize(8);
// selection is now 0, so set to 1 and then back again
customBeanFoundSet.getFoundset().setSelectedIndex(1);
customBeanFoundSet.getFoundset().setSelectedIndex(0);
Assert.assertEquals(8, dynamicBeanRelatedFoundset.getViewPort().getSize());
Assert.assertEquals(0, dynamicBeanRelatedFoundset.getViewPort().getStartIndex());
StringWriter stringWriter = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(stringWriter);
dynamicBeanRelatedFoundset.toJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext2);
Assert.assertEquals("{\"serverSize\":12,\"foundsetId\":3,\"sortColumns\":\"\",\"selectedRowIndexes\":[0],\"multiSelect\":false,\"hasMoreRows\":false,\"viewPort\":{\"startIndex\":0,\"size\":8,\"rows\":[{\"_svyRowId\":\"1.1;_0\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"1.2;_1\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"},{\"_svyRowId\":\"1.3;_2\",\"dp1\":\"relatedvalue131\",\"dp2\":\"relatedvalue132\"},{\"_svyRowId\":\"1.5;_3\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"1.6;_4\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"},{\"_svyRowId\":\"1.7;_5\",\"dp1\":\"relatedvalue131\",\"dp2\":\"relatedvalue132\"},{\"_svyRowId\":\"1.9;_6\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"2.10;_7\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"}]}}", stringWriter.toString());
stringWriter = new StringWriter();
jsonWriter = new JSONWriter(stringWriter);
// selection is now 0, so set to 1 and then back again
customBeanFoundSet.getFoundset().setSelectedIndex(1);
dynamicBeanRelatedFoundset.changesToJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext2);
Assert.assertEquals("{\"upd_serverSize\":4,\"upd_foundsetId\":4,\"upd_selectedRowIndexes\":[0],\"upd_viewPort\":{\"startIndex\":0,\"size\":4,\"rows\":[{\"_svyRowId\":\"1.4;_0\",\"dp1\":\"relatedvalue241\",\"dp2\":\"relatedvalue242\"},{\"_svyRowId\":\"1.8;_1\",\"dp1\":\"relatedvalue241\",\"dp2\":\"relatedvalue242\"},{\"_svyRowId\":\"2.12;_2\",\"dp1\":\"relatedvalue241\",\"dp2\":\"relatedvalue242\"},{\"_svyRowId\":\"2.16;_3\",\"dp1\":\"relatedvalue241\",\"dp2\":\"relatedvalue242\"}]}}", stringWriter.toString());
stringWriter = new StringWriter();
jsonWriter = new JSONWriter(stringWriter);
customBeanFoundSet.getFoundset().setSelectedIndex(0);
dynamicBeanRelatedFoundset.changesToJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext2);
Assert.assertEquals("{\"upd_serverSize\":12,\"upd_foundsetId\":3,\"upd_selectedRowIndexes\":[0],\"upd_viewPort\":{\"startIndex\":0,\"size\":8,\"rows\":[{\"_svyRowId\":\"1.1;_0\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"1.2;_1\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"},{\"_svyRowId\":\"1.3;_2\",\"dp1\":\"relatedvalue131\",\"dp2\":\"relatedvalue132\"},{\"_svyRowId\":\"1.5;_3\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"1.6;_4\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"},{\"_svyRowId\":\"1.7;_5\",\"dp1\":\"relatedvalue131\",\"dp2\":\"relatedvalue132\"},{\"_svyRowId\":\"1.9;_6\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"2.10;_7\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"}]}}", stringWriter.toString());
}
use of com.servoy.j2db.server.ngclient.IWebFormController in project servoy-client by Servoy.
the class FoundsetTest method foundsetChangeMonitorChangeFlags.
@Test
public void foundsetChangeMonitorChangeFlags() throws ServoyException {
IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
Assert.assertNotNull(form);
FoundsetTypeSabloValue rawPropertyValue = (FoundsetTypeSabloValue) form.getFormUI().getWebComponent("mycustombean").getRawPropertyValue("myfoundset");
IFoundSetInternal foundSet = rawPropertyValue.getFoundset();
rawPropertyValue.changeMonitor.clearChanges();
foundSet.newRecord(0, false);
Assert.assertEquals(FoundsetTypeChangeMonitor.SEND_FOUNDSET_SIZE | FoundsetTypeChangeMonitor.SEND_SELECTED_INDEXES, rawPropertyValue.changeMonitor.changeFlags);
rawPropertyValue.changeMonitor.clearChanges();
foundSet.deleteRecord(0);
Assert.assertEquals(FoundsetTypeChangeMonitor.SEND_FOUNDSET_SIZE | FoundsetTypeChangeMonitor.SEND_SELECTED_INDEXES, rawPropertyValue.changeMonitor.changeFlags);
}
use of com.servoy.j2db.server.ngclient.IWebFormController in project servoy-client by Servoy.
the class FoundsetTest method foundsetViewportAllRecordChangedAndDeleted.
@Test
public // change rows in/near viewport
void foundsetViewportAllRecordChangedAndDeleted() throws // change rows in/near viewport
JSONException, // change rows in/near viewport
ServoyException {
IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
Assert.assertNotNull(form);
WebFormComponent wc = form.getFormUI().getWebComponent("mycustombean");
FoundsetTypeSabloValue rawPropertyValue = (FoundsetTypeSabloValue) wc.getRawPropertyValue("myfoundset");
BrowserConverterContext allowBrowserConverterContext = new BrowserConverterContext(wc, PushToServerEnum.allow);
FoundsetTypeViewport viewPort = rawPropertyValue.getViewPort();
viewPort.setBounds(0, form.getFormModel().getSize());
StringWriter stringWriter = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(stringWriter);
rawPropertyValue.toJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext);
Assert.assertTrue(new JSONObject("{\"serverSize\":18,\"foundsetId\":2,\"sortColumns\":\"\",\"selectedRowIndexes\":[0],\"multiSelect\":false,\"hasMoreRows\":false,\"viewPort\":{\"startIndex\":0,\"size\":18,\"rows\":[{\"_svyRowId\":\"1.1;_0\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.2;_1\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.3;_2\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.4;_3\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.5;_4\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.6;_5\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.7;_6\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.8;_7\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.9;_8\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.10;_9\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.11;_10\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.12;_11\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.13;_12\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.14;_13\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.15;_14\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.16;_15\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.17;_16\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.18;_17\",\"lastname\":\"value4\",\"firstname\":\"value3\"}]}}").similar(new JSONObject(stringWriter.toString())));
form.getFormModel().fireFoundSetChanged();
form.getFormModel().deleteRecord(0);
stringWriter = new StringWriter();
jsonWriter = new JSONWriter(stringWriter);
rawPropertyValue.toJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext);
Assert.assertTrue(new JSONObject("{\"serverSize\":17,\"foundsetId\":2,\"sortColumns\":\"\",\"selectedRowIndexes\":[0],\"multiSelect\":false,\"hasMoreRows\":false,\"viewPort\":{\"startIndex\":0,\"size\":17,\"rows\":[{\"_svyRowId\":\"1.2;_0\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.3;_1\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.4;_2\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.5;_3\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.6;_4\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.7;_5\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.8;_6\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.9;_7\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.10;_8\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.11;_9\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.12;_10\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.13;_11\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.14;_12\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.15;_13\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.16;_14\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.17;_15\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.18;_16\",\"lastname\":\"value4\",\"firstname\":\"value3\"}]}}").similar(new JSONObject(stringWriter.toString())));
}
Aggregations