001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.db4ounit.common.exceptions;
022:
023: import com.db4o.*;
024: import com.db4o.config.*;
025: import com.db4o.ext.*;
026:
027: import db4ounit.*;
028:
029: public class Db4oIOExceptionTestCase extends
030: Db4oIOExceptionTestCaseBase {
031:
032: public static void main(String[] args) {
033: new Db4oIOExceptionTestCase().runSolo();
034: }
035:
036: protected void configure(Configuration config) {
037: super .configure(config);
038: }
039:
040: public void testActivate() throws Exception {
041: store(new Item(3));
042: fixture().config().activationDepth(1);
043: fixture().reopen();
044: final Item item = (Item) retrieveOnlyInstance(Item.class);
045: Assert.expect(Db4oIOException.class, new CodeBlock() {
046: public void run() throws Throwable {
047: ExceptionIOAdapter.exception = true;
048: db().activate(item, 3);
049: }
050: });
051: }
052:
053: public void testClose() {
054: Assert.expect(Db4oIOException.class, new CodeBlock() {
055: public void run() throws Throwable {
056: ExceptionIOAdapter.exception = true;
057: db().close();
058: }
059: });
060: }
061:
062: public void testCommit() {
063: store(new Item(0));
064: Assert.expect(Db4oIOException.class, new CodeBlock() {
065: public void run() throws Throwable {
066: ExceptionIOAdapter.exception = true;
067: db().commit();
068: }
069: });
070: }
071:
072: public void testDelete() throws Exception {
073: store(new Item(3));
074: final Item item = (Item) retrieveOnlyInstance(Item.class);
075: Assert.expect(Db4oIOException.class, new CodeBlock() {
076: public void run() throws Throwable {
077: ExceptionIOAdapter.exception = true;
078: db().delete(item);
079: }
080: });
081: }
082:
083: public void testGet() throws Exception {
084: store(new Item(3));
085: Assert.expect(Db4oIOException.class, new CodeBlock() {
086: public void run() throws Throwable {
087: ExceptionIOAdapter.exception = true;
088: db().get(Item.class);
089: }
090: });
091: }
092:
093: public void testGetAll() throws Exception {
094: store(new Item(3));
095: Assert.expect(Db4oIOException.class, new CodeBlock() {
096: public void run() throws Throwable {
097: ExceptionIOAdapter.exception = true;
098: ObjectSet os = db().get(null);
099: while (os.hasNext()) {
100: os.next();
101: }
102: }
103: });
104: }
105:
106: public void testQuery() throws Exception {
107: store(new Item(3));
108: Assert.expect(Db4oIOException.class, new CodeBlock() {
109: public void run() throws Throwable {
110: ExceptionIOAdapter.exception = true;
111: db().query(Item.class);
112: }
113: });
114: }
115:
116: public void testRollback() throws Exception {
117: store(new Item(3));
118: Assert.expect(Db4oIOException.class, new CodeBlock() {
119: public void run() throws Throwable {
120: ExceptionIOAdapter.exception = true;
121: db().rollback();
122: }
123: });
124: }
125:
126: public void testSet() throws Exception {
127: Assert.expect(Db4oIOException.class, new CodeBlock() {
128: public void run() throws Throwable {
129: ExceptionIOAdapter.exception = true;
130: db().set(new Item(3));
131: }
132: });
133: }
134:
135: public void testGetByUUID() throws Exception {
136: fixture().config().generateUUIDs(ConfigScope.GLOBALLY);
137: fixture().reopen();
138: Item item = new Item(1);
139: store(item);
140: final Db4oUUID uuid = db().getObjectInfo(item).getUUID();
141: fixture().reopen();
142: Assert.expect(Db4oIOException.class, new CodeBlock() {
143: public void run() throws Throwable {
144: ExceptionIOAdapter.exception = true;
145: db().getByUUID(uuid);
146: }
147: });
148: }
149:
150: public static class Item {
151: public Item(int depth) {
152: member = new DeepMemeber(depth);
153: }
154:
155: public DeepMemeber member;
156: }
157:
158: public static class DeepMemeber {
159: public DeepMemeber(int depth) {
160: if (depth > 0) {
161: member = new DeepMemeber(--depth);
162: }
163: }
164:
165: public DeepMemeber member;
166: }
167:
168: }
|