PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://datanucleus-appengine.googlecode.com/
Java | 58 lines | 33 code | 7 blank | 18 comment | 0 complexity | fe7fc0cf15ab5bcec76adcd5c261373c 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.Entity;
19import com.google.appengine.api.datastore.EntityNotFoundException;
20import com.google.appengine.api.datastore.Key;
21import com.google.appengine.api.datastore.KeyFactory;
22import com.google.appengine.datanucleus.test.jpa.HasTableAndColumnsInMappingJPA;
23
24
25/**
26 * @author Max Ross <maxr@google.com>
27 */
28public class JPATableAndColumnTest extends JPATestCase {
29
30  public void testInsert() throws EntityNotFoundException {
31    HasTableAndColumnsInMappingJPA htacim = new HasTableAndColumnsInMappingJPA();
32    htacim.setFoo("foo val");
33    beginTxn();
34    em.persist(htacim);
35    commitTxn();
36    assertNotNull(htacim.getId());
37    Entity entity = ds.get(KeyFactory.createKey(
38        HasTableAndColumnsInMappingJPA.TABLE_NAME, htacim.getId()));
39    assertNotNull(entity);
40    assertEquals(HasTableAndColumnsInMappingJPA.TABLE_NAME, entity.getKind());
41    assertEquals("foo val", entity.getProperty(HasTableAndColumnsInMappingJPA.FOO_COLUMN_NAME));
42  }
43
44  public void testFetch() {
45    Entity entity = new Entity(HasTableAndColumnsInMappingJPA.TABLE_NAME);
46    entity.setProperty(HasTableAndColumnsInMappingJPA.FOO_COLUMN_NAME, "foo val");
47    Key key = ds.put(entity);
48
49    String keyStr = KeyFactory.keyToString(key);
50    beginTxn();
51    HasTableAndColumnsInMappingJPA htacim = em.find(HasTableAndColumnsInMappingJPA.class, keyStr);
52    assertNotNull(htacim);
53    assertEquals(Long.valueOf(key.getId()), htacim.getId());
54    assertEquals("foo val", htacim.getFoo());
55    commitTxn();
56  }
57
58}