Search in sources :

Example 1 with ProjectionEntityQuery

use of com.google.cloud.datastore.ProjectionEntityQuery in project spring-cloud-gcp by spring-cloud.

the class Employee method testSlicedEntityProjections.

@Test
public void testSlicedEntityProjections() {
    reset(datastoreTemplate);
    Slice<TestEntityProjection> testEntityProjectionSlice = this.testEntityRepository.findBySize(2L, PageRequest.of(0, 1));
    List<TestEntityProjection> testEntityProjections = testEntityProjectionSlice.get().collect(Collectors.toList());
    assertThat(testEntityProjections).hasSize(1);
    assertThat(testEntityProjections.get(0)).isInstanceOf(TestEntityProjection.class);
    assertThat(testEntityProjections.get(0)).isNotInstanceOf(TestEntity.class);
    // Verifies that the projection method call works.
    assertThat(testEntityProjections.get(0).getColor()).isEqualTo("blue");
    ProjectionEntityQuery projectionQuery = com.google.cloud.datastore.Query.newProjectionEntityQueryBuilder().addProjection("color").setFilter(PropertyFilter.eq("size", 2L)).setKind("test_entities_ci").setLimit(1).build();
    verify(datastoreTemplate).queryKeysOrEntities(eq(projectionQuery), any());
}
Also used : ProjectionEntityQuery(com.google.cloud.datastore.ProjectionEntityQuery) Test(org.junit.Test)

Example 2 with ProjectionEntityQuery

use of com.google.cloud.datastore.ProjectionEntityQuery in project spring-cloud-gcp by spring-cloud.

the class Employee method projectionTest.

@Test
public void projectionTest() {
    reset(datastoreTemplate);
    assertThat(this.testEntityRepository.findBySize(2L).getColor()).isEqualTo("blue");
    ProjectionEntityQuery projectionQuery = com.google.cloud.datastore.Query.newProjectionEntityQueryBuilder().addProjection("color").setFilter(PropertyFilter.eq("size", 2L)).setKind("test_entities_ci").setLimit(1).build();
    verify(datastoreTemplate).queryKeysOrEntities(eq(projectionQuery), any());
}
Also used : ProjectionEntityQuery(com.google.cloud.datastore.ProjectionEntityQuery) Test(org.junit.Test)

Aggregations

ProjectionEntityQuery (com.google.cloud.datastore.ProjectionEntityQuery)2 Test (org.junit.Test)2