* Tests deletion of items.
*
* @see PersistenceManagerIF#deleteItem
*/
public void testDeleteItem() {
ChannelIF channel = null;
ItemIF item1 = null;
ItemIF item2 = null;
try {
// Create channel with two items
channel = manager.createChannel(tuids1, url1);
item1 = manager.createItem(channel, tuids1);
item2 = manager.createItem(channel, tuids2);
// Delete first item
manager.deleteItem(item1);
// Check item and channel
assertEquals("Item ID should be in uninitialized state (-1).", -1, item1.getId());
final Collection items = channel.getItems();
assertNotNull(items);
assertEquals("Number of items in list is incorrect.", 1, items.size());
assertTrue("Wrong item was removed.", item2 == items.iterator().next());
} catch (PersistenceManagerException e) {
e.printStackTrace();
fail();
} finally {
// Delete items and channel
try {
if (item1 != null && item1.getId() != -1) manager.deleteItem(item1);
if (item2 != null && item2.getId() != -1) manager.deleteItem(item2);
if (channel != null && channel.getId() != -1) manager.deleteChannel(channel);
} catch (PersistenceManagerException e) {
// We can do nothing here.
}
}
}