Search in sources :

Example 11 with AfterSaveEvent

use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterSaveEvent 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();
    List<Mutation> mutations = Collections.singletonList(mutation);
    TestEntity entity = new TestEntity();
    Set<String> cols = new HashSet<>(Arrays.asList("a", "b"));
    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, "a", "b"), x -> x.verify(this.databaseClient, times(1)).write(eq(mutations)));
}
Also used : AfterSaveEvent(org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterSaveEvent) BeforeSaveEvent(org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeSaveEvent) Mutation(com.google.cloud.spanner.Mutation) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Mutation (com.google.cloud.spanner.Mutation)11 AfterSaveEvent (org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterSaveEvent)11 BeforeSaveEvent (org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeSaveEvent)11 Test (org.junit.Test)10 HashSet (java.util.HashSet)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3