1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2000-2009 Oracle. All rights reserved. 5 * 6 * $Id$ 7 */ 8package com.sleepycat.persist.test; 9 10import junit.framework.TestCase; 11 12import com.sleepycat.compat.DbCompat; 13import com.sleepycat.db.Environment; 14 15class PersistTestUtils { 16 17 /** 18 * Asserts than a database expectExists or does not exist. If keyName is 19 * null, checks an entity database. If keyName is non-null, checks a 20 * secondary database. 21 */ 22 static void assertDbExists(boolean expectExists, 23 Environment env, 24 String storeName, 25 String entityClassName, 26 String keyName) { 27 String fileName; 28 String dbName; 29 if (DbCompat.SEPARATE_DATABASE_FILES) { 30 fileName = storeName + '-' + entityClassName; 31 if (keyName != null) { 32 fileName += "-" + keyName; 33 } 34 dbName = null; 35 } else { 36 fileName = null; 37 dbName = "persist#" + storeName + '#' + entityClassName; 38 if (keyName != null) { 39 dbName += "#" + keyName; 40 } 41 } 42 boolean exists = DbCompat.databaseExists(env, fileName, dbName); 43 if (expectExists != exists) { 44 TestCase.fail 45 ((expectExists ? "Does not exist: " : "Does exist: ") + 46 dbName); 47 } 48 } 49} 50