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.exceptions;
22:
23: import java.io.IOException;
24:
25: import com.db4o.*;
26: import com.db4o.db4ounit.util.IOServices;
27: import com.db4o.db4ounit.util.WorkspaceServices;
28: import com.db4o.ext.OldFormatException;
29: import com.db4o.foundation.io.File4;
30: import com.db4o.internal.Platform4;
31:
32: import db4ounit.*;
33: import db4ounit.extensions.fixtures.OptOutNoFileSystemData;
34:
35: /**
36: * @exclude
37: */
38: public class OldFormatExceptionTestCase implements TestCase,
39: OptOutNoFileSystemData {
40:
41: public static void main(String[] args) {
42: new TestRunner(OldFormatExceptionTestCase.class).run();
43: }
44:
45: // It is also regression test for COR-634.
46:
47: public void test() throws Exception {
48: if (WorkspaceServices.workspaceRoot() == null) {
49: System.err
50: .println("Build environment not available. Skipping test case...");
51: return;
52: }
53: if (!File4.exists(sourceFile())) {
54: System.err.println("Test source file " + sourceFile()
55: + " not available. Skipping test case...");
56: return;
57: }
58:
59: Db4o
60: .configure()
61: .reflectWith(
62: Platform4
63: .reflectorForType(OldFormatExceptionTestCase.class));
64:
65: Db4o.configure().allowVersionUpdates(false);
66: final String oldDatabaseFilePath = oldDatabaseFilePath();
67:
68: Assert.expect(OldFormatException.class, new CodeBlock() {
69: public void run() throws Throwable {
70: Db4o.openFile(oldDatabaseFilePath);
71: }
72: });
73:
74: Db4o.configure().allowVersionUpdates(true);
75: ObjectContainer container = null;
76: try {
77: container = Db4o.openFile(oldDatabaseFilePath);
78: } finally {
79: if (container != null) {
80: container.close();
81: }
82: }
83: }
84:
85: protected String oldDatabaseFilePath() throws IOException {
86: final String oldFile = IOServices.buildTempPath("old_db.yap");
87: File4.copy(sourceFile(), oldFile);
88: return oldFile;
89: }
90:
91: private String sourceFile() {
92: return WorkspaceServices
93: .workspaceTestFilePath("db4oVersions/db4o_3.0.3");
94: }
95:
96: }
|