use of com.google.cloud.datastore.NullValue in project google-cloud-java by GoogleCloudPlatform.
the class ITDatastoreTest method testPut.
@Test
public void testPut() {
Entity updatedEntity = Entity.newBuilder(ENTITY1).set("new_property", 42L).build();
assertEquals(updatedEntity, DATASTORE.put(updatedEntity));
assertEquals(updatedEntity, DATASTORE.get(updatedEntity.getKey()));
Entity entity2 = Entity.newBuilder(ENTITY2).clear().set("bla", new NullValue()).build();
assertNotEquals(ENTITY2, entity2);
List<Entity> entities = DATASTORE.put(ENTITY1, entity2, ENTITY3, PARTIAL_ENTITY1);
assertEquals(ENTITY1, entities.get(0));
assertEquals(entity2, entities.get(1));
assertEquals(ENTITY3, entities.get(2));
assertEquals(PARTIAL_ENTITY1.getNames(), entities.get(3).getNames());
assertEquals(PARTIAL_ENTITY1.getKey().getAncestors(), entities.get(3).getKey().getAncestors());
assertEquals(ENTITY1, DATASTORE.get(ENTITY1.getKey()));
assertEquals(entity2, DATASTORE.get(entity2.getKey()));
assertEquals(ENTITY3, DATASTORE.get(ENTITY3.getKey()));
Entity entity = DATASTORE.get(entities.get(3).getKey());
assertEquals(entities.get(3), entity);
for (Entity entityToDelete : entities) {
DATASTORE.delete(entityToDelete.getKey());
}
}
use of com.google.cloud.datastore.NullValue in project google-cloud-java by GoogleCloudPlatform.
the class ITDatastoreTest method testUpdate.
@Test
public void testUpdate() {
List<Entity> keys = DATASTORE.fetch(ENTITY1.getKey(), ENTITY3.getKey());
assertEquals(ENTITY1, keys.get(0));
assertNull(keys.get(1));
assertEquals(2, keys.size());
try {
DATASTORE.update(ENTITY3);
fail("Expecting a failure");
} catch (DatastoreException expected) {
// expected;
}
DATASTORE.add(ENTITY3);
assertEquals(ENTITY3, DATASTORE.get(ENTITY3.getKey()));
Entity entity3 = Entity.newBuilder(ENTITY3).clear().set("bla", new NullValue()).build();
assertNotEquals(ENTITY3, entity3);
DATASTORE.update(entity3);
assertEquals(entity3, DATASTORE.get(ENTITY3.getKey()));
}
Aggregations