Search in sources :

Example 6 with Trade

use of org.springframework.cloud.gcp.data.spanner.test.domain.Trade in project spring-cloud-gcp by spring-cloud.

the class SpannerRepositoryIntegrationTests method queryOptionalSingleValueTest.

@Test
public void queryOptionalSingleValueTest() {
    Trade trade = Trade.aTrade(null, 0);
    this.spannerOperations.insert(trade);
    Optional<String> nonEmpty = tradeRepository.fetchSymbolById(trade.getId());
    assertThat(nonEmpty.isPresent()).isTrue();
    assertThat(nonEmpty.get()).isEqualTo("ABCD");
    Optional<String> empty = tradeRepository.fetchSymbolById(trade.getId() + "doesNotExist");
    assertThat(empty.isPresent()).isFalse();
}
Also used : SubTrade(org.springframework.cloud.gcp.data.spanner.test.domain.SubTrade) Trade(org.springframework.cloud.gcp.data.spanner.test.domain.Trade) AbstractSpannerIntegrationTest(org.springframework.cloud.gcp.data.spanner.test.AbstractSpannerIntegrationTest) Test(org.junit.Test)

Example 7 with Trade

use of org.springframework.cloud.gcp.data.spanner.test.domain.Trade in project spring-cloud-gcp by spring-cloud.

the class SpannerRepositoryIntegrationTests method existsTest.

@Test
public void existsTest() {
    Trade trade = Trade.aTrade();
    this.tradeRepository.save(trade);
    SpannerPersistentEntity<?> persistentEntity = this.spannerMappingContext.getPersistentEntity(Trade.class);
    PersistentPropertyAccessor accessor = persistentEntity.getPropertyAccessor(trade);
    PersistentProperty idProperty = persistentEntity.getIdProperty();
    Key key = (Key) accessor.getProperty(idProperty);
    assertThat(this.tradeRepository.existsById(key)).isTrue();
    this.tradeRepository.delete(trade);
    assertThat(this.tradeRepository.existsById(key)).isFalse();
}
Also used : SubTrade(org.springframework.cloud.gcp.data.spanner.test.domain.SubTrade) Trade(org.springframework.cloud.gcp.data.spanner.test.domain.Trade) PersistentPropertyAccessor(org.springframework.data.mapping.PersistentPropertyAccessor) PersistentProperty(org.springframework.data.mapping.PersistentProperty) Key(com.google.cloud.spanner.Key) AbstractSpannerIntegrationTest(org.springframework.cloud.gcp.data.spanner.test.AbstractSpannerIntegrationTest) Test(org.junit.Test)

Aggregations

Trade (org.springframework.cloud.gcp.data.spanner.test.domain.Trade)7 Test (org.junit.Test)6 AbstractSpannerIntegrationTest (org.springframework.cloud.gcp.data.spanner.test.AbstractSpannerIntegrationTest)6 SubTrade (org.springframework.cloud.gcp.data.spanner.test.domain.SubTrade)4 Key (com.google.cloud.spanner.Key)2 ArrayList (java.util.ArrayList)2 PersistentProperty (org.springframework.data.mapping.PersistentProperty)2 PersistentPropertyAccessor (org.springframework.data.mapping.PersistentPropertyAccessor)2 Timestamp (com.google.cloud.Timestamp)1 Statement (com.google.cloud.spanner.Statement)1 Struct (com.google.cloud.spanner.Struct)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Sets (org.assertj.core.util.Sets)1 After (org.junit.After)1 Before (org.junit.Before)1