public void performCRUDTest(String objectTypeName) throws Exception { try { s_log.info("CRUDTest on " + objectTypeName); DataObject object = SessionManager.getSession().create(objectTypeName); reportPropertyTypes(object); initializeObject(object, null); OID id = object.getOID(); s_log.info("Initialized object with id: " + id); object.save(); object = SessionManager.getSession().retrieve(id); Assert.assertNotNull( object, "Object of type: " + objectTypeName + "and id: " + id + " was not found!"); checkDefaultValues(object); checkUpdates(object, null); deleteObject(id); } catch (Exception e) { s_log.info("END CRUDTest on " + objectTypeName + " With error!"); s_log.info(e.getMessage()); s_log.info(""); s_log.info(""); throw e; } s_log.info("END CRUDTest on " + objectTypeName); s_log.info(""); s_log.info(""); }
private void deleteObject(OID id) throws Exception { // Manipulator for removing associations before delete PropertyManipulator.AssociationManipulator assocRemover = new PropertyManipulator.AssociationManipulator() { public void manipulate(Property p, DataObject data) throws Exception { s_log.info("Found association: " + p.getName()); if (p.isCollection()) { DataAssociation assoc = (DataAssociation) data.get(p.getName()); DataAssociationCursor cursor = assoc.cursor(); while (cursor.next()) { s_log.info( "Removing from association: " + cursor.getDataObject().getObjectType().getName()); cursor.remove(); s_log.info("Removed!"); } } } }; DataObject data = SessionManager.getSession().retrieve(id); s_log.info(""); String objectName = data.getObjectType().getName(); s_log.info("Deleting object: " + objectName + " with OID: " + data.getOID()); PropertyManipulator.manipulateProperties(data, assocRemover); s_log.info("daving data!"); data.save(); s_log.info("about to delete!"); data.delete(); Assert.truth(data.isDeleted()); data = SessionManager.getSession().retrieve(id); Assert.truth(null == data); s_log.info("END Removing object: " + objectName); s_log.info(""); }