/** @throws Exception */ @Test(expected = EntityNotFoundRuntimeException.class) public void entityMapToModelListWhenNoEntityIsFound() throws Exception { Key key = Datastore.createKey("Hoge", 1); Key key2 = Datastore.createKey("Hoge", 2); Key key3 = Datastore.createKey("Hoge", 3); Entity entity = new Entity(key); Entity entity2 = new Entity(key2); Map<Key, Entity> map = new HashMap<Key, Entity>(); map.put(key2, entity2); map.put(key, entity); DatastoreUtil.entityMapToModelList(meta, Arrays.asList(key, key2, key3), map); }
/** @throws Exception */ @Test public void bytesToEntity() throws Exception { Entity entity = new Entity(Datastore.createKey("Hoge", 1)); byte[] bytes = DatastoreUtil.entityToBytes(entity); Entity entity2 = DatastoreUtil.bytesToEntity(bytes); assertThat(entity2, is(notNullValue())); assertThat(entity2, is(entity)); }
/** @throws Exception */ @Test public void entityMapToModelMap() throws Exception { Key key = Datastore.createKey("Hoge", 1); Key key2 = Datastore.createKey("Hoge", 2); Key key3 = Datastore.createKey("Hoge", 3); Entity entity = new Entity(key); Entity entity2 = new Entity(key2); Entity entity3 = new Entity(key3); Map<Key, Entity> map = new HashMap<Key, Entity>(); map.put(key3, entity3); map.put(key2, entity2); map.put(key, entity); Map<Key, Hoge> map2 = DatastoreUtil.entityMapToModelMap(meta, map); assertThat(map2.size(), is(3)); assertThat(map2.get(key).getKey(), is(key)); assertThat(map2.get(key2).getKey(), is(key2)); assertThat(map2.get(key3).getKey(), is(key3)); }
/** @throws Exception */ @Test public void entityMapToModelList() throws Exception { Key key = Datastore.createKey("Hoge", 1); Key key2 = Datastore.createKey("Hoge", 2); Key key3 = Datastore.createKey("Hoge", 3); Entity entity = new Entity(key); Entity entity2 = new Entity(key2); Entity entity3 = new Entity(key3); Map<Key, Entity> map = new HashMap<Key, Entity>(); map.put(key3, entity3); map.put(key2, entity2); map.put(key, entity); List<Hoge> list = DatastoreUtil.entityMapToModelList(meta, Arrays.asList(key, key2, key3), map); assertThat(list.size(), is(3)); assertThat(list.get(0).getKey(), is(key)); assertThat(list.get(1).getKey(), is(key2)); assertThat(list.get(2).getKey(), is(key3)); }