/tests/com/google/appengine/datanucleus/jdo/JDOStorageVersionTest.java

http://datanucleus-appengine.googlecode.com/ · Java · 60 lines · 34 code · 7 blank · 19 comment · 0 complexity · 3391a13effc616fa7e1a5fbb75128834 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.jdo;
  17. import java.util.Map;
  18. import javax.jdo.JDOFatalUserException;
  19. import javax.jdo.JDOHelper;
  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 JDOStorageVersionTest extends JDOTestCase {
  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. pm.close();
  33. pmf.close();
  34. Map<String, String> props = Utils.newHashMap();
  35. props.put(StorageVersion.STORAGE_VERSION_PROPERTY, StorageVersion.PARENTS_DO_NOT_REFER_TO_CHILDREN.name());
  36. pmf = JDOHelper.getPersistenceManagerFactory(props, getPersistenceManagerFactoryName().name());
  37. pm = pmf.getPersistenceManager();
  38. DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
  39. assertEquals(StorageVersion.PARENTS_DO_NOT_REFER_TO_CHILDREN, storeMgr.getStorageVersion());
  40. }
  41. public void testUnknownStorageVersion() {
  42. pm.close();
  43. pmf.close();
  44. Map<String, String> props = Utils.newHashMap();
  45. props.put(StorageVersion.STORAGE_VERSION_PROPERTY, "does not exist");
  46. try {
  47. pmf = JDOHelper.getPersistenceManagerFactory(props, getPersistenceManagerFactoryName().name());
  48. } catch (JDOFatalUserException e) {
  49. // good
  50. assertTrue(e.getCause().getMessage().startsWith("'does not exist'"));
  51. }
  52. }
  53. }