PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://datanucleus-appengine.googlecode.com/
Java | 76 lines | 48 code | 10 blank | 18 comment | 0 complexity | 034835386c4cb23549e8e90e47b7181b 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.api.datastore.Blob;
19import com.google.appengine.api.datastore.Entity;
20import com.google.appengine.api.datastore.EntityNotFoundException;
21import com.google.appengine.api.datastore.KeyFactory;
22import com.google.appengine.api.datastore.Text;
23import com.google.appengine.datanucleus.Utils;
24import com.google.appengine.datanucleus.test.jdo.HasUnindexedPropertiesJDO;
25
26
27import java.lang.reflect.Field;
28import java.util.Map;
29
30/**
31 * @author Max Ross <maxr@google.com>
32 */
33public class JDOUnindexedPropertiesTest extends JDOTestCase {
34
35  private static final Field PROPERTY_MAP_FIELD;
36  static {
37    try {
38      PROPERTY_MAP_FIELD = Entity.class.getDeclaredField("propertyMap");
39    } catch (NoSuchFieldException e) {
40      throw new RuntimeException(e);
41    }
42    PROPERTY_MAP_FIELD.setAccessible(true);
43  }
44
45  private static Object getRawProperty(Entity e, String propertyName) throws
46                                                                      IllegalAccessException {
47    Map<String, Object> rawProps = (Map<String, Object>) PROPERTY_MAP_FIELD.get(e);
48    return rawProps.get(propertyName);
49  }
50
51  private static boolean isUnindexedProperty(Object obj) {
52    return "com.google.appengine.api.datastore.Entity$UnindexedValue".equals(obj.getClass().getName());
53  }
54
55  public void testInsert() throws EntityNotFoundException, IllegalAccessException {
56    HasUnindexedPropertiesJDO pojo = new HasUnindexedPropertiesJDO();
57    pojo.setUnindexedString("str");
58    pojo.setUnindexedList(Utils.newArrayList("a", "b", "c"));
59    pojo.setUnindexedText(new Text("unindexed text"));
60    pojo.setUnindexedBlob(new Blob("unindexed blob".getBytes()));
61    pojo.setText(new Text("text"));
62    pojo.setBlob(new Blob("blob".getBytes()));
63
64    beginTxn();
65    pm.makePersistent(pojo);
66    commitTxn();
67
68    Entity e = ds.get(KeyFactory.createKey(pojo.getClass().getSimpleName(), pojo.getId()));
69    assertTrue(isUnindexedProperty(getRawProperty(e, "unindexedString")));
70    assertTrue(isUnindexedProperty(getRawProperty(e, "unindexedList")));
71    assertTrue(isUnindexedProperty(getRawProperty(e, "unindexedText")));
72    assertTrue(isUnindexedProperty(getRawProperty(e, "unindexedBlob")));
73    assertTrue(isUnindexedProperty(getRawProperty(e, "text")));
74    assertTrue(isUnindexedProperty(getRawProperty(e, "blob")));
75  }
76}