01: /*
02: * Copyright 2002 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: ExtentTest.java,v 1.1 2003/01/08 17:22:35 pierreg0 Exp $
09: */
10:
11: package com.triactive.jdo.test;
12:
13: import java.util.Iterator;
14: import javax.jdo.PersistenceManager;
15: import javax.jdo.Transaction;
16: import javax.jdo.Extent;
17:
18: /**
19: * Tests <code>javax.jdo.Extent</code>
20: *
21: * @author <a href="mailto:jdb@getsu.com">J. David Beutel</a>
22: * @version $Revision: 1.1 $
23: */
24: public class ExtentTest extends PersistenceTestCase {
25: protected boolean schemaInitialized = false;
26:
27: /**
28: * Used by the JUnit framework to construct tests.
29: *
30: * @param name Name of the test case.
31: */
32: public ExtentTest(String name) {
33: super (name);
34: }
35:
36: protected void setUp() throws Exception {
37: super .setUp();
38:
39: if (!schemaInitialized) {
40: addClassesToSchema(new Class[] { Widget.class, });
41: schemaInitialized = true;
42: }
43: }
44:
45: public void testCloseAll() throws Exception {
46: PersistenceManager pm = pmf.getPersistenceManager();
47: Transaction tx = pm.currentTransaction();
48: try {
49: tx.begin();
50: Extent ex = pm.getExtent(Widget.class, /* subclasses = */
51: false);
52:
53: ex.closeAll(); // none open
54:
55: Iterator i = ex.iterator();
56: ex.closeAll(); // one open
57: assertEquals("iterator.hasNext() after extent.closeAll",
58: false, i.hasNext());
59:
60: ex.iterator();
61: ex.iterator();
62: ex.closeAll(); // two open
63:
64: tx.commit();
65: } finally {
66: if (tx.isActive())
67: tx.rollback();
68:
69: pm.close();
70: }
71: }
72: }
|