001: /**
002: * Copyright (C) 2006 NetMind Consulting Bt.
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 3 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package hu.netmind.persistence;
018:
019: import java.util.List;
020: import java.util.Vector;
021:
022: /**
023: * Test the remove function of Store.
024: * @author Brautigam Robert
025: * @version Revision: $Revision$
026: */
027: public class RemoveTests extends AbstractPersistenceTest {
028: public RemoveTests(String name) throws Exception {
029: super (name);
030: }
031:
032: public void testSimpleRemove() throws Exception {
033: // Drop
034: dropTables("book");
035: // Create
036: Book b = new Book("Learn brain surgery in 7 days", "1-2-3-4");
037: store.save(b);
038: // Get back
039: List result = store.find("find book");
040: assertEquals(1, result.size());
041: // Remove
042: store.remove(b);
043: result = store.find("find book");
044: assertEquals(0, result.size());
045: // Insert again
046: store.save(b);
047: result = store.find("find book");
048: assertEquals(1, result.size());
049: }
050:
051: public void testRemoveNonExistentObject() throws Exception {
052: // Drop
053: dropTables("book");
054: // Create
055: Book b = new Book("Learn brain surgery in 7 days", "1-2-3-4");
056: List result = store.find("find book");
057: assertEquals(0, result.size());
058: store.remove(b);
059: result = store.find("find book");
060: assertEquals(0, result.size());
061: }
062:
063: public void testRemoveReferencedObject() throws Exception {
064: // Drop
065: dropTables("book");
066: dropTables("author");
067: // Create
068: Book b = new Book("Learn brain surgery in 7 days", "1-2-3-4");
069: Author a = new Author("Freddy", "Krueger");
070: b.setMainAuthor(a);
071: // Save
072: store.save(b);
073: // Now remove
074: store.remove(a);
075: // Check
076: List result = store.find("find book");
077: assertEquals(1, result.size());
078: assertEquals(b, result.get(0));
079: assertNull(((Book) result.get(0)).getMainAuthor());
080: }
081:
082: public void testRemoveListedObject() throws Exception {
083: // Drop
084: dropTables("book");
085: dropTables("author");
086: // Create
087: Book b = new Book("Learn brain surgery in 7 days", "1-2-3-4");
088: Author a = new Author("Freddy", "Krueger");
089: Vector v = new Vector();
090: v.add(a);
091: b.setAuthors(v);
092: // Save
093: store.save(b);
094: // Now remove
095: store.remove(a);
096: // Check
097: List result = store.find("find book");
098: assertEquals(1, result.size());
099: assertEquals(b, result.get(0));
100: assertEquals(0, ((Book) result.get(0)).getAuthors().size());
101: }
102: }
|