use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterSaveEvent 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();
List<Mutation> mutations = Collections.singletonList(mutation);
Set<String> cols = new HashSet<>(Arrays.asList("a", "b"));
when(this.mutationFactory.upsert(same(entity), eq(cols))).thenReturn(Collections.singletonList(mutation));
verifyBeforeAndAfterEvents(new BeforeSaveEvent(Collections.singletonList(entity), cols), new AfterSaveEvent(mutations, Collections.singletonList(entity), cols), () -> this.spannerTemplate.upsert(entity, cols), x -> x.verify(this.databaseClient, times(1)).write(eq(mutations)));
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterSaveEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method insertTest.
@Test
public void insertTest() {
Mutation mutation = Mutation.newInsertBuilder("custom_test_table").build();
TestEntity entity = new TestEntity();
List<Mutation> mutations = Collections.singletonList(mutation);
when(this.mutationFactory.insert(entity)).thenReturn(mutations);
verifyBeforeAndAfterEvents(new BeforeSaveEvent(Collections.singletonList(entity), null), new AfterSaveEvent(mutations, Collections.singletonList(entity), null), () -> this.spannerTemplate.insert(entity), x -> x.verify(this.databaseClient, times(1)).write(eq(mutations)));
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterSaveEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method updateTest.
@Test
public void updateTest() {
Mutation mutation = Mutation.newUpdateBuilder("custom_test_table").build();
TestEntity entity = new TestEntity();
List<Mutation> mutations = Collections.singletonList(mutation);
when(this.mutationFactory.update(entity, null)).thenReturn(mutations);
verifyBeforeAndAfterEvents(new BeforeSaveEvent(Collections.singletonList(entity), null), new AfterSaveEvent(mutations, Collections.singletonList(entity), null), () -> this.spannerTemplate.update(entity), x -> x.verify(this.databaseClient, times(1)).write(eq(mutations)));
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterSaveEvent 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("a", "b"));
List<Mutation> mutations = Collections.singletonList(mutation);
when(this.mutationFactory.update(same(entity), eq(cols))).thenReturn(mutations);
verifyBeforeAndAfterEvents(new BeforeSaveEvent(Collections.singletonList(entity), cols), new AfterSaveEvent(mutations, Collections.singletonList(entity), cols), () -> this.spannerTemplate.update(entity, cols), x -> x.verify(this.databaseClient, times(1)).write(eq(mutations)));
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterSaveEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method updateAllTest.
@Test
public void updateAllTest() {
Mutation mutation = Mutation.newInsertOrUpdateBuilder("custom_test_table").build();
TestEntity entity = new TestEntity();
List<Mutation> mutations = Arrays.asList(mutation, mutation, mutation);
List entities = Arrays.asList(entity, entity, entity);
when(this.mutationFactory.update(same(entity), isNull())).thenReturn(Collections.singletonList(mutation));
verifyBeforeAndAfterEvents(new BeforeSaveEvent(entities, null), new AfterSaveEvent(mutations, entities, null), () -> this.spannerTemplate.updateAll(entities), x -> x.verify(this.databaseClient, times(1)).write(eq(mutations)));
}
Aggregations