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

http://datanucleus-appengine.googlecode.com/ · Java · 82 lines · 52 code · 12 blank · 18 comment · 0 complexity · c6995bc4ff17b1c5c0702f8f0364267c 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.jdo;
  14. import com.google.appengine.datanucleus.Utils;
  15. import com.google.appengine.datanucleus.test.jdo.HasEnumJDO;
  16. import com.google.appengine.datanucleus.test.jdo.HasEnumJDO.MyEnum;
  17. import static com.google.appengine.datanucleus.test.jdo.HasEnumJDO.MyEnum.V1;
  18. import static com.google.appengine.datanucleus.test.jdo.HasEnumJDO.MyEnum.V2;
  19. import java.util.Arrays;
  20. /**
  21. * @author Max Ross <maxr@google.com>
  22. */
  23. public class JDOEnumTest extends JDOTestCase {
  24. public void testRoundtrip() {
  25. HasEnumJDO pojo = new HasEnumJDO();
  26. pojo.setMyEnum(V1);
  27. pojo.setMyEnumArray(new MyEnum[] {V2, V1, V2});
  28. pojo.setMyEnumList(Utils.newArrayList(V1, V2, V1));
  29. beginTxn();
  30. pm.makePersistent(pojo);
  31. commitTxn();
  32. beginTxn();
  33. pojo = pm.getObjectById(HasEnumJDO.class, pojo.getKey());
  34. assertEquals(HasEnumJDO.MyEnum.V1, pojo.getMyEnum());
  35. assertTrue(Arrays.equals(new MyEnum[] {V2, V1, V2 }, pojo.getMyEnumArray()));
  36. assertEquals(Utils.newArrayList(V1, V2, V1), pojo.getMyEnumList());
  37. commitTxn();
  38. }
  39. public void testRoundtrip_Null() {
  40. HasEnumJDO pojo = new HasEnumJDO();
  41. beginTxn();
  42. pm.makePersistent(pojo);
  43. commitTxn();
  44. beginTxn();
  45. pojo = pm.getObjectById(HasEnumJDO.class, pojo.getKey());
  46. assertNull(pojo.getMyEnum());
  47. assertNotNull(pojo.getMyEnumArray());
  48. assertEquals(0, pojo.getMyEnumArray().length);
  49. assertNotNull(pojo.getMyEnumList());
  50. assertTrue(pojo.getMyEnumList().isEmpty());
  51. commitTxn();
  52. }
  53. public void testRoundtrip_NullContainerVals() {
  54. HasEnumJDO pojo = new HasEnumJDO();
  55. pojo.setMyEnumArray(new MyEnum[] {null, V2});
  56. pojo.setMyEnumList(Utils.newArrayList(null, V2));
  57. beginTxn();
  58. pm.makePersistent(pojo);
  59. commitTxn();
  60. beginTxn();
  61. pojo = pm.getObjectById(HasEnumJDO.class, pojo.getKey());
  62. assertNull(pojo.getMyEnum());
  63. assertTrue(Arrays.equals(new MyEnum[] {null, V2}, pojo.getMyEnumArray()));
  64. assertEquals(Utils.newArrayList(null, V2), pojo.getMyEnumList());
  65. commitTxn();
  66. }
  67. }