PageRenderTime 19ms CodeModel.GetById 2ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 1ms

/tests/com/google/appengine/datanucleus/jpa/JPAEntityManagerFactoryTest.java

http://datanucleus-appengine.googlecode.com/
Java | 87 lines | 60 code | 9 blank | 18 comment | 20 complexity | a281a4e38a31827ea1ffcbe107a04ff9 MD5 | raw file
 1/**********************************************************************
 2Copyright (c) 2009 Google Inc.
 3
 4Licensed under the Apache License, Version 2.0 (the "License");
 5you may not use this file except in compliance with the License.
 6You may obtain a copy of the License at
 7
 8http://www.apache.org/licenses/LICENSE-2.0
 9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15**********************************************************************/
16package com.google.appengine.datanucleus.jpa;
17
18import junit.framework.TestCase;
19
20import javax.persistence.EntityManagerFactory;
21import javax.persistence.Persistence;
22
23/**
24 * @author Max Ross <maxr@google.com>
25 */
26public class JPAEntityManagerFactoryTest extends TestCase {
27
28  public void testAllocationOfDuplicateNamedEMFAsSingleton() {
29    EntityManagerFactory emf1 = null;
30    EntityManagerFactory emf2 = null;
31    try {
32      emf1 = Persistence.createEntityManagerFactory("nontransactional_ds_non_transactional_ops_allowed_singleton");
33
34      emf2 = Persistence.createEntityManagerFactory("nontransactional_ds_non_transactional_ops_allowed_singleton");
35
36      assertTrue(emf1 == emf2);
37    }
38    catch (Exception e) {
39      fail("Exception thrown during allocation of two EMFs with same name requiring singleton");
40    }
41    finally {
42      if (emf1 != emf2) {
43        if (emf1 != null) {
44          emf1.close();
45        }
46        if (emf2 != null) {
47          emf2.close();
48        }
49      }
50      else {
51        if (emf1 != null) {
52          emf1.close();
53        }
54      }
55    }
56  }
57
58  public void testAllocationOfDuplicateNamedEMF() {
59    EntityManagerFactory emf1 = null;
60    EntityManagerFactory emf2 = null;
61    try {
62      emf1 = Persistence.createEntityManagerFactory("nontransactional_ds_non_transactional_ops_allowed");
63
64      emf2 = Persistence.createEntityManagerFactory("nontransactional_ds_non_transactional_ops_allowed");
65
66      assertTrue(emf1 != emf2);
67    }
68    catch (Exception e) {
69      fail("Exception thrown during allocation of two EMFs with same name requiring singleton");
70    }
71    finally {
72      if (emf1 != emf2) {
73        if (emf1 != null) {
74          emf1.close();
75        }
76        if (emf2 != null) {
77          emf2.close();
78        }
79      }
80      else {
81        if (emf1 != null) {
82          emf1.close();
83        }
84      }
85    }
86  }
87}