use of org.sablo.WebComponent 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);
}
use of org.sablo.WebComponent in project servoy-client by Servoy.
the class PropertySetTest method setColorProperty.
@Test
public void setColorProperty() throws Exception {
IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
Assert.assertNotNull(form);
Collection<WebComponent> components = form.getFormUI().getComponents();
Assert.assertEquals(1, components.size());
WebComponent comp = components.iterator().next();
Assert.assertEquals(Color.BLACK, comp.getProperty("background"));
JSONObject json = new JSONObject();
json.put("formname", "test");
json.put("beanname", comp.getName());
JSONObject changes = new JSONObject();
changes.put("background", "#0000FF");
json.put("changes", changes);
FormServiceHandler.INSTANCE.executeMethod("dataPush", json);
// should be changed.
Assert.assertEquals(Color.BLUE, comp.getProperty("background"));
changes.put("background", "#FF0000");
JSONObject oldvalues = new JSONObject();
oldvalues.put("background", "#0000FF");
json.put("oldvalues", oldvalues);
FormServiceHandler.INSTANCE.executeMethod("dataPush", json);
// should be changed, old value was really the old value.
Assert.assertEquals(Color.RED, comp.getProperty("background"));
changes.put("background", "#00FF00");
// should not be changed, still RED
FormServiceHandler.INSTANCE.executeMethod("dataPush", json);
Assert.assertEquals(Color.RED, comp.getProperty("background"));
}
use of org.sablo.WebComponent in project servoy-client by Servoy.
the class CustomArrayAndObjectPropertyRhinoTest method testCustomTypeJavaBasedRhinoChanges.
@Test
public void testCustomTypeJavaBasedRhinoChanges() throws JSONException {
Context.enter();
try {
WebComponent component = new WebComponent("mycomponent", "testComponentName");
BrowserConverterContext allowingBrowserConverterContext = new BrowserConverterContext(component, PushToServerEnum.allow);
PropertyDescription arrayTPD = component.getSpecification().getProperty("arrayT");
// just some initial checks and setting a java value
assertNull(component.getProperty("arrayT"));
List<Map<String, Object>> javaV = new ArrayList<>();
HashMap<String, Object> hm = new HashMap<String, Object>();
javaV.add(hm);
hm.put("text", "Just some text");
component.setProperty("arrayT", javaV);
// set should turn it into a change-aware list
Object wrapped = component.getProperty("arrayT");
assertTrue(wrapped instanceof ChangeAwareList<?, ?>);
ChangeAwareList<Map<String, Object>, Map<String, Object>> cal = (ChangeAwareList) wrapped;
assertEquals("Just some text", cal.get(0).get("text"));
assertTrue(cal.get(0) instanceof ChangeAwareMap<?, ?>);
ChangeAwareMap cam = ((ChangeAwareMap<?, ?>) cal.get(0));
Changes chMap = cam.getChanges();
ChangeAwareList<Map<String, Object>, Map<String, Object>>.Changes chList = cal.getChanges();
// TODO I guess this kind of reference changes should be treated in the BaseWebObject directly when we have separate methods for changesToJSON and fullToJSON
// so for now the change aware things do not report as being changed...
assertTrue(!chList.mustSendAll());
assertTrue(!chMap.mustSendAll());
// still the component has to see them as changed!
TypedData<Map<String, Object>> changes = component.getAndClearChanges();
assertTrue(changes.content.get("arrayT") != null);
assertTrue(changes.contentType.getProperty("arrayT").getType() instanceof CustomJSONArrayType);
Object arrayCh = changes.content.get("arrayT");
assertTrue(arrayCh != null);
assertTrue(changes.contentType.getProperty("arrayT").getType() instanceof CustomJSONArrayType);
Object mapCh = ((ChangeAwareList) arrayCh).get(0);
assertTrue(mapCh != null);
assertTrue(((CustomJSONPropertyType<?>) changes.contentType.getProperty("arrayT").getType()).getCustomJSONTypeDefinition().getType() instanceof CustomJSONObjectType);
JSONUtils.writeDataWithConversions(changes.content, changes.contentType, allowingBrowserConverterContext);
// ok now that we called component.getChanges() no changes should be present any more
assertTrue(!chList.mustSendAll());
assertTrue(!chMap.mustSendAll());
assertEquals(0, component.getAndClearChanges().content.size());
assertFalse(chList.getGranularUpdatesKeeper().hasChanges());
// check changing java => change reflected in Rhino
ScriptableObject topLevel = new ScriptableObject() {
@Override
public String getClassName() {
return "test_top_level_scope";
}
};
Scriptable rhinoVal = (Scriptable) NGConversions.INSTANCE.convertSabloComponentToRhinoValue(component.getProperty("arrayT"), arrayTPD, component, topLevel);
assertEquals("Just some text", ((Scriptable) rhinoVal.get(0, rhinoVal)).get("text", rhinoVal));
cam.put("text", "Just some text 2");
assertEquals(1, chMap.getKeysChangedByRef().size());
assertEquals("text", chMap.getKeysChangedByRef().iterator().next());
ArrayOperation[] opSeq = chList.getGranularUpdatesKeeper().getEquivalentSequenceOfOperations();
assertEquals(1, opSeq.length);
assertGranularOpIs(0, 0, ArrayOperation.CHANGE, ChangeAwareList.GRANULAR_UPDATE_OP, opSeq[0]);
assertTrue(!chList.mustSendAll());
assertTrue(!chMap.mustSendAll());
assertEquals("Just some text 2", ((Scriptable) rhinoVal.get(0, rhinoVal)).get("text", rhinoVal));
cam.put("active", new ArrayList());
assertTrue(!chList.mustSendAll());
assertTrue(!chMap.mustSendAll());
assertEquals(2, chMap.getKeysChangedByRef().size());
assertTrue(chMap.getKeysChangedByRef().contains("text"));
assertTrue(chMap.getKeysChangedByRef().contains("active"));
cam.remove("active");
assertTrue(!chList.mustSendAll());
assertTrue(chMap.mustSendAll());
cal.add(new HashMap<String, Object>());
ChangeAwareMap cam1 = ((ChangeAwareMap<?, ?>) cal.get(1));
assertFalse(chList.mustSendAll());
opSeq = chList.getGranularUpdatesKeeper().getEquivalentSequenceOfOperations();
assertEquals(2, opSeq.length);
assertGranularOpIs(0, 0, ArrayOperation.CHANGE, ChangeAwareList.GRANULAR_UPDATE_OP, opSeq[0]);
assertGranularOpIs(1, 1, ArrayOperation.INSERT, null, opSeq[1]);
assertTrue(chMap.mustSendAll());
// ok clear changes
changes = component.getAndClearChanges();
JSONUtils.writeDataWithConversions(changes.content, changes.contentType, allowingBrowserConverterContext);
assertEquals(1, changes.content.size());
assertEquals(0, component.getAndClearChanges().content.size());
assertTrue(!chList.mustSendAll());
assertTrue(!chMap.mustSendAll());
assertFalse(chList.getGranularUpdatesKeeper().hasChanges());
assertEquals(0, chMap.getKeysChangedByRef().size());
assertEquals(0, chMap.getKeysWithUpdates().size());
// assign some native values
Scriptable oneO = Context.getCurrentContext().newObject(topLevel);
Scriptable activeA1 = Context.getCurrentContext().newArray(topLevel, 0);
Scriptable activeA1Obj = Context.getCurrentContext().newObject(topLevel);
rhinoVal.put(0, rhinoVal, oneO);
// same as 'cam' but in it's Rhino representation
Scriptable oneOScriptable = (Scriptable) rhinoVal.get(0, rhinoVal);
assertTrue(!chList.mustSendAll());
opSeq = chList.getGranularUpdatesKeeper().getEquivalentSequenceOfOperations();
assertEquals(1, opSeq.length);
assertGranularOpIs(0, 0, ArrayOperation.CHANGE, null, opSeq[0]);
cam = ((ChangeAwareMap<?, ?>) cal.get(0));
chMap = cam.getChanges();
activeA1Obj.put("field", activeA1Obj, 11);
activeA1.put(0, activeA1, activeA1Obj);
oneOScriptable.put("active", oneOScriptable, activeA1);
assertEquals(11, ((Map) ((List) ((Map) cal.get(0)).get("active")).get(0)).get("field"));
((Map) ((List) ((Map) cal.get(0)).get("active")).get(0)).put("percent", 0.22);
assertEquals(1, chMap.getKeysChangedByRef().size());
assertEquals(0, chMap.getKeysWithUpdates().size());
assertTrue(chMap.getKeysChangedByRef().contains("active"));
assertTrue(!chList.mustSendAll());
opSeq = chList.getGranularUpdatesKeeper().getEquivalentSequenceOfOperations();
assertEquals(1, opSeq.length);
assertGranularOpIs(0, 0, ArrayOperation.CHANGE, null, opSeq[0]);
// now change the native values using initial ref to see if it changed in java; this is no longer supported after case SVY-11027
// activeA1Obj.put("field", activeA1Obj, 98);
// assertEquals(98, ((Map)((List)((Map)cal.get(0)).get("active")).get(0)).get("field"));
// activeA1.put(1, activeA1, activeA2Obj);
// activeA2Obj.put("field", activeA2Obj, 45);
// assertEquals(45, ((Map)((List)((Map)cal.get(0)).get("active")).get(1)).get("field"));
changes = component.getAndClearChanges();
String msg = JSONUtils.writeChangesWithConversions(changes.content, changes.contentType, allowingBrowserConverterContext);
JSONAssert.assertEquals("{\"arrayT\":{\"vEr\":3,\"g\":[{\"op\":[0,0,0],\"d\":[{\"rt\":\"mycomponent.mytype007\",\"vEr\":5,\"v\":{\"active\":{\"vEr\":2,\"v\":[{\"rt\":\"mycomponent.activeType\",\"vEr\":2,\"v\":{\"field\":11,\"percent\":0.22}}],\"svy_types\":{\"0\":\"JSON_obj\"}}},\"svy_types\":{\"active\":\"JSON_arr\"}}],\"svy_types\":{\"0\":\"JSON_obj\"}}]},\"svy_types\":{\"arrayT\":\"JSON_arr\"}}", msg, JSONCompareMode.NON_EXTENSIBLE);
((Map) ((List) ((Map) cal.get(0)).get("active")).get(0)).put("percent", 0.33);
assertEquals(0, chMap.getKeysChangedByRef().size());
assertEquals(1, chMap.getKeysWithUpdates().size());
changes = component.getAndClearChanges();
msg = JSONUtils.writeChangesWithConversions(changes.content, changes.contentType, allowingBrowserConverterContext);
JSONAssert.assertEquals("{\"arrayT\":{\"vEr\":3,\"g\":[{\"op\":[0,0,0],\"d\":[{\"rt\":\"mycomponent.mytype007\",\"vEr\":5,\"u\":[{\"k\":\"active\",\"v\":{\"vEr\":2,\"g\":[{\"op\":[0,0,0],\"d\":[{\"rt\":\"mycomponent.activeType\",\"vEr\":2,\"u\":[{\"k\":\"percent\",\"v\":0.33}]}],\"svy_types\":{\"0\":\"JSON_obj\"}}]}}],\"svy_types\":{\"0\":{\"v\":\"JSON_arr\"}}}],\"svy_types\":{\"0\":\"JSON_obj\"}}]},\"svy_types\":{\"arrayT\":\"JSON_arr\"}}", msg, JSONCompareMode.NON_EXTENSIBLE);
((List) ((Map) cal.get(0)).get("active")).add(new HashMap<String, Object>());
((Map) ((List) ((Map) cal.get(0)).get("active")).get(1)).put("percent", 0.99);
component.getAndClearChanges();
// now simulate another request cycle that makes some change to the property from javascript
rhinoVal = (Scriptable) NGConversions.INSTANCE.convertSabloComponentToRhinoValue(component.getProperty("arrayT"), arrayTPD, component, topLevel);
Scriptable v = ((Scriptable) rhinoVal.get(0, rhinoVal));
v = (Scriptable) v.get("active", v);
v = (Scriptable) v.get(1, v);
assertEquals(0.99, v.get("percent", v));
v.put("percent", v, 0.56);
assertEquals(0.56, ((Map) ((List) ((Map) cal.get(0)).get("active")).get(1)).get("percent"));
assertTrue(!chMap.mustSendAll());
assertTrue(!chList.mustSendAll());
opSeq = chList.getGranularUpdatesKeeper().getEquivalentSequenceOfOperations();
assertEquals(1, opSeq.length);
assertGranularOpIs(0, 0, ArrayOperation.CHANGE, ChangeAwareList.GRANULAR_UPDATE_OP, opSeq[0]);
assertEquals(1, chMap.getKeysWithUpdates().size());
assertEquals("active", chMap.getKeysWithUpdates().iterator().next());
} finally {
Context.exit();
}
}
use of org.sablo.WebComponent in project servoy-client by Servoy.
the class CustomArrayAndObjectPropertyRhinoTest method seeThatNormalArraysAndCustomObjectsKeepNullsAsExpected.
@Test
public void seeThatNormalArraysAndCustomObjectsKeepNullsAsExpected() throws JSONException {
WebComponent component = new WebComponent("mycomponent", "testComponentName");
PropertyDescription normalArrayPD = component.getSpecification().getProperty("normalArray");
checkNormalArraysAndCustomObjectsWithNullValues(component, normalArrayPD);
}
use of org.sablo.WebComponent in project servoy-client by Servoy.
the class CustomArrayAndObjectPropertyRhinoTest method seeThatNormalArraysAndCustomObjectsWithIrrelevantConfigKeepNullsAsExpected.
@Test
public void seeThatNormalArraysAndCustomObjectsWithIrrelevantConfigKeepNullsAsExpected() throws JSONException {
WebComponent component = new WebComponent("mycomponent", "testComponentName");
PropertyDescription normalArrayPD = component.getSpecification().getProperty("normalArrayWithConfig");
checkNormalArraysAndCustomObjectsWithNullValues(component, normalArrayPD);
}
Aggregations