use of com.google.cloud.spanner.Mutation in project spring-cloud-gcp by spring-cloud.
the class SpannerMutationFactoryImplTests method upsertTest.
@Test
public void upsertTest() {
Mutation mutation = this.spannerMutationFactory.upsert(new TestEntity(), null);
assertEquals("custom_test_table", mutation.getTable());
assertEquals(Op.INSERT_OR_UPDATE, mutation.getOperation());
}
use of com.google.cloud.spanner.Mutation in project spring-cloud-gcp by spring-cloud.
the class SpannerMutationFactoryImplTests method deleteEntitiesTest.
@Test
public void deleteEntitiesTest() {
TestEntity t1 = new TestEntity();
t1.id = "key1";
TestEntity t2 = new TestEntity();
t2.id = "key2";
Mutation mutation = this.spannerMutationFactory.delete(TestEntity.class, Arrays.asList(t1, t2));
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(t1.id, t2.id));
}
use of com.google.cloud.spanner.Mutation in project spring-cloud-gcp by spring-cloud.
the class SpannerMutationFactoryImplTests method deleteKeyTest.
@Test
public void deleteKeyTest() {
Key key = Key.of("key1");
Mutation mutation = this.spannerMutationFactory.delete(TestEntity.class, key);
assertEquals("custom_test_table", mutation.getTable());
assertEquals(Op.DELETE, mutation.getOperation());
List<String> keys = new ArrayList<>();
mutation.getKeySet().getKeys().forEach((k) -> {
keys.add((String) (k.getParts().iterator().next()));
});
assertThat(keys, containsInAnyOrder("key1"));
}
use of com.google.cloud.spanner.Mutation in project spring-cloud-gcp by spring-cloud.
the class SpannerMutationFactoryImplTests method deleteEntityTest.
@Test
public void deleteEntityTest() {
TestEntity t1 = new TestEntity();
t1.id = "key1";
Mutation mutation = this.spannerMutationFactory.delete(t1);
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(t1.id));
}
use of com.google.cloud.spanner.Mutation in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method upsertColumnsSetTest.
@Test
public void upsertColumnsSetTest() {
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.upsert(same(entity), eq(Optional.of(cols)))).thenReturn(mutation);
this.spannerTemplate.upsert(entity, Optional.of(cols));
verify(this.databaseClient, times(1)).write(eq(Arrays.asList(mutation)));
}
Aggregations