Search in sources :

Example 1 with SimpleFirestoreReactiveRepository

use of com.google.cloud.spring.data.firestore.SimpleFirestoreReactiveRepository in project spring-cloud-gcp by GoogleCloudPlatform.

the class FirestoreRepositoryIntegrationTests method writeReadDeleteTest.

@Test
// tag::repository_built_in[]
void writeReadDeleteTest() {
    List<User.Address> addresses = Arrays.asList(new User.Address("123 Alice st", "US"), new User.Address("1 Alice ave", "US"));
    User.Address homeAddress = new User.Address("10 Alice blvd", "UK");
    User alice = new User("Alice", 29, null, addresses, homeAddress);
    User bob = new User("Bob", 60);
    this.userRepository.save(alice).block();
    this.userRepository.save(bob).block();
    assertThat(this.userRepository.count().block()).isEqualTo(2);
    assertThat(this.userRepository.findAll().map(User::getName).collectList().block()).containsExactlyInAnyOrder("Alice", "Bob");
    User aliceLoaded = this.userRepository.findById("Alice").block();
    assertThat(aliceLoaded.getAddresses()).isEqualTo(addresses);
    assertThat(aliceLoaded.getHomeAddress()).isEqualTo(homeAddress);
    // cast to SimpleFirestoreReactiveRepository for method be reachable with Spring Boot 2.4
    SimpleFirestoreReactiveRepository repository = AopTestUtils.getTargetObject(this.userRepository);
    StepVerifier.create(repository.deleteAllById(Arrays.asList("Alice", "Bob")).then(this.userRepository.count())).expectNext(0L).verifyComplete();
}
Also used : Address(com.google.cloud.spring.data.firestore.entities.User.Address) User(com.google.cloud.spring.data.firestore.entities.User) Address(com.google.cloud.spring.data.firestore.entities.User.Address) SimpleFirestoreReactiveRepository(com.google.cloud.spring.data.firestore.SimpleFirestoreReactiveRepository) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleFirestoreReactiveRepository (com.google.cloud.spring.data.firestore.SimpleFirestoreReactiveRepository)1 User (com.google.cloud.spring.data.firestore.entities.User)1 Address (com.google.cloud.spring.data.firestore.entities.User.Address)1 Test (org.junit.jupiter.api.Test)1