Map props = new HashMap();
props.put("name1", "value1");
props.put("name2", "value2");
byte[] content = "Dummy content".getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(content);
GFileTO fileTO = new GFileTO(path, props, in);
GFileDAO fileDAO = new LocalGFileDAO(root);
// Create.
fileDAO.create(fileTO);
// Read.
fileTO = fileDAO.read(path);
assertEquals("Wrong path", path, fileTO.getPath());
props = fileTO.getProperties();
assertEquals("Wrong # of properties", 2, props.size());
for (Iterator iter = props.entrySet().iterator(); iter.hasNext();) {
Map.Entry property = (Map.Entry) iter.next();
String name = (String) property.getKey();
if ( name.equals("name1") ) {
assertEquals("Wrong value", "value1", property.getValue());
} else if ( name.equals("name2") ) {
assertEquals("Wrong value", "value2", property.getValue());
} else {
assertTrue("Wrong property name {" + name + "}", false);
}
}
// Update
props.put("name3", "value3");
fileDAO.update(fileTO);
fileTO = fileDAO.read(path);
props = fileTO.getProperties();
assertEquals("Wrong # of properties", 3, props.size());
// Delete
fileDAO.delete(path);
fileTO = fileDAO.read(path);
assertFalse("Should not exist.", fileTO.exists());
}