KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > test > ExtentTest


1 /*
2  * Copyright 2002 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: ExtentTest.java,v 1.1 2003/01/08 17:22:35 pierreg0 Exp $
9  */

10
11 package com.triactive.jdo.test;
12
13 import java.util.Iterator JavaDoc;
14 import javax.jdo.PersistenceManager;
15 import javax.jdo.Transaction;
16 import javax.jdo.Extent;
17
18
19 /**
20  * Tests <code>javax.jdo.Extent</code>
21  *
22  * @author <a HREF="mailto:jdb@getsu.com">J. David Beutel</a>
23  * @version $Revision: 1.1 $
24  */

25 public class ExtentTest extends PersistenceTestCase
26 {
27     protected boolean schemaInitialized = false;
28
29     /**
30      * Used by the JUnit framework to construct tests.
31      *
32      * @param name Name of the test case.
33      */

34     public ExtentTest(String JavaDoc name)
35     {
36         super(name);
37     }
38
39
40     protected void setUp() throws Exception JavaDoc
41     {
42         super.setUp();
43
44         if (!schemaInitialized)
45         {
46             addClassesToSchema(new Class JavaDoc[]
47                 {
48                     Widget.class,
49                 }
50             );
51             schemaInitialized = true;
52         }
53     }
54
55
56     public void testCloseAll() throws Exception JavaDoc
57     {
58         PersistenceManager pm = pmf.getPersistenceManager();
59         Transaction tx = pm.currentTransaction();
60         try
61         {
62             tx.begin();
63             Extent ex = pm.getExtent( Widget.class, /* subclasses = */ false );
64
65             ex.closeAll(); // none open
66

67             Iterator JavaDoc i = ex.iterator();
68             ex.closeAll(); // one open
69
assertEquals( "iterator.hasNext() after extent.closeAll", false, i.hasNext() );
70
71             ex.iterator();
72             ex.iterator();
73             ex.closeAll(); // two open
74

75             tx.commit();
76         }
77         finally
78         {
79             if (tx.isActive())
80                 tx.rollback();
81
82             pm.close();
83         }
84     }
85 }
86
Popular Tags