PageRenderTime 31ms CodeModel.GetById 26ms 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
Possible License(s): Apache-2.0
  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.Entity;
  15. import com.google.appengine.api.datastore.EntityNotFoundException;
  16. import com.google.appengine.api.datastore.Key;
  17. import com.google.appengine.api.datastore.KeyFactory;
  18. import com.google.appengine.datanucleus.test.jpa.HasTableAndColumnsInMappingJPA;
  19. /**
  20. * @author Max Ross <maxr@google.com>
  21. */
  22. public class JPATableAndColumnTest extends JPATestCase {
  23. public void testInsert() throws EntityNotFoundException {
  24. HasTableAndColumnsInMappingJPA htacim = new HasTableAndColumnsInMappingJPA();
  25. htacim.setFoo("foo val");
  26. beginTxn();
  27. em.persist(htacim);
  28. commitTxn();
  29. assertNotNull(htacim.getId());
  30. Entity entity = ds.get(KeyFactory.createKey(
  31. HasTableAndColumnsInMappingJPA.TABLE_NAME, htacim.getId()));
  32. assertNotNull(entity);
  33. assertEquals(HasTableAndColumnsInMappingJPA.TABLE_NAME, entity.getKind());
  34. assertEquals("foo val", entity.getProperty(HasTableAndColumnsInMappingJPA.FOO_COLUMN_NAME));
  35. }
  36. public void testFetch() {
  37. Entity entity = new Entity(HasTableAndColumnsInMappingJPA.TABLE_NAME);
  38. entity.setProperty(HasTableAndColumnsInMappingJPA.FOO_COLUMN_NAME, "foo val");
  39. Key key = ds.put(entity);
  40. String keyStr = KeyFactory.keyToString(key);
  41. beginTxn();
  42. HasTableAndColumnsInMappingJPA htacim = em.find(HasTableAndColumnsInMappingJPA.class, keyStr);
  43. assertNotNull(htacim);
  44. assertEquals(Long.valueOf(key.getId()), htacim.getId());
  45. assertEquals("foo val", htacim.getFoo());
  46. commitTxn();
  47. }
  48. }