PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/com/google/appengine/datanucleus/jdo/JDOPersistenceManagerFactoryTest.java

http://datanucleus-appengine.googlecode.com/
Java | 87 lines | 60 code | 9 blank | 18 comment | 20 complexity | c86491ef52424814f9f10838aeb7bc30 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.jdo;
17
18import junit.framework.TestCase;
19
20import javax.jdo.JDOHelper;
21import javax.jdo.PersistenceManagerFactory;
22
23/**
24 * @author Max Ross <maxr@google.com>
25 */
26public class JDOPersistenceManagerFactoryTest extends TestCase {
27
28  public void testAllocationOfDuplicateNamedPMFAsSingleton() {
29    PersistenceManagerFactory pmf1 = null;
30    PersistenceManagerFactory pmf2 = null;
31    try {
32      pmf1 = JDOHelper.getPersistenceManagerFactory("nontransactional-singleton");
33
34      pmf2 = JDOHelper.getPersistenceManagerFactory("nontransactional-singleton");
35
36      assertTrue(pmf1 == pmf2);
37    }
38    catch (Exception e) {
39      fail("Exception thrown during allocation of two PMFs with same name requiring singleton");
40    }
41    finally {
42      if (pmf1 != pmf2) {
43        if (pmf1 != null) {
44          pmf1.close();
45        }
46        if (pmf2 != null) {
47          pmf2.close();
48        }
49      }
50      else {
51        if (pmf1 != null) {
52          pmf1.close();
53        }
54      }
55    }
56  }
57
58  public void testAllocationOfDuplicateNamedPMF() {
59    PersistenceManagerFactory pmf1 = null;
60    PersistenceManagerFactory pmf2 = null;
61    try {
62      pmf1 = JDOHelper.getPersistenceManagerFactory("nontransactional");
63
64      pmf2 = JDOHelper.getPersistenceManagerFactory("nontransactional");
65
66      assertTrue(pmf1 != pmf2);
67    }
68    catch (Exception e) {
69      fail("Exception thrown during allocation of two PMFs with same name");
70    }
71    finally {
72      if (pmf1 != pmf2) {
73        if (pmf1 != null) {
74          pmf1.close();
75        }
76        if (pmf2 != null) {
77          pmf2.close();
78        }
79      }
80      else {
81        if (pmf1 != null) {
82          pmf1.close();
83        }
84      }
85    }
86  }
87}