use of org.springframework.cloud.gcp.data.spanner.core.convert.SpannerWriteConverter in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method setUp.
@Before
public void setUp() {
this.databaseClient = mock(DatabaseClient.class);
this.mappingContext = new SpannerMappingContext();
this.objectMapper = mock(SpannerEntityProcessor.class);
this.mutationFactory = mock(SpannerMutationFactory.class);
this.schemaUtils = new SpannerSchemaUtils(this.mappingContext, this.objectMapper, true);
this.readContext = mock(ReadContext.class);
when(this.databaseClient.singleUse()).thenReturn(this.readContext);
when(this.objectMapper.getWriteConverter()).thenReturn(new SpannerWriteConverter());
this.spannerTemplate = new SpannerTemplate(() -> this.databaseClient, this.mappingContext, this.objectMapper, this.mutationFactory, this.schemaUtils);
}
use of org.springframework.cloud.gcp.data.spanner.core.convert.SpannerWriteConverter in project spring-cloud-gcp by spring-cloud.
the class SpannerQueryLookupStrategyTests method getColumnsStringForSelectMultipleTest.
@Test
@SuppressWarnings("unchecked")
public void getColumnsStringForSelectMultipleTest() {
final SpannerPersistentEntity<TestEntity> entity = (SpannerPersistentEntity<TestEntity>) this.spannerMappingContext.getPersistentEntity(TestEntity.class);
Statement childrenRowsQuery = SpannerStatementQueryExecutor.buildQuery(KeySet.newBuilder().addKey(Key.of("k1.1", "k1.2")).addKey(Key.of("k2.1", "k2.2")).build(), entity, new SpannerWriteConverter(), this.spannerMappingContext, entity.getWhere());
assertThat(childrenRowsQuery.getSql()).isEqualTo("SELECT other, deleted, id, custom_col, id_2, ARRAY (SELECT AS STRUCT deleted, id3, id, id_2 " + "FROM child_test_table WHERE (child_test_table.id = custom_test_table.id " + "AND child_test_table.id_2 = custom_test_table.id_2) AND (deleted = false)) AS childEntities " + "FROM custom_test_table WHERE ((id = @tag0 AND id_2 = @tag1) " + "OR (id = @tag2 AND id_2 = @tag3)) AND (deleted = false)");
}
use of org.springframework.cloud.gcp.data.spanner.core.convert.SpannerWriteConverter in project spring-cloud-gcp by spring-cloud.
the class SpannerQueryLookupStrategyTests method getChildrenRowsQueryTest.
@Test
public void getChildrenRowsQueryTest() {
TestEntity t = new TestEntity();
t.id = "key";
t.id2 = "key2";
Statement statement = SpannerStatementQueryExecutor.getChildrenRowsQuery(Key.newBuilder().append(t.id).append(t.id2).build(), this.spannerMappingContext.getPersistentEntity(TestEntity.class).getPersistentProperty("childEntities"), new SpannerWriteConverter(), this.spannerMappingContext);
assertThat(statement.getSql()).isEqualTo("SELECT deleted, id3, id, id_2 FROM child_test_table WHERE ((id = @tag0 AND id_2 = @tag1)) AND (deleted = false)");
assertThat(statement.getParameters()).hasSize(2);
assertThat(statement.getParameters().get("tag0").getString()).isEqualTo("key");
assertThat(statement.getParameters().get("tag1").getString()).isEqualTo("key2");
}
use of org.springframework.cloud.gcp.data.spanner.core.convert.SpannerWriteConverter in project spring-cloud-gcp by spring-cloud.
the class SpannerStatementQueryTests method initMocks.
@Before
public void initMocks() throws NoSuchMethodException {
this.queryMethod = mock(SpannerQueryMethod.class);
// this is a dummy object. it is not mockable otherwise.
Method method = Object.class.getMethod("toString");
when(this.queryMethod.getMethod()).thenReturn(method);
this.spannerTemplate = mock(SpannerTemplate.class);
SpannerEntityProcessor spannerEntityProcessor = mock(SpannerEntityProcessor.class);
when(this.spannerTemplate.getSpannerEntityProcessor()).thenReturn(spannerEntityProcessor);
when(spannerEntityProcessor.getWriteConverter()).thenReturn(new SpannerWriteConverter());
this.spannerMappingContext = new SpannerMappingContext();
}
use of org.springframework.cloud.gcp.data.spanner.core.convert.SpannerWriteConverter in project spring-cloud-gcp by spring-cloud.
the class SqlSpannerQueryTests method initMocks.
@Before
public void initMocks() throws NoSuchMethodException {
this.queryMethod = mock(SpannerQueryMethod.class);
// this is a dummy object. it is not mockable otherwise.
Method method = Object.class.getMethod("toString");
when(this.queryMethod.getMethod()).thenReturn(method);
when(this.spannerEntityProcessor.getWriteConverter()).thenReturn(new SpannerWriteConverter());
this.spannerTemplate = spy(new SpannerTemplate(() -> this.databaseClient, this.spannerMappingContext, this.spannerEntityProcessor, mock(SpannerMutationFactory.class), new SpannerSchemaUtils(this.spannerMappingContext, this.spannerEntityProcessor, true)));
this.expressionParser = new SpelExpressionParser();
this.evaluationContextProvider = mock(QueryMethodEvaluationContextProvider.class);
}
Aggregations