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.jre11.assorted;
22:
23: import java.io.IOException;
24:
25: import com.db4o.*;
26: import com.db4o.config.ConfigScope;
27: import com.db4o.db4ounit.common.assorted.UUIDTestItem;
28: import com.db4o.db4ounit.util.*;
29: import com.db4o.foundation.Hashtable4;
30: import com.db4o.foundation.io.*;
31:
32: import db4ounit.*;
33: import db4ounit.extensions.fixtures.*;
34:
35: /**
36: * @exclude
37: */
38: public class UUIDMigrationTestCase implements TestCase,
39: OptOutNoFileSystemData {
40:
41: public static void main(String[] args) {
42: new TestRunner(UUIDMigrationTestCase.class).run();
43: }
44:
45: public void test() throws Exception {
46: configure();
47: try {
48: final ObjectContainer container = Db4o
49: .openFile(getUUIDMigrationSourcePath());
50: try {
51: Assert.isNotNull(container);
52:
53: final Hashtable4 uuidCache = new Hashtable4();
54:
55: UUIDTestItem.assertItemsCanBeRetrievedByUUID(container
56: .ext(), uuidCache);
57: Assert.areEqual(2, uuidCache.size());
58:
59: UUIDTestItem.assertItemsCanBeRetrievedByUUID(container
60: .ext(), uuidCache);
61: } finally {
62: if (null != container)
63: container.close();
64: }
65:
66: } finally {
67: restoreConfiguration();
68: }
69: }
70:
71: private String getUUIDMigrationSourcePath() throws IOException {
72: final String fileName = "UUIDMigrationSource-db4o-5.5.yap";
73: final String sourceFile = WorkspaceServices
74: .workspaceTestFilePath("uuid/" + fileName);
75: String targetFile = IOServices.buildTempPath(fileName);
76: File4.copy(sourceFile, targetFile);
77: return targetFile;
78: }
79:
80: private void restoreConfiguration() {
81: Db4o.configure().allowVersionUpdates(false);
82: Db4o.configure().generateUUIDs(ConfigScope.DISABLED);
83: }
84:
85: private void configure() {
86: Db4o.configure().allowVersionUpdates(true);
87: Db4o.configure().generateUUIDs(ConfigScope.GLOBALLY);
88: }
89: }
|