use of com.google.cloud.spanner.Mutation.WriteBuilder in project spring-cloud-gcp by spring-cloud.
the class SpannerObjectMapperImplTests method writeUnsupportedTypeIterableTest.
@Test(expected = SpannerDataException.class)
public void writeUnsupportedTypeIterableTest() {
FaultyTestEntity2 ft = new FaultyTestEntity2();
ft.listWithUnsupportedInnerType = new ArrayList<TestEntity>();
WriteBuilder writeBuilder = Mutation.newInsertBuilder("faulty_test_table_2");
this.objectMapper.write(ft, writeBuilder);
}
use of com.google.cloud.spanner.Mutation.WriteBuilder in project spring-cloud-gcp by spring-cloud.
the class SpannerObjectMapperImplTests method writeUnannotatedIterableTest.
@Test(expected = SpannerDataException.class)
public void writeUnannotatedIterableTest() {
FaultyTestEntity ft = new FaultyTestEntity();
ft.doubleList = new ArrayList<>();
WriteBuilder writeBuilder = Mutation.newInsertBuilder("faulty_test_table");
this.objectMapper.write(ft, writeBuilder);
}
use of com.google.cloud.spanner.Mutation.WriteBuilder in project spanner-jdbc by olavloite.
the class ValueBinderExpressionVisitorAdapterTest method create.
private ValueBinderExpressionVisitorAdapter<WriteBuilder> create() {
ParameterStore parameterStore = new ParameterStore();
WriteBuilder builder = Mutation.newInsertBuilder("INSERT INTO FOO (ID, COL1, COL2) VALUES (?, ?, ?)");
ValueBinder<WriteBuilder> binder = builder.set("COL1");
ValueBinderExpressionVisitorAdapter<WriteBuilder> res = new ValueBinderExpressionVisitorAdapter<>(parameterStore, binder, "COL1");
return res;
}
use of com.google.cloud.spanner.Mutation.WriteBuilder in project spring-cloud-gcp by spring-cloud.
the class SpannerObjectMapperImplTests method writeTest.
@Test
public void writeTest() throws ClassNotFoundException {
TestEntity t = new TestEntity();
t.id = "key1";
t.stringField = "string";
t.booleanField = true;
t.intField = 123;
t.longField = 3L;
t.doubleField = 3.33;
t.doubleArray = new double[] { 3.33, 3.33, 3.33 };
t.doubleList = new ArrayList<>();
t.doubleList.add(3.33);
t.stringList = new ArrayList<>();
t.stringList.add("stringstringstring");
t.dateField = Date.fromYearMonthDay(2018, 11, 22);
t.timestampField = Timestamp.ofTimeMicroseconds(333);
t.bytes = ByteArray.copyFrom("333");
t.booleanList = new ArrayList<>();
t.booleanList.add(t.booleanField);
t.longList = new ArrayList<>();
t.longList.add(t.longField);
t.dateList = new ArrayList<>();
t.dateList.add(t.dateField);
t.timestampList = new ArrayList<>();
t.timestampList.add(t.timestampField);
t.bytesList = new ArrayList<>();
t.bytesList.add(t.bytes);
WriteBuilder writeBuilder = mock(WriteBuilder.class);
ValueBinder<WriteBuilder> idBinder = mock(ValueBinder.class);
when(idBinder.to(anyString())).thenReturn(null);
when(writeBuilder.set(eq("id"))).thenReturn(idBinder);
ValueBinder<WriteBuilder> stringFieldBinder = mock(ValueBinder.class);
when(stringFieldBinder.to(anyString())).thenReturn(null);
when(writeBuilder.set(eq("custom_col"))).thenReturn(stringFieldBinder);
ValueBinder<WriteBuilder> booleanFieldBinder = mock(ValueBinder.class);
when(booleanFieldBinder.to((Boolean) any())).thenReturn(null);
when(writeBuilder.set(eq("booleanField"))).thenReturn(booleanFieldBinder);
ValueBinder<WriteBuilder> intFieldBinder = mock(ValueBinder.class);
when(intFieldBinder.to(anyLong())).thenReturn(null);
when(writeBuilder.set(eq("intField"))).thenReturn(intFieldBinder);
ValueBinder<WriteBuilder> longFieldBinder = mock(ValueBinder.class);
when(longFieldBinder.to(anyLong())).thenReturn(null);
when(writeBuilder.set(eq("longField"))).thenReturn(longFieldBinder);
ValueBinder<WriteBuilder> doubleFieldBinder = mock(ValueBinder.class);
when(doubleFieldBinder.to(anyDouble())).thenReturn(null);
when(writeBuilder.set(eq("doubleField"))).thenReturn(doubleFieldBinder);
ValueBinder<WriteBuilder> doubleArrayFieldBinder = mock(ValueBinder.class);
when(doubleArrayFieldBinder.toFloat64Array((double[]) any())).thenReturn(null);
when(writeBuilder.set(eq("doubleArray"))).thenReturn(doubleArrayFieldBinder);
ValueBinder<WriteBuilder> doubleListFieldBinder = mock(ValueBinder.class);
when(doubleListFieldBinder.toFloat64Array((Iterable<Double>) any())).thenReturn(null);
when(writeBuilder.set(eq("doubleList"))).thenReturn(doubleListFieldBinder);
ValueBinder<WriteBuilder> stringListFieldBinder = mock(ValueBinder.class);
when(stringListFieldBinder.toStringArray(any())).thenReturn(null);
when(writeBuilder.set(eq("stringList"))).thenReturn(stringListFieldBinder);
ValueBinder<WriteBuilder> booleanListFieldBinder = mock(ValueBinder.class);
when(booleanListFieldBinder.toBoolArray((Iterable<Boolean>) any())).thenReturn(null);
when(writeBuilder.set(eq("booleanList"))).thenReturn(booleanListFieldBinder);
ValueBinder<WriteBuilder> longListFieldBinder = mock(ValueBinder.class);
when(longListFieldBinder.toInt64Array((Iterable<Long>) any())).thenReturn(null);
when(writeBuilder.set(eq("longList"))).thenReturn(longListFieldBinder);
ValueBinder<WriteBuilder> timestampListFieldBinder = mock(ValueBinder.class);
when(timestampListFieldBinder.toTimestampArray(any())).thenReturn(null);
when(writeBuilder.set(eq("timestampList"))).thenReturn(timestampListFieldBinder);
ValueBinder<WriteBuilder> dateListFieldBinder = mock(ValueBinder.class);
when(dateListFieldBinder.toDateArray(any())).thenReturn(null);
when(writeBuilder.set(eq("dateList"))).thenReturn(dateListFieldBinder);
ValueBinder<WriteBuilder> bytesListFieldBinder = mock(ValueBinder.class);
when(bytesListFieldBinder.toDateArray(any())).thenReturn(null);
when(writeBuilder.set(eq("bytesList"))).thenReturn(bytesListFieldBinder);
ValueBinder<WriteBuilder> dateFieldBinder = mock(ValueBinder.class);
when(dateFieldBinder.to((Date) any())).thenReturn(null);
when(writeBuilder.set(eq("dateField"))).thenReturn(dateFieldBinder);
ValueBinder<WriteBuilder> timestampFieldBinder = mock(ValueBinder.class);
when(timestampFieldBinder.to((Timestamp) any())).thenReturn(null);
when(writeBuilder.set(eq("timestampField"))).thenReturn(timestampFieldBinder);
ValueBinder<WriteBuilder> bytesFieldBinder = mock(ValueBinder.class);
when(bytesFieldBinder.to((ByteArray) any())).thenReturn(null);
when(writeBuilder.set(eq("bytes"))).thenReturn(bytesFieldBinder);
this.objectMapper.write(t, writeBuilder);
verify(idBinder, times(1)).to(eq(t.id));
verify(stringFieldBinder, times(1)).to(eq(t.stringField));
verify(booleanFieldBinder, times(1)).to(eq(Boolean.valueOf(t.booleanField)));
verify(intFieldBinder, times(1)).to(eq(Long.valueOf(t.intField)));
verify(longFieldBinder, times(1)).to(eq(Long.valueOf(t.longField)));
verify(doubleFieldBinder, times(1)).to(eq(Double.valueOf(t.doubleField)));
verify(doubleArrayFieldBinder, times(1)).toFloat64Array(eq(t.doubleArray));
verify(doubleListFieldBinder, times(1)).toFloat64Array(eq(t.doubleList));
verify(stringListFieldBinder, times(1)).toStringArray(eq(t.stringList));
verify(booleanListFieldBinder, times(1)).toBoolArray(eq(t.booleanList));
verify(longListFieldBinder, times(1)).toInt64Array(eq(t.longList));
verify(timestampListFieldBinder, times(1)).toTimestampArray(eq(t.timestampList));
verify(dateListFieldBinder, times(1)).toDateArray(eq(t.dateList));
verify(bytesListFieldBinder, times(1)).toBytesArray(eq(t.bytesList));
verify(dateFieldBinder, times(1)).to(eq(t.dateField));
verify(timestampFieldBinder, times(1)).to(eq(t.timestampField));
verify(bytesFieldBinder, times(1)).to(eq(t.bytes));
}
use of com.google.cloud.spanner.Mutation.WriteBuilder in project spring-cloud-gcp by spring-cloud.
the class SpannerObjectMapperImplTests method writeSomeColumnsTest.
@Test
public void writeSomeColumnsTest() throws ClassNotFoundException {
TestEntity t = new TestEntity();
t.id = "key1";
t.stringField = "string";
WriteBuilder writeBuilder = mock(WriteBuilder.class);
ValueBinder<WriteBuilder> idBinder = mock(ValueBinder.class);
when(idBinder.to(anyString())).thenReturn(null);
when(writeBuilder.set(eq("id"))).thenReturn(idBinder);
ValueBinder<WriteBuilder> stringFieldBinder = mock(ValueBinder.class);
when(stringFieldBinder.to(anyString())).thenReturn(null);
when(writeBuilder.set(eq("custom_col"))).thenReturn(stringFieldBinder);
ValueBinder<WriteBuilder> booleanFieldBinder = mock(ValueBinder.class);
when(booleanFieldBinder.to((Boolean) any())).thenReturn(null);
when(writeBuilder.set(eq("booleanField"))).thenReturn(booleanFieldBinder);
this.objectMapper.write(t, writeBuilder, new HashSet<>(Arrays.asList(new String[] { "id", "custom_col" })));
verify(idBinder, times(1)).to(eq(t.id));
verify(stringFieldBinder, times(1)).to(eq(t.stringField));
verifyZeroInteractions(booleanFieldBinder);
}
Aggregations