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