KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > collections > test > serial > CatalogCornerCaseTest


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2000,2006 Oracle. All rights reserved.
5  *
6  * $Id: CatalogCornerCaseTest.java,v 1.6 2006/10/30 21:14:39 bostic Exp $
7  */

8 package com.sleepycat.collections.test.serial;
9
10 import junit.framework.Test;
11 import junit.framework.TestCase;
12 import junit.framework.TestSuite;
13
14 import com.sleepycat.bind.serial.StoredClassCatalog;
15 import com.sleepycat.collections.test.DbTestUtil;
16 import com.sleepycat.collections.test.TestEnv;
17 import com.sleepycat.compat.DbCompat;
18 import com.sleepycat.je.Database;
19 import com.sleepycat.je.DatabaseConfig;
20 import com.sleepycat.je.Environment;
21
22 /**
23  * @author Mark Hayes
24  */

25 public class CatalogCornerCaseTest extends TestCase {
26
27     public static void main(String JavaDoc[] args)
28         throws Exception JavaDoc {
29
30         junit.framework.TestResult tr =
31             junit.textui.TestRunner.run(suite());
32         if (tr.errorCount() > 0 ||
33             tr.failureCount() > 0) {
34             System.exit(1);
35         } else {
36             System.exit(0);
37         }
38     }
39
40     public static Test suite()
41         throws Exception JavaDoc {
42
43         return new TestSuite(CatalogCornerCaseTest.class);
44     }
45
46     private Environment env;
47
48     public CatalogCornerCaseTest(String JavaDoc name) {
49
50         super(name);
51     }
52
53     public void setUp()
54         throws Exception JavaDoc {
55
56         DbTestUtil.printTestName(getName());
57         env = TestEnv.BDB.open(getName());
58     }
59
60     public void tearDown() {
61
62         try {
63             if (env != null) {
64                 env.close();
65             }
66         } catch (Exception JavaDoc e) {
67             System.out.println("Ignored exception during tearDown: " + e);
68         } finally {
69             /* Ensure that GC can cleanup. */
70             env = null;
71         }
72     }
73
74     public void testReadOnlyEmptyCatalog()
75         throws Exception JavaDoc {
76
77         String JavaDoc file = "catalog.db";
78
79         /* Create an empty database. */
80         DatabaseConfig config = new DatabaseConfig();
81         config.setAllowCreate(true);
82         DbCompat.setTypeBtree(config);
83         Database db = DbCompat.openDatabase(env, null, file, null, config);
84         db.close();
85
86         /* Open the empty database read-only. */
87         config.setAllowCreate(false);
88         config.setReadOnly(true);
89         db = DbCompat.openDatabase(env, null, file, null, config);
90
91         /* Expect exception when creating the catalog. */
92         try {
93             new StoredClassCatalog(db);
94             fail();
95         } catch (IllegalStateException JavaDoc e) { }
96         db.close();
97     }
98 }
99
Popular Tags