connection.setLastUpdateUser("user");
connection.setLastUpdateDate(updated);
connection.setEnabled(false);
// Fill some data at the beginning
MStringInput input = (MStringInput) connection.getConnectorPart().getForms()
.get(0).getInputs().get(0);
input.setValue("Hi there!");
// Serialize it to JSON object
ConnectionBean bean = new ConnectionBean(connection);
JSONObject json = bean.extract(false);
// Check for sensitivity
JSONArray all = (JSONArray)json.get("all");
JSONObject allItem = (JSONObject)all.get(0);
JSONArray connectors = (JSONArray)allItem.get("connector");
JSONObject connector = (JSONObject)connectors.get(0);
JSONArray inputs = (JSONArray)connector.get("inputs");
for (Object input1 : inputs) {
assertTrue(((JSONObject)input1).containsKey("sensitive"));
}
// "Move" it across network in text form
String string = json.toJSONString();
// Retrieved transferred object
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string);
ConnectionBean retrievedBean = new ConnectionBean();
retrievedBean.restore(retrievedJson);
MConnection target = retrievedBean.getConnections().get(0);
// Check id and name
assertEquals(666, target.getPersistenceId());
assertEquals("Connection", target.getName());
assertEquals("admin", target.getCreationUser());
assertEquals(created, target.getCreationDate());
assertEquals("user", target.getLastUpdateUser());
assertEquals(updated, target.getLastUpdateDate());
assertEquals(false, target.getEnabled());
// Test that value was correctly moved
MStringInput targetInput = (MStringInput) target.getConnectorPart()
.getForms().get(0).getInputs().get(0);
assertEquals("Hi there!", targetInput.getValue());
}