Search in sources :

Example 6 with ServoyDataConverterContext

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

the class PersistFieldInstanceTest method testCustomComponentWithFormProperty.

@Test
public void testCustomComponentWithFormProperty() throws RepositoryException, JSONException {
    // TODO this should become a test on form uuid in the inner html/bean xml instead of the form name..
    Form form = solution.getForm("test");
    Assert.assertNotNull(form);
    DataAdapterList dataAdapterList = new DataAdapterList(new TestFormController(form, client));
    Form tabForm = solution.createNewForm(validator, null, "tabform", null, false, new Dimension(600, 400));
    // as client's "inDesigner" == true we will generate an error bean because legacy Bean usage for custom web components with custom object/array types is depreacated and not fully working (in designer at least)
    // so we will check that it generates an error bean (that means no props are set)
    // TODO maybe this can be uncommented after https://support.servoy.com/browse/SVY-9459 is done
    // Bean bean = form.createNewBean("mycustombean", "my-component");
    // bean.setInnerHTML("{atype:{name:'name',form:'tabform'}}");
    List<FormElement> formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
    // Assert.assertEquals(1, formElements.size());
    // WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), null);
    @SuppressWarnings("unchecked") WebComponent // form.removeChild(bean);
    webComponent = form.createNewWebComponent("mycustombean", "my-component");
    webComponent.setProperty("atype", new ServoyJSONObject("{name:'name',form:'tabform'}", false));
    formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
    Assert.assertEquals(1, formElements.size());
    WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), null, form);
    Map<String, Object> type = (Map<String, Object>) wc.getProperty("atype");
    Assert.assertEquals("name", type.get("name"));
    Assert.assertEquals("tabform", type.get("form"));
    Assert.assertEquals(0, wc.getAndClearChanges().content.size());
    TypedData<Map<String, Object>> props = wc.getProperties();
    String json = JSONUtils.writeDataWithConversions(props.content, props.contentType, null);
    JSONAssert.assertEquals("{\"atype\":{\"rt\":\"my-component.mytype\",\"vEr\":2,\"v\":{\"form\":\"tabform\",\"name\":\"name\"}},\"svyMarkupId\":\"sf331d64ddc0c17747371b7740e3e3447\",\"svy_types\":{\"atype\":\"JSON_obj\"}}", json, true);
}
Also used : Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) Dimension(java.awt.Dimension) FormElement(com.servoy.j2db.server.ngclient.FormElement) WebComponent(com.servoy.j2db.persistence.WebComponent) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) ServoyDataConverterContext(com.servoy.j2db.server.ngclient.ServoyDataConverterContext) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 7 with ServoyDataConverterContext

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

the class PersistFieldInstanceTest method testCustomComponentWithI18NProperty.

@Test
public void testCustomComponentWithI18NProperty() throws RepositoryException, JSONException {
    Form form = solution.getForm("test");
    Assert.assertNotNull(form);
    DataAdapterList dataAdapterList = new DataAdapterList(new TestFormController(form, client));
    WebComponent bean = form.createNewWebComponent("mycustombean", "my-component");
    bean.setProperty("atype", new ServoyJSONObject("{name:'name',text:'i18n:servoy.button.ok'}", false));
    List<FormElement> formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
    Assert.assertEquals(1, formElements.size());
    WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), null, form);
    BrowserConverterContext allowBrowserConverterContext = new BrowserConverterContext(wc, PushToServerEnum.allow);
    Map<String, Object> type = (Map<String, Object>) wc.getProperty("atype");
    Assert.assertEquals("name", type.get("name"));
    // it gets automatically translated to a static string
    Assert.assertEquals("OK", ((BasicTagStringTypeSabloValue) type.get("text")).getDesignValue());
    Assert.assertEquals("OK", ((BasicTagStringTypeSabloValue) type.get("text")).getTagReplacedValue());
    Assert.assertEquals(0, wc.getAndClearChanges().content.size());
    TypedData<Map<String, Object>> props = wc.getProperties();
    String json = JSONUtils.writeDataWithConversions(props.content, props.contentType, allowBrowserConverterContext);
    JSONAssert.assertEquals("{\"atype\":{\"rt\":\"my-component.mytype\",\"vEr\":2,\"v\":{\"text\":\"OK\",\"name\":\"name\"}},\"svyMarkupId\":\"sf331d64ddc0c17747371b7740e3e3447\",\"svy_types\":{\"atype\":\"JSON_obj\"}}", json, true);
}
Also used : Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) FormElement(com.servoy.j2db.server.ngclient.FormElement) WebComponent(com.servoy.j2db.persistence.WebComponent) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) ServoyDataConverterContext(com.servoy.j2db.server.ngclient.ServoyDataConverterContext) BrowserConverterContext(org.sablo.specification.property.BrowserConverterContext) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

ServoyDataConverterContext (com.servoy.j2db.server.ngclient.ServoyDataConverterContext)7 FormElement (com.servoy.j2db.server.ngclient.FormElement)6 IDataAdapterList (com.servoy.j2db.server.ngclient.IDataAdapterList)6 Form (com.servoy.j2db.persistence.Form)5 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)5 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Test (org.junit.Test)5 DataAdapterList (com.servoy.j2db.server.ngclient.DataAdapterList)4 CustomValueList (com.servoy.j2db.dataprocessing.CustomValueList)3 IValueList (com.servoy.j2db.dataprocessing.IValueList)3 ValueList (com.servoy.j2db.persistence.ValueList)3 Dimension (java.awt.Dimension)3 TabPanel (com.servoy.j2db.persistence.TabPanel)2 WebComponent (com.servoy.j2db.persistence.WebComponent)2 List (java.util.List)2 Field (com.servoy.j2db.persistence.Field)1 FormElementContext (com.servoy.j2db.server.ngclient.FormElementContext)1 IServoyDataConverterContext (com.servoy.j2db.server.ngclient.IServoyDataConverterContext)1