01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package com.db4o.db4ounit.common.config;
22:
23: import java.io.*;
24:
25: import com.db4o.*;
26: import com.db4o.config.*;
27: import com.db4o.internal.*;
28:
29: import db4ounit.*;
30: import db4ounit.extensions.*;
31:
32: public class NonStaticConfigurationTestCase implements Db4oTestCase {
33:
34: public static void main(String[] args) {
35: new TestRunner(NonStaticConfigurationTestCase.class).run();
36: }
37:
38: public void setUp() throws Exception {
39: new File(FILENAME).delete();
40: }
41:
42: public void tearDown() throws Exception {
43: new File(FILENAME).delete();
44: }
45:
46: public static class Data {
47: public int id;
48:
49: public Data(int id) {
50: this .id = id;
51: }
52: }
53:
54: private static final String FILENAME = "nonstaticcfg.yap";
55:
56: public void testOpenWithNonStaticConfiguration() {
57: final Configuration config1 = Db4o.newConfiguration();
58: config1.readOnly(true);
59: Assert.expect(DatabaseReadOnlyException.class, new CodeBlock() {
60: public void run() throws Throwable {
61: Db4o.openFile(config1, FILENAME);
62: }
63: });
64: config1.readOnly(false);
65: final ObjectContainer db1 = Db4o.openFile(config1, FILENAME);
66: config1.readOnly(true);
67: try {
68: Assert.expect(DatabaseReadOnlyException.class,
69: new CodeBlock() {
70: public void run() throws Throwable {
71: db1.set(new Data(1));
72: }
73: });
74: } finally {
75: db1.close();
76: }
77:
78: Configuration config2 = Db4o.newConfiguration();
79: ObjectContainer db2 = Db4o.openFile(config2, FILENAME);
80: try {
81: db2.set(new Data(2));
82: Assert.areEqual(1, db2.query(Data.class).size());
83: } finally {
84: db2.close();
85: }
86: }
87:
88: public void testIndependentObjectConfigs() {
89: Configuration config = Db4o.newConfiguration();
90: ObjectClass objectConfig = config.objectClass(Data.class);
91: objectConfig.translate(new TNull());
92: Configuration otherConfig = Db4o.newConfiguration();
93: Assert.areNotSame(config, otherConfig);
94: Config4Class otherObjectConfig = (Config4Class) otherConfig
95: .objectClass(Data.class);
96: Assert.areNotSame(objectConfig, otherObjectConfig);
97: Assert.isNull(otherObjectConfig.getTranslator());
98: }
99: }
|