use of com.servoy.j2db.server.ngclient.DataAdapterList 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);
}
Aggregations