01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.persistence.test;
20:
21: import org.apache.openjpa.jdbc.meta.ClassMapping;
22: import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
23:
24: public abstract class SingleEMFTestCase extends PersistenceTestCase {
25:
26: protected OpenJPAEntityManagerFactorySPI emf;
27:
28: /**
29: * Call {@link #setUp(Object...)} with no arguments so that the emf
30: * set-up happens even if <code>setUp()</code> is not called from the
31: * subclass.
32: */
33: public void setUp() throws Exception {
34: setUp(new Object[0]);
35: }
36:
37: /**
38: * Initialize entity manager factory. Put {@link #CLEAR_TABLES} in
39: * this list to tell the test framework to delete all table contents
40: * before running the tests.
41: *
42: * @param props list of persistent types used in testing and/or
43: * configuration values in the form key,value,key,value...
44: */
45: protected void setUp(Object... props) {
46: emf = createEMF(props);
47: }
48:
49: /**
50: * Closes the entity manager factory.
51: */
52: public void tearDown() throws Exception {
53: super .tearDown();
54:
55: if (emf == null)
56: return;
57:
58: try {
59: clear(emf);
60: } catch (Exception e) {
61: // if a test failed, swallow any exceptions that happen
62: // during tear-down, as these just mask the original problem.
63: if (testResult.wasSuccessful())
64: throw e;
65: } finally {
66: closeEMF(emf);
67: }
68: }
69:
70: protected ClassMapping getMapping(String name) {
71: return (ClassMapping) emf.getConfiguration()
72: .getMetaDataRepositoryInstance().getMetaData(name,
73: getClass().getClassLoader(), true);
74: }
75: }
|