Search in sources :

Example 1 with NullValue

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());
    }
}
Also used : FullEntity(com.google.cloud.datastore.FullEntity) Entity(com.google.cloud.datastore.Entity) ProjectionEntity(com.google.cloud.datastore.ProjectionEntity) NullValue(com.google.cloud.datastore.NullValue) Test(org.junit.Test)

Example 2 with NullValue

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()));
}
Also used : FullEntity(com.google.cloud.datastore.FullEntity) Entity(com.google.cloud.datastore.Entity) ProjectionEntity(com.google.cloud.datastore.ProjectionEntity) NullValue(com.google.cloud.datastore.NullValue) DatastoreException(com.google.cloud.datastore.DatastoreException) Test(org.junit.Test)

Aggregations

Entity (com.google.cloud.datastore.Entity)2 FullEntity (com.google.cloud.datastore.FullEntity)2 NullValue (com.google.cloud.datastore.NullValue)2 ProjectionEntity (com.google.cloud.datastore.ProjectionEntity)2 Test (org.junit.Test)2 DatastoreException (com.google.cloud.datastore.DatastoreException)1