use of com.google.cloud.spanner.Key in project spring-cloud-gcp by spring-cloud.
the class SpannerRepositoryImplTests method findAllPageableTest.
@Test
public void findAllPageableTest() {
Pageable pageable = mock(Pageable.class);
Sort sort = mock(Sort.class);
when(pageable.getSort()).thenReturn(sort);
when(pageable.getOffset()).thenReturn(3L);
when(pageable.getPageSize()).thenReturn(5);
when(this.template.queryAll(eq(Object.class), any())).thenAnswer((invocation) -> {
SpannerPageableQueryOptions spannerQueryOptions = invocation.getArgument(1);
assertThat(spannerQueryOptions.getSort()).isSameAs(sort);
assertThat(spannerQueryOptions.getOffset()).isEqualTo(3);
assertThat(spannerQueryOptions.getLimit()).isEqualTo(5);
return new ArrayList<>();
});
new SimpleSpannerRepository<Object, Key>(this.template, Object.class).findAll(pageable);
verify(this.template, times(1)).queryAll(eq(Object.class), any());
}
use of com.google.cloud.spanner.Key in project spring-cloud-gcp by spring-cloud.
the class SpannerRepositoryImplTests method findAllSortTest.
@Test
public void findAllSortTest() {
Sort sort = mock(Sort.class);
when(this.template.queryAll(eq(Object.class), any())).thenAnswer((invocation) -> {
SpannerPageableQueryOptions spannerQueryOptions = invocation.getArgument(1);
assertThat(spannerQueryOptions.getSort()).isSameAs(sort);
return null;
});
new SimpleSpannerRepository<Object, Key>(this.template, Object.class).findAll(sort);
verify(this.template, times(1)).queryAll(eq(Object.class), any());
}
use of com.google.cloud.spanner.Key in project spring-cloud-gcp by spring-cloud.
the class SpannerRepositoryImplTests method findAllByIdTest.
@Test
public void findAllByIdTest() {
List<Key> unconvertedKey = Arrays.asList(Key.of("key1"), Key.of("key2"));
when(this.entityProcessor.convertToKey(eq(Key.of("key1")))).thenReturn(Key.of("key1"));
when(this.entityProcessor.convertToKey(eq(Key.of("key2")))).thenReturn(Key.of("key2"));
when(this.template.read(eq(Object.class), (KeySet) any())).thenAnswer((invocation) -> {
KeySet keys = invocation.getArgument(1);
assertThat(keys.getKeys()).containsExactlyInAnyOrder(Key.of("key2"), Key.of("key1"));
return null;
});
new SimpleSpannerRepository<Object, Key>(this.template, Object.class).findAllById(unconvertedKey);
}
use of com.google.cloud.spanner.Key in project spring-cloud-gcp by spring-cloud.
the class SpannerSchemaUtilsTests method getIdTest.
@Test
public void getIdTest() {
TestEntity t = new TestEntity();
t.id = "aaa";
t.embeddedColumns = new EmbeddedColumns();
t.embeddedColumns.id2 = "2";
t.id3 = 3L;
Key expectedKey = Key.newBuilder().append(t.id).appendObject(t.embeddedColumns.id2).append(t.id3).build();
assertThat(this.spannerSchemaUtils.getKey(t)).isEqualTo(expectedKey);
}
use of com.google.cloud.spanner.Key in project spring-cloud-gcp by spring-cloud.
the class KeyConversionTests method keyWritingTestCase.
@Test
public void keyWritingTestCase() {
try {
Key key = this.spannerEntityWriter.convertToKey(this.objectToTest);
assertThat(key).isEqualTo(this.expectedResult);
} catch (Exception ex) {
assertThat(ex.getClass()).as("Unexpected exception: " + ex + "\nexpected: " + this.expectedResult).isEqualTo(this.expectedResult);
}
}
Aggregations