use of com.google.cloud.spanner.Mutation in project spring-cloud-gcp by spring-cloud.
the class SpannerMutationFactoryImplTests method deleteKeysTest.
@Test
public void deleteKeysTest() {
KeySet keySet = KeySet.newBuilder().addKey(Key.of("key1")).addKey(Key.of("key2")).build();
Mutation mutation = this.spannerMutationFactory.delete(TestEntity.class, keySet);
assertEquals("custom_test_table", mutation.getTable());
assertEquals(Op.DELETE, mutation.getOperation());
List<String> keys = new ArrayList<>();
mutation.getKeySet().getKeys().forEach((key) -> {
keys.add((String) (key.getParts().iterator().next()));
});
assertThat(keys, containsInAnyOrder("key1", "key2"));
}
use of com.google.cloud.spanner.Mutation in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method updateColumnsSetTest.
@Test
public void updateColumnsSetTest() {
Mutation mutation = Mutation.newInsertOrUpdateBuilder("custom_test_table").build();
TestEntity entity = new TestEntity();
Set<String> cols = new HashSet<>(Arrays.asList(new String[] { "a", "b" }));
when(this.mutationFactory.update(same(entity), eq(Optional.of(cols)))).thenReturn(mutation);
this.spannerTemplate.update(entity, Optional.of(cols));
verify(this.databaseClient, times(1)).write(eq(Arrays.asList(mutation)));
}
use of com.google.cloud.spanner.Mutation in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method deleteKeysTest.
@Test
public void deleteKeysTest() {
KeySet keys = KeySet.newBuilder().addKey(Key.of("key1")).addKey(Key.of("key2")).build();
Mutation mutation = Mutation.delete("custom_test_table", keys);
when(this.mutationFactory.delete(eq(TestEntity.class), same(keys))).thenReturn(mutation);
this.spannerTemplate.delete(TestEntity.class, keys);
verify(this.databaseClient, times(1)).write(eq(Arrays.asList(mutation)));
}
use of com.google.cloud.spanner.Mutation in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method updateColumnsArrayTest.
@Test
public void updateColumnsArrayTest() {
Mutation mutation = Mutation.newInsertOrUpdateBuilder("custom_test_table").build();
TestEntity entity = new TestEntity();
when(this.mutationFactory.update(same(entity), eq(Optional.of(new HashSet<>(Arrays.asList(new String[] { "a", "b" })))))).thenReturn(mutation);
this.spannerTemplate.update(entity, "a", "b");
verify(this.databaseClient, times(1)).write(eq(Arrays.asList(mutation)));
}
use of com.google.cloud.spanner.Mutation in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method deleteByKeyTest.
@Test
public void deleteByKeyTest() {
Key key = Key.of("key");
Mutation mutation = Mutation.delete("custom_test_table", key);
when(this.mutationFactory.delete(eq(TestEntity.class), same(key))).thenReturn(mutation);
this.spannerTemplate.delete(TestEntity.class, key);
verify(this.databaseClient, times(1)).write(eq(Arrays.asList(mutation)));
}
Aggregations