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 com.db4o.*;
24: import com.db4o.config.*;
25: import com.db4o.foundation.io.*;
26: import com.db4o.reflect.*;
27: import com.db4o.reflect.jdk.*;
28: import com.db4o.test.util.*;
29:
30: import db4ounit.*;
31:
32: public class GenericArrayFieldTypeTestCase implements TestLifeCycle {
33:
34: public static class SubData {
35: public int _id;
36:
37: public SubData(int id) {
38: _id = id;
39: }
40: }
41:
42: public static class Data {
43: public SubData[] _data;
44:
45: public Data(SubData[] data) {
46: _data = data;
47: }
48: }
49:
50: private static final String FILENAME = "genericarray.db4o";
51:
52: public void testGenericArrayFieldType() {
53: Class[] excludedClasses = new Class[] { Data.class,
54: SubData.class, };
55: ClassLoader loader = new ExcludingClassLoader(getClass()
56: .getClassLoader(), excludedClasses);
57: Configuration config = Db4o.newConfiguration();
58: config.reflectWith(new JdkReflector(loader));
59: ObjectContainer db = Db4o.openFile(config, FILENAME);
60: try {
61: ReflectClass dataClazz = db.ext().reflector().forName(
62: Data.class.getName());
63: ReflectField field = dataClazz.getDeclaredField("_data");
64: ReflectClass fieldType = field.getFieldType();
65: Assert.isTrue(fieldType.isArray());
66: ReflectClass componentType = fieldType.getComponentType();
67: Assert.areEqual(SubData.class.getName(), componentType
68: .getName());
69: } finally {
70: db.close();
71: }
72: }
73:
74: private void store() {
75: ObjectContainer db = Db4o.openFile(Db4o.newConfiguration(),
76: FILENAME);
77: SubData[] subData = { new SubData(1), new SubData(42), };
78: Data data = new Data(subData);
79: db.set(data);
80: db.close();
81: }
82:
83: private void deleteFile() {
84: File4.delete(FILENAME);
85: }
86:
87: public void setUp() throws Exception {
88: deleteFile();
89: store();
90: }
91:
92: public void tearDown() throws Exception {
93: deleteFile();
94: }
95: }
|