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.HashMap;
021:
022: /**
023: * Test whether the store itself handles transactions well.
024: * @author Brautigam Robert
025: * @version Revision: $Revision$
026: */
027: public class InternalTransactionTests extends AbstractPersistenceTest {
028: public InternalTransactionTests(String name) throws Exception {
029: super (name);
030: }
031:
032: public void testSuccessfulSaveCommit() 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:
038: Transaction tx = store.getTransactionTracker().getTransaction(
039: TransactionTracker.TX_NEW);
040: tx.begin();
041: store.save(b);
042: tx.commit();
043:
044: List result = store.find("find book");
045: assertEquals(1, result.size());
046: }
047:
048: public void testSuccessfulSaveRollback() throws Exception {
049: // Drop
050: dropTables("book");
051: // Create
052: Book b = new Book("Learn brain surgery in 7 days", "1-2-3-4");
053:
054: Transaction tx = store.getTransactionTracker().getTransaction(
055: TransactionTracker.TX_NEW);
056: tx.begin();
057: store.save(b);
058: tx.rollback();
059:
060: List result = store.find("find book");
061: assertEquals(0, result.size());
062: }
063:
064: public void testUnsuccessfulSaveCommit() throws Exception {
065: // Drop
066: dropTables("mapholder");
067: // Create
068: MapHolder h = new MapHolder();
069: HashMap map = new HashMap();
070: map.put("book", new Book("Learn brain surgery in 7 days",
071: "1-2-3-4"));
072: map.put("wrong", new int[] { 1, 2 });
073: h.setMeta(map);
074: try {
075: store.save(h);
076: fail("saving a map with a reserved type succseeded.");
077: } catch (Exception e) {
078: }
079:
080: List result = store.find("find mapholder");
081: assertEquals(0, result.size());
082: }
083:
084: public void testSuccessfulRemoveCommit() throws Exception {
085: // Drop
086: dropTables("book");
087: // Create
088: Book b = new Book("Learn brain surgery in 7 days", "1-2-3-4");
089: store.save(b);
090:
091: Transaction tx = store.getTransactionTracker().getTransaction(
092: TransactionTracker.TX_NEW);
093: tx.begin();
094: store.remove(b);
095: tx.commit();
096:
097: List result = store.find("find book");
098: assertEquals(0, result.size());
099: }
100:
101: public void testSuccessfulRemoveRollback() throws Exception {
102: // Drop
103: dropTables("book");
104: // Create
105: Book b = new Book("Learn brain surgery in 7 days", "1-2-3-4");
106: store.save(b);
107:
108: Transaction tx = store.getTransactionTracker().getTransaction(
109: TransactionTracker.TX_NEW);
110: tx.begin();
111: store.remove(b);
112: tx.rollback();
113:
114: List result = store.find("find book");
115: assertEquals(1, result.size());
116: }
117:
118: }
|