PageRenderTime 22ms CodeModel.GetById 10ms app.highlight 9ms RepoModel.GetById 1ms 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
 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 */
16package com.google.appengine.datanucleus.jpa;
17
18import com.google.appengine.api.datastore.TransactionOptions;
19import com.google.appengine.datanucleus.DatastoreManager;
20import com.google.appengine.datanucleus.Utils;
21
22import java.util.Map;
23
24import javax.persistence.Persistence;
25
26/**
27 * @author Max Ross <max.ross@gmail.com>
28 */
29public class JPATransactionOptionsTest extends JPATestCase {
30
31  public void testDefault() {
32    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
33    TransactionOptions txnOpts = storeMgr.getDefaultDatastoreTransactionOptions();
34    assertFalse(txnOpts.isXG());
35  }
36
37  public void testIsXG_Props() {
38    em.close();
39    emf.close();
40    Map<String, String> props = Utils.newHashMap();
41    props.put("datanucleus.appengine.datastoreEnableXGTransactions", Boolean.TRUE.toString());
42    emf = Persistence.createEntityManagerFactory(getEntityManagerFactoryName().name(), props);
43    em = emf.createEntityManager();
44    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
45    TransactionOptions txnOpts = storeMgr.getDefaultDatastoreTransactionOptions();
46    assertTrue(txnOpts.isXG());
47  }
48
49  public void testIsNotXG_Props() {
50    em.close();
51    emf.close();
52    Map<String, String> props = Utils.newHashMap();
53    props.put("datanucleus.appengine.datastoreEnableXGTransactions", Boolean.FALSE.toString());
54    emf = Persistence.createEntityManagerFactory(getEntityManagerFactoryName().name(), props);
55    em = emf.createEntityManager();
56    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
57    TransactionOptions txnOpts = storeMgr.getDefaultDatastoreTransactionOptions();
58    assertFalse(txnOpts.isXG());
59  }
60
61  public void testIsXG_Config() {
62    em.close();
63    emf.close();
64    emf = Persistence.createEntityManagerFactory("allowXGTxns");
65    em = emf.createEntityManager();
66    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
67    TransactionOptions txnOpts = storeMgr.getDefaultDatastoreTransactionOptions();
68    assertTrue(txnOpts.isXG());
69  }
70
71  public void testIsNotXG_Config() {
72    em.close();
73    emf.close();
74    emf = Persistence.createEntityManagerFactory("disallowXGTxns");
75    em = emf.createEntityManager();
76    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
77    TransactionOptions txnOpts = storeMgr.getDefaultDatastoreTransactionOptions();
78    assertFalse(txnOpts.isXG());
79  }
80}