Imported Upstream version 5.3.21
[platform/upstream/libdb.git] / test / java / compat / src / com / sleepycat / db / util / DualTestCase.java
1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002, 2012 Oracle and/or its affiliates.  All rights reserved.
5  *
6  * $Id$
7  */
8
9 package com.sleepycat.db.util;
10
11 import java.io.File;
12 import java.io.FileNotFoundException;
13
14 import junit.framework.TestCase;
15
16 import com.sleepycat.db.DatabaseException;
17 import com.sleepycat.db.Environment;
18 import com.sleepycat.db.EnvironmentConfig;
19
20 public class DualTestCase extends TestCase {
21
22     private Environment env;
23     private boolean setUpInvoked = false;
24
25     public DualTestCase() {
26         super();
27     }
28
29     protected DualTestCase(String name) {
30         super(name);
31     }
32
33     @Override
34     protected void setUp()
35         throws Exception {
36
37         setUpInvoked = true;
38         super.setUp();
39     }
40
41     @Override
42     protected void tearDown()
43         throws Exception {
44
45         if (!setUpInvoked) {
46             throw new IllegalStateException
47                 ("tearDown was invoked without a corresponding setUp() call");
48         }
49         destroy();
50         super.tearDown();
51     }
52
53     protected Environment create(File envHome, EnvironmentConfig envConfig)
54         throws DatabaseException {
55
56         try {
57             env = new Environment(envHome, envConfig);
58         } catch (FileNotFoundException e) {
59             throw new RuntimeException(e);
60         }
61         return env;
62     }
63
64     protected void close(Environment environment)
65         throws DatabaseException {
66
67         env.close();
68         env = null;
69     }
70
71     protected void destroy()
72         throws Exception {
73
74         if (env != null) {
75             try {
76                 /* Close in case we hit an exception and didn't close */
77                 env.close();
78             } catch (RuntimeException e) {
79                 /* OK if already closed */
80             }
81             env = null;
82         }
83     }
84
85     public static boolean isReplicatedTest(Class<?> testCaseClass) {
86         return false;
87     }
88 }