Search in sources :

Example 1 with IWebFormController

use of com.servoy.j2db.server.ngclient.IWebFormController in project servoy-client by Servoy.

the class EventCallTest method callButtonWithUUIDName.

@Test
public void callButtonWithUUIDName() {
    IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
    Assert.assertNotNull(form);
    Collection<WebComponent> components = form.getFormUI().getComponents();
    String beanName = null;
    for (WebComponent webComponent : components) {
        String rawName = ((WebFormComponent) webComponent).getFormElement().getRawName();
        if (rawName != null && rawName.equals(uuid)) {
            beanName = webComponent.getName();
            break;
        }
    }
    Assert.assertNotNull(beanName);
    // fake incoming request for button click
    endpoint.incoming("{\"service\":\"formService\",\"methodname\":\"executeEvent\",\"args\":{\"formname\":\"test\",\"beanname\":\"" + beanName + "\",\"event\":\"onActionMethodID\",\"args\":[{\"type\":\"event\",\"eventName\":\"onActionMethodID\",\"modifiers\":0,\"timestamp\":1430912492641,\"x\":362,\"y\":207}],\"changes\":{}},\"cmsgid\":2}", true);
    Object object = form.getFormScope().get("testVar2");
    Assert.assertEquals(uuid, object);
}
Also used : WebComponent(org.sablo.WebComponent) IWebFormController(com.servoy.j2db.server.ngclient.IWebFormController) Test(org.junit.Test)

Example 2 with IWebFormController

use of com.servoy.j2db.server.ngclient.IWebFormController in project servoy-client by Servoy.

the class EventCallTest method callButtonWithNoName.

@Test
public void callButtonWithNoName() {
    IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
    Assert.assertNotNull(form);
    // fake incoming request for button click
    endpoint.incoming("{\"service\":\"formService\",\"methodname\":\"executeEvent\",\"args\":{\"formname\":\"test\",\"beanname\":\"svy_3\",\"event\":\"onActionMethodID\",\"args\":[{\"type\":\"event\",\"eventName\":\"onActionMethodID\",\"modifiers\":0,\"timestamp\":1430912492641,\"x\":362,\"y\":207}],\"changes\":{}},\"cmsgid\":2}", true);
    Object object = form.getFormScope().get("testVar");
    Assert.assertEquals(10, ((Number) object).longValue());
}
Also used : IWebFormController(com.servoy.j2db.server.ngclient.IWebFormController) Test(org.junit.Test)

Example 3 with IWebFormController

use of com.servoy.j2db.server.ngclient.IWebFormController in project servoy-client by Servoy.

the class FoundsetTest method foundsetReadByDataprovidersPushToServerAllow.

@Test
public void foundsetReadByDataprovidersPushToServerAllow() 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("myfoundsetWithAllow");
    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\":{\"myfoundsetWithAllow\":[{\"newViewPort\":{\"startIndex\":0,\"size\":18}, \"id\": 1234}]}},\"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("myfoundsetWithAllow");
    Assert.assertEquals(18, foundset.getInt("serverSize"));
    Assert.assertEquals(18, foundset.getInt("serverSize"));
    JSONArray handledClientReqIds = foundset.getJSONArray("handledClientReqIds");
    Assert.assertEquals(1, handledClientReqIds.length());
    Assert.assertEquals(1234, handledClientReqIds.getJSONObject(0).getInt("id"));
    Assert.assertTrue(handledClientReqIds.getJSONObject(0).getBoolean("value"));
    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());
    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\":{\"myfoundsetWithAllow\":[{\"viewportDataChanged\":{\"_svyRowId\":\"" + row1.getString("_svyRowId") + "\",\"value\":\"value5\",\"dp\":\"lastname\"}}]}},\"service\":\"formService\"}", true);
    Assert.assertEquals("value5", form.getFormModel().getRecord(1).getValue("test2"));
}
Also used : Container(org.sablo.Container) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) JSONArray(org.json.JSONArray) IWebFormController(com.servoy.j2db.server.ngclient.IWebFormController) Test(org.junit.Test)

Example 4 with IWebFormController

use of com.servoy.j2db.server.ngclient.IWebFormController in project servoy-client by Servoy.

the class FoundsetTest method foundsetViewportAddRemove.

@Test
public // add / remove rows in viewport, near viewport
void foundsetViewportAddRemove() throws // add / remove rows in viewport, near viewport
JSONException, // add / remove rows in viewport, near viewport
ServoyException {
    IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
    Assert.assertNotNull(form);
    FoundsetTypeSabloValue rawPropertyValue = (FoundsetTypeSabloValue) form.getFormUI().getWebComponent("mycustombean").getRawPropertyValue("myfoundset");
    FoundsetTypeViewport viewPort = rawPropertyValue.getViewPort();
    viewPort.setPreferredViewportSize(1);
    viewPort.setBounds(1, 1);
    IFoundSetInternal foundSet = rawPropertyValue.getFoundset();
    foundSet.newRecord(1, false);
    Assert.assertEquals(1, viewPort.size);
    Assert.assertEquals(1, viewPort.startIndex);
    Assert.assertEquals(19, rawPropertyValue.getFoundset().getSize());
    StringWriter stringWriter = new StringWriter();
    JSONWriter jsonWriter = new JSONWriter(stringWriter);
    rawPropertyValue.addViewPort(jsonWriter);
    Assert.assertTrue(new JSONObject("{\"startIndex\":1,\"size\":1,\"rows\":[{\"_svyRowId\":\".null;_1\",\"lastname\":null,\"firstname\":null}]}").similar(new JSONObject(stringWriter.toString())));
    foundSet.deleteRecord(1);
    Assert.assertEquals(18, rawPropertyValue.getFoundset().getSize());
    stringWriter.getBuffer().setLength(0);
    jsonWriter = new JSONWriter(stringWriter);
    rawPropertyValue.addViewPort(jsonWriter);
    Assert.assertTrue(new JSONObject("{\"startIndex\":1,\"size\":1,\"rows\":[{\"_svyRowId\":\"1.2;_1\",\"lastname\":\"value4\",\"firstname\":\"value3\"}]}").similar(new JSONObject(stringWriter.toString())));
    foundSet.newRecord(0, false);
    stringWriter.getBuffer().setLength(0);
    jsonWriter = new JSONWriter(stringWriter);
    rawPropertyValue.addViewPort(jsonWriter);
    Assert.assertTrue(new JSONObject("{\"startIndex\":1,\"size\":1,\"rows\":[{\"_svyRowId\":\"1.1;_1\",\"lastname\":\"value2\",\"firstname\":\"value1\"}]}").similar(new JSONObject(stringWriter.toString())));
    foundSet.newRecord(3, false);
    Assert.assertEquals(20, rawPropertyValue.getFoundset().getSize());
    stringWriter.getBuffer().setLength(0);
    jsonWriter = new JSONWriter(stringWriter);
    rawPropertyValue.addViewPort(jsonWriter);
    Assert.assertTrue(new JSONObject("{\"startIndex\":1,\"size\":1,\"rows\":[{\"_svyRowId\":\"1.1;_1\",\"lastname\":\"value2\",\"firstname\":\"value1\"}]}").similar(new JSONObject(stringWriter.toString())));
    // delete records added in this test
    foundSet.deleteRecord(0);
    // last record is now at index 2
    foundSet.deleteRecord(2);
    Assert.assertEquals(18, rawPropertyValue.getFoundset().getSize());
}
Also used : JSONWriter(org.json.JSONWriter) StringWriter(java.io.StringWriter) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) IWebFormController(com.servoy.j2db.server.ngclient.IWebFormController) Test(org.junit.Test)

Example 5 with IWebFormController

use of com.servoy.j2db.server.ngclient.IWebFormController in project servoy-client by Servoy.

the class FoundsetTest method foundsetRelated.

@Test
public // change selected index in main foundset and related foundset should change
void foundsetRelated() throws // change selected index in main foundset and related foundset should change
JSONException {
    IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
    Assert.assertNotNull(form);
    BrowserConverterContext allowBrowserConverterContext2 = new BrowserConverterContext(form.getFormUI().getWebComponent("mydynamiccustombean"), PushToServerEnum.allow);
    FoundsetTypeSabloValue customBeanFoundSet = (FoundsetTypeSabloValue) form.getFormUI().getWebComponent("mycustombean").getRawPropertyValue("myfoundset");
    FoundsetTypeSabloValue dynamicBeanRelatedFoundset = (FoundsetTypeSabloValue) form.getFormUI().getWebComponent("mydynamiccustombean").getRawPropertyValue("myfoundset");
    dynamicBeanRelatedFoundset.getViewPort().setBounds(1, 1);
    // selection is now 0, so set to 1 and then back again
    customBeanFoundSet.getFoundset().setSelectedIndex(1);
    customBeanFoundSet.getFoundset().setSelectedIndex(0);
    Assert.assertEquals(12, dynamicBeanRelatedFoundset.getViewPort().getSize());
    Assert.assertEquals(0, dynamicBeanRelatedFoundset.getViewPort().getStartIndex());
    dynamicBeanRelatedFoundset.getViewPort().setBounds(1, 1);
    StringWriter stringWriter = new StringWriter();
    JSONWriter jsonWriter = new JSONWriter(stringWriter);
    dynamicBeanRelatedFoundset.addViewPort(jsonWriter);
    Assert.assertEquals("{\"startIndex\":1,\"size\":1,\"rows\":[{\"_svyRowId\":\"1.2;_1\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"}]}", stringWriter.toString());
    stringWriter.getBuffer().setLength(0);
    jsonWriter = new JSONWriter(stringWriter);
    dynamicBeanRelatedFoundset.changesToJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext2);
    Assert.assertEquals("{\"upd_serverSize\":12,\"upd_foundsetId\":3,\"upd_selectedRowIndexes\":[0],\"upd_viewPort\":{\"startIndex\":1,\"size\":1,\"rows\":[{\"_svyRowId\":\"1.2;_1\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"}]}}", stringWriter.toString());
    customBeanFoundSet.getFoundset().setSelectedIndex(1);
    dynamicBeanRelatedFoundset.getViewPort().setBounds(0, 1);
    stringWriter.getBuffer().setLength(0);
    jsonWriter = new JSONWriter(stringWriter);
    dynamicBeanRelatedFoundset.changesToJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext2);
    Assert.assertEquals("{\"upd_serverSize\":4,\"upd_foundsetId\":4,\"upd_selectedRowIndexes\":[0],\"upd_viewPort\":{\"startIndex\":0,\"size\":1,\"rows\":[{\"_svyRowId\":\"1.4;_0\",\"dp1\":\"relatedvalue241\",\"dp2\":\"relatedvalue242\"}]}}", stringWriter.toString());
}
Also used : JSONWriter(org.json.JSONWriter) DataConversion(org.sablo.websocket.utils.DataConversion) StringWriter(java.io.StringWriter) BrowserConverterContext(org.sablo.specification.property.BrowserConverterContext) IWebFormController(com.servoy.j2db.server.ngclient.IWebFormController) Test(org.junit.Test)

Aggregations

IWebFormController (com.servoy.j2db.server.ngclient.IWebFormController)24 Test (org.junit.Test)21 JSONObject (org.json.JSONObject)12 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)10 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)9 StringWriter (java.io.StringWriter)9 JSONWriter (org.json.JSONWriter)9 BrowserConverterContext (org.sablo.specification.property.BrowserConverterContext)9 DataConversion (org.sablo.websocket.utils.DataConversion)8 JSONArray (org.json.JSONArray)4 Container (org.sablo.Container)4 FormScope (com.servoy.j2db.scripting.FormScope)3 Context (org.mozilla.javascript.Context)3 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)2 Form (com.servoy.j2db.persistence.Form)2 RhinoMapOrArrayWrapper (com.servoy.j2db.server.ngclient.component.RhinoMapOrArrayWrapper)2 ServoyException (com.servoy.j2db.util.ServoyException)2 JSONException (org.json.JSONException)2 WebComponent (org.sablo.WebComponent)2 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)1