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.jre12.assorted;
22:
23: import java.io.*;
24: import java.math.*;
25:
26: import com.db4o.*;
27: import com.db4o.config.*;
28:
29: import db4ounit.*;
30:
31: public class TranslatorStoredClassesTestCase implements TestCase {
32:
33: private final static String FILENAME = "translator.yap";
34:
35: public static class DataRawChild implements Serializable {
36: public int _id;
37:
38: public DataRawChild(int id) {
39: _id = id;
40: }
41: }
42:
43: public static class DataRawParent {
44: public DataRawChild _child;
45:
46: public DataRawParent(int id) {
47: _child = new DataRawChild(id);
48: }
49: }
50:
51: public static class DataBigDecimal {
52: public BigDecimal _bd;
53:
54: public DataBigDecimal(int id) {
55: _bd = new BigDecimal(String.valueOf(id));
56: }
57: }
58:
59: public void testBigDecimal() {
60: assertStoredClassesAfterTranslator(BigDecimal.class,
61: new DataBigDecimal(42));
62: }
63:
64: public void testRaw() {
65: assertStoredClassesAfterTranslator(DataRawChild.class,
66: new DataRawParent(42));
67: }
68:
69: public void assertStoredClassesAfterTranslator(Class translated,
70: Object data) {
71: createFile(translated, data);
72: check(translated);
73: }
74:
75: private static void createFile(Class translated, Object data) {
76: new File(FILENAME).delete();
77: ObjectContainer server = db(translated, new TSerializable());
78: server.set(data);
79: server.close();
80: }
81:
82: private static void check(Class translated) {
83: ObjectContainer db = db(translated, null);
84: db.ext().storedClasses();
85: db.close();
86: }
87:
88: private static ObjectContainer db(Class translated,
89: ObjectTranslator translator) {
90: Configuration config = Db4o.newConfiguration();
91: config.objectClass(translated).translate(translator);
92: return Db4o.openFile(config, FILENAME);
93: }
94:
95: }
|