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();
}
Aggregations