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