PageRenderTime 71ms CodeModel.GetById 61ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://datanucleus-appengine.googlecode.com/
Java | 62 lines | 35 code | 7 blank | 20 comment | 0 complexity | 84bde1f41b995570fc283423e24ea94b 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 java.util.Map;
19
20import javax.persistence.Persistence;
21import javax.persistence.PersistenceException;
22
23import com.google.appengine.datanucleus.DatastoreManager;
24import com.google.appengine.datanucleus.StorageVersion;
25import com.google.appengine.datanucleus.Utils;
26
27/**
28 * @author Max Ross <max.ross@gmail.com>
29 */
30public class JPAStorageVersionTest extends JPATestCase {
31
32  public void testDefaultStorageVersion() {
33    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
34    assertEquals(StorageVersion.READ_OWNED_CHILD_KEYS_FROM_PARENTS, storeMgr.getStorageVersion());
35  }
36
37  public void testNonDefaultStorageVersion() {
38    em.close();
39    emf.close();
40    Map<String, String> props = Utils.newHashMap();
41    props.put(StorageVersion.STORAGE_VERSION_PROPERTY, StorageVersion.PARENTS_DO_NOT_REFER_TO_CHILDREN.name());
42    emf = Persistence.createEntityManagerFactory(getEntityManagerFactoryName().name(), props);
43    em = emf.createEntityManager();
44    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
45    assertEquals(StorageVersion.PARENTS_DO_NOT_REFER_TO_CHILDREN, storeMgr.getStorageVersion());
46  }
47
48  public void testUnknownStorageVersion() {
49    em.close();
50    emf.close();
51    Map<String, String> props = Utils.newHashMap();
52    props.put(StorageVersion.STORAGE_VERSION_PROPERTY, "does not exist");
53    try {
54      emf = Persistence.createEntityManagerFactory(getEntityManagerFactoryName().name(), props);
55    } catch (Exception e) {
56      // not all Persistence impls wrap EMF creation exception into PersistenceException
57      Throwable cause = (e instanceof PersistenceException) ? e.getCause() : e;
58      // good
59      assertTrue(cause.getMessage().startsWith("'does not exist'"));
60    }
61  }
62}