PageRenderTime 44ms CodeModel.GetById 38ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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