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

http://datanucleus-appengine.googlecode.com/ · Java · 85 lines · 57 code · 9 blank · 19 comment · 0 complexity · 53a7096e85ff3338141581b9241bf379 MD5 · raw file

  1. /**********************************************************************
  2. Copyright (c) 2009 Google Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. **********************************************************************/
  13. package com.google.appengine.datanucleus.jpa;
  14. import com.google.appengine.api.datastore.Key;
  15. import com.google.appengine.api.datastore.KeyFactory;
  16. import com.google.appengine.datanucleus.test.jdo.KitchenSink;
  17. /**
  18. * TODO This uses KitchenSink but that is a JDO model class!!
  19. * @author Max Ross <maxr@google.com>
  20. */
  21. public class JPADeleteTest extends JPATestCase {
  22. public void testSimpleDelete() {
  23. Key key = ds.put(KitchenSink.newKitchenSinkEntity(null));
  24. String keyStr = KeyFactory.keyToString(key);
  25. KitchenSink ks;
  26. beginTxn();
  27. ks = em.find(KitchenSink.class, keyStr);
  28. assertNotNull(ks);
  29. em.remove(ks);
  30. commitTxn();
  31. beginTxn();
  32. try {
  33. assertNull(em.find(KitchenSink.class, keyStr));
  34. } finally {
  35. commitTxn();
  36. }
  37. }
  38. public void testSimpleDeleteWithNamedKey() {
  39. Key key = ds.put(KitchenSink.newKitchenSinkEntity("named key", null));
  40. assertEquals("named key", key.getName());
  41. String keyStr = KeyFactory.keyToString(key);
  42. KitchenSink ks;
  43. beginTxn();
  44. ks = em.find(KitchenSink.class, keyStr);
  45. assertNotNull(ks);
  46. em.remove(ks);
  47. commitTxn();
  48. beginTxn();
  49. try {
  50. assertNull(em.find(KitchenSink.class, keyStr));
  51. } finally {
  52. commitTxn();
  53. }
  54. }
  55. public void testDeletePersistentNew() {
  56. int count = countForClass(KitchenSink.class);
  57. beginTxn();
  58. KitchenSink ks = KitchenSink.newKitchenSink();
  59. em.persist(ks);
  60. em.remove(ks);
  61. commitTxn();
  62. assertEquals(count, countForClass(KitchenSink.class));
  63. }
  64. public void testDeletePersistentNew_NoTxn() {
  65. int count = countForClass(KitchenSink.class);
  66. switchDatasource(EntityManagerFactoryName.nontransactional_ds_non_transactional_ops_not_allowed);
  67. KitchenSink ks = KitchenSink.newKitchenSink();
  68. em.persist(ks);
  69. em.remove(ks);
  70. assertEquals(count, countForClass(KitchenSink.class));
  71. em.close();
  72. }
  73. }