KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > persist > test > PersistTestUtils


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2000,2006 Oracle. All rights reserved.
5  *
6  * $Id: PersistTestUtils.java,v 1.1 2006/11/16 04:18:21 mark Exp $
7  */

8 package com.sleepycat.persist.test;
9
10 import java.util.List JavaDoc;
11
12 import junit.framework.TestCase;
13
14 import com.sleepycat.je.DatabaseException;
15 import com.sleepycat.je.Environment;
16
17 class PersistTestUtils {
18
19     /**
20      * Asserts than a database expectExists or does not exist. If keyName is
21      * null, checks an entity database. If keyName is non-null, checks a
22      * secondary database.
23      */

24     static void assertDbExists(boolean expectExists,
25                                Environment env,
26                                String JavaDoc storeName,
27                                String JavaDoc entityClassName,
28                                String JavaDoc keyName) {
29         String JavaDoc dbName = "persist#" + storeName + '#' + entityClassName;
30         if (keyName != null) {
31             dbName += "#" + keyName;
32         }
33         List JavaDoc allDbNames;
34         try {
35             allDbNames = env.getDatabaseNames();
36         } catch (DatabaseException e) {
37             throw new RuntimeException JavaDoc(e);
38         }
39         if (expectExists != allDbNames.contains(dbName)) {
40             TestCase.fail
41                 ((expectExists ? "Does not exist: " : "Does exist: ") +
42                  dbName);
43         }
44     }
45 }
46
Popular Tags