KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > ExtMethods


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 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.test;
22
23 import com.db4o.ext.*;
24
25 public class ExtMethods {
26     
27     public void test(){
28         
29         ExtMethods em = new ExtMethods();
30         Test.store(em);
31         
32         ExtObjectContainer eoc = Test.objectContainer();
33         
34         Test.ensure(! eoc.isClosed());
35         
36         Test.ensure(eoc.isActive(em));
37         Test.ensure(eoc.isStored(em));
38         
39         eoc.deactivate(em, 1);
40         Test.ensure(! eoc.isActive(em));
41         
42         eoc.activate(em, 1);
43         Test.ensure(eoc.isActive(em));
44         
45         long id = eoc.getID(em);
46         
47         Test.ensure(eoc.isCached(id));
48         
49         eoc.purge(em);
50         
51         Test.ensure(! eoc.isCached(id));
52         Test.ensure(! eoc.isStored(em));
53         Test.ensure(! eoc.isActive(em));
54         
55         eoc.bind(em, id);
56         
57         Test.ensure(eoc.isCached(id));
58         Test.ensure(eoc.isStored(em));
59         Test.ensure(eoc.isActive(em));
60         
61         ExtMethods em2 = (ExtMethods)eoc.getByID(id);
62         
63         Test.ensure(em == em2);
64         
65         // Purge all and try again
66
eoc.purge();
67         
68         Test.ensure(eoc.isCached(id));
69         Test.ensure(eoc.isStored(em));
70         Test.ensure(eoc.isActive(em));
71         
72         em2 = (ExtMethods)eoc.getByID(id);
73         Test.ensure(em == em2);
74         
75         Test.delete(em2);
76         Test.commit();
77         Test.ensure(! eoc.isCached(id));
78         Test.ensure(! eoc.isStored(em2));
79         Test.ensure(! eoc.isActive(em2));
80         
81         // Null checks
82
Test.ensure(! eoc.isStored(null));
83         Test.ensure(! eoc.isActive(null));
84         Test.ensure(! eoc.isCached(0));
85         
86     }
87
88 }
89
Popular Tags