Search in sources :

Example 11 with SpannerOperations

use of org.springframework.cloud.gcp.data.spanner.core.SpannerOperations in project spring-cloud-gcp by spring-cloud.

the class SpannerRepositoryImplTests method getSpannerOperationsTest.

@Test
public void getSpannerOperationsTest() {
    SpannerOperations operations = mock(SpannerOperations.class);
    assertSame(operations, new SimpleSpannerRepository(operations, Object.class).getSpannerOperations());
}
Also used : SpannerOperations(org.springframework.cloud.gcp.data.spanner.core.SpannerOperations) Test(org.junit.Test)

Example 12 with SpannerOperations

use of org.springframework.cloud.gcp.data.spanner.core.SpannerOperations in project spring-cloud-gcp by spring-cloud.

the class SpannerRepositoryImplTests method existsByIdTestNotFound.

@Test
public void existsByIdTestNotFound() {
    SpannerOperations operations = mock(SpannerOperations.class);
    when(operations.find(eq(Object.class), (Key) any())).thenReturn(null);
    assertFalse(new SimpleSpannerRepository(operations, Object.class).existsById(Key.of("key")));
}
Also used : SpannerOperations(org.springframework.cloud.gcp.data.spanner.core.SpannerOperations) Test(org.junit.Test)

Example 13 with SpannerOperations

use of org.springframework.cloud.gcp.data.spanner.core.SpannerOperations in project spring-cloud-gcp by spring-cloud.

the class SpannerRepositoryImplTests method findAllByIdTest.

@Test
public void findAllByIdTest() {
    SpannerOperations operations = mock(SpannerOperations.class);
    when(operations.find(eq(Object.class), (KeySet) any())).thenAnswer(invocation -> {
        KeySet keys = invocation.getArgument(1);
        assertThat(keys.getKeys(), containsInAnyOrder(Key.of("key2"), Key.of("key1")));
        return null;
    });
    new SimpleSpannerRepository(operations, Object.class).findAllById(Arrays.asList(Key.of("key1"), Key.of("key2")));
}
Also used : KeySet(com.google.cloud.spanner.KeySet) SpannerOperations(org.springframework.cloud.gcp.data.spanner.core.SpannerOperations) Test(org.junit.Test)

Example 14 with SpannerOperations

use of org.springframework.cloud.gcp.data.spanner.core.SpannerOperations in project spring-cloud-gcp by spring-cloud.

the class SpannerRepositoryImplTests method findAllPageableTest.

@Test
public void findAllPageableTest() {
    SpannerOperations operations = mock(SpannerOperations.class);
    Pageable pageable = mock(Pageable.class);
    new SimpleSpannerRepository(operations, Object.class).findAll(pageable);
    verify(operations, times(1)).findAll(eq(Object.class), same(pageable));
}
Also used : Pageable(org.springframework.data.domain.Pageable) SpannerOperations(org.springframework.cloud.gcp.data.spanner.core.SpannerOperations) Test(org.junit.Test)

Example 15 with SpannerOperations

use of org.springframework.cloud.gcp.data.spanner.core.SpannerOperations in project spring-cloud-gcp by spring-cloud.

the class SpannerRepositoryImplTests method findAllSortTest.

@Test
public void findAllSortTest() {
    SpannerOperations operations = mock(SpannerOperations.class);
    Sort sort = mock(Sort.class);
    new SimpleSpannerRepository(operations, Object.class).findAll(sort);
    verify(operations, times(1)).findAll(eq(Object.class), same(sort));
}
Also used : Sort(org.springframework.data.domain.Sort) SpannerOperations(org.springframework.cloud.gcp.data.spanner.core.SpannerOperations) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)15 SpannerOperations (org.springframework.cloud.gcp.data.spanner.core.SpannerOperations)15 Key (com.google.cloud.spanner.Key)3 KeySet (com.google.cloud.spanner.KeySet)1 Pageable (org.springframework.data.domain.Pageable)1 Sort (org.springframework.data.domain.Sort)1