// deletePersonData()
// getPersonData()
public void testAppDataManager() throws Exception {
AppDataManagerImpl manager = new AppDataManagerImpl();
manager.setRegistry(registry);
Map<String, String> personData = new HashMap<String, String>();
personData.put("key1", "value1");
personData.put("key2", "value2");
personData.put("key3", "value3");
/* save person data */
manager.savePersonData("user1", "3", personData);
Map<String, Map<String, String>> dataMap1;
String[] userIds = new String[1];
userIds[0]="user1";
Set<String> fields = new HashSet<String>();
fields.add("key1");
fields.add("key2");
/* get person data */
dataMap1 = manager.getPersonData(userIds, null, "3", fields);
assertNotNull(dataMap1);
assertEquals(dataMap1.size(), 1);
assertEquals(dataMap1.get("user1").size(), 2);
assertTrue(dataMap1.get("user1").get("key1") != null && dataMap1.get("user1").get("key2") != null && dataMap1.get("user1").get("key1").equals("value1"));
assertNull(dataMap1.get("userC"));
userIds = new String[1];
userIds[0]="useC";
dataMap1 = manager.getPersonData(userIds, null, "3", fields);
// assertNull(dataMap1);
fields = new HashSet<String>();
fields.add("key1");
/* Delete person data */
manager.deletePersonData("user1", null, "3", fields);
userIds = new String[1];
userIds[0]="user1";
fields = new HashSet<String>();
fields.add("key1");
fields.add("key2");
fields.add("key3");
dataMap1 = manager.getPersonData(userIds, null, "3", fields);
assertNotNull(dataMap1);
assertNull(dataMap1.get("user1").get("key1"));
assertEquals(dataMap1.size(), 1);
assertEquals(2, dataMap1.get("user1").size());
assertTrue(dataMap1.get("user1").get("key3") != null && dataMap1.get("user1").get("key2") != null && dataMap1.get("user1").get("key3").equals("value3"));
personData = new HashMap<String, String>();
personData.put("key2", "newvalue2");
fields = new HashSet<String>();
fields.add("key2");
/* Update person data */
manager.updatePersonData("user1", null, "3", fields, personData);
fields = new HashSet<String>();
fields.add("key2");
dataMap1 = manager.getPersonData(userIds, null, "3", fields);
assertNotNull(dataMap1);
assertEquals(dataMap1.size(), 1);
assertEquals(1, dataMap1.get("user1").size());
assertEquals("newvalue2", dataMap1.get("user1").get("key2"));
/* value in fields but not in map */
personData = new HashMap<String, String>();
personData.put("key2", "newvalue2");
fields = new HashSet<String>();
fields.add("key2");
fields.add("key3");
manager.updatePersonData("user1", null, "3", fields, personData);
fields = new HashSet<String>();
fields.add("key2");
dataMap1 = manager.getPersonData(userIds, null, "3", fields);
assertNotNull(dataMap1);
assertNull(dataMap1.get("user1").get("key3")); // value for key3 should be deleted
}