PageRenderTime 35ms CodeModel.GetById 28ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

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