PageRenderTime 30ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://datanucleus-appengine.googlecode.com/
Java | 80 lines | 53 code | 9 blank | 18 comment | 0 complexity | 5fd9b2581fd6d6dea8b43a42b0dc7d45 MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  2. * Copyright (C) 2010 Google Inc
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.google.appengine.datanucleus.jpa;
  17. import com.google.appengine.api.datastore.TransactionOptions;
  18. import com.google.appengine.datanucleus.DatastoreManager;
  19. import com.google.appengine.datanucleus.Utils;
  20. import java.util.Map;
  21. import javax.persistence.Persistence;
  22. /**
  23. * @author Max Ross <max.ross@gmail.com>
  24. */
  25. public class JPATransactionOptionsTest extends JPATestCase {
  26. public void testDefault() {
  27. DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
  28. TransactionOptions txnOpts = storeMgr.getDefaultDatastoreTransactionOptions();
  29. assertFalse(txnOpts.isXG());
  30. }
  31. public void testIsXG_Props() {
  32. em.close();
  33. emf.close();
  34. Map<String, String> props = Utils.newHashMap();
  35. props.put("datanucleus.appengine.datastoreEnableXGTransactions", Boolean.TRUE.toString());
  36. emf = Persistence.createEntityManagerFactory(getEntityManagerFactoryName().name(), props);
  37. em = emf.createEntityManager();
  38. DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
  39. TransactionOptions txnOpts = storeMgr.getDefaultDatastoreTransactionOptions();
  40. assertTrue(txnOpts.isXG());
  41. }
  42. public void testIsNotXG_Props() {
  43. em.close();
  44. emf.close();
  45. Map<String, String> props = Utils.newHashMap();
  46. props.put("datanucleus.appengine.datastoreEnableXGTransactions", Boolean.FALSE.toString());
  47. emf = Persistence.createEntityManagerFactory(getEntityManagerFactoryName().name(), props);
  48. em = emf.createEntityManager();
  49. DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
  50. TransactionOptions txnOpts = storeMgr.getDefaultDatastoreTransactionOptions();
  51. assertFalse(txnOpts.isXG());
  52. }
  53. public void testIsXG_Config() {
  54. em.close();
  55. emf.close();
  56. emf = Persistence.createEntityManagerFactory("allowXGTxns");
  57. em = emf.createEntityManager();
  58. DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
  59. TransactionOptions txnOpts = storeMgr.getDefaultDatastoreTransactionOptions();
  60. assertTrue(txnOpts.isXG());
  61. }
  62. public void testIsNotXG_Config() {
  63. em.close();
  64. emf.close();
  65. emf = Persistence.createEntityManagerFactory("disallowXGTxns");
  66. em = emf.createEntityManager();
  67. DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
  68. TransactionOptions txnOpts = storeMgr.getDefaultDatastoreTransactionOptions();
  69. assertFalse(txnOpts.isXG());
  70. }
  71. }