1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2000,2008 Oracle. All rights reserved. 5 * 6 * $Id: CatalogCornerCaseTest.java,v 12.7 2008/02/07 17:12:32 mark Exp $ 7 */ 8package com.sleepycat.collections.test.serial; 9 10import junit.framework.Test; 11import junit.framework.TestCase; 12import junit.framework.TestSuite; 13 14import com.sleepycat.bind.serial.StoredClassCatalog; 15import com.sleepycat.compat.DbCompat; 16import com.sleepycat.db.Database; 17import com.sleepycat.db.DatabaseConfig; 18import com.sleepycat.db.Environment; 19import com.sleepycat.util.test.SharedTestUtils; 20import com.sleepycat.util.test.TestEnv; 21 22/** 23 * @author Mark Hayes 24 */ 25public class CatalogCornerCaseTest extends TestCase { 26 27 public static void main(String[] args) 28 throws Exception { 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 { 42 43 return new TestSuite(CatalogCornerCaseTest.class); 44 } 45 46 private Environment env; 47 48 public CatalogCornerCaseTest(String name) { 49 50 super(name); 51 } 52 53 public void setUp() 54 throws Exception { 55 56 SharedTestUtils.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 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 { 76 77 String 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 = 84 DbCompat.testOpenDatabase(env, null, file, null, config); 85 db.close(); 86 87 /* Open the empty database read-only. */ 88 config.setAllowCreate(false); 89 config.setReadOnly(true); 90 db = DbCompat.testOpenDatabase(env, null, file, null, config); 91 92 /* Expect exception when creating the catalog. */ 93 try { 94 new StoredClassCatalog(db); 95 fail(); 96 } catch (IllegalStateException e) { } 97 db.close(); 98 } 99} 100