use of org.springframework.cloud.gcp.data.firestore.entities.User in project spring-cloud-gcp by spring-cloud.
the class FirestoreRepositoryIntegrationTests method writeReadDeleteTest.
@Test
public // 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);
}
use of org.springframework.cloud.gcp.data.firestore.entities.User in project spring-cloud-gcp by spring-cloud.
the class FirestoreRepositoryIntegrationTests method sortQueryTest.
@Test
public void sortQueryTest() {
Flux<User> users = Flux.fromStream(IntStream.range(1, 11).boxed()).map(n -> new User("blah-person" + n, n));
this.userRepository.saveAll(users).blockLast();
List<String> pagedUsers = this.userRepository.findByAgeGreaterThan(7, Sort.by(Order.asc("age"))).map(User::getName).collectList().block();
assertThat(pagedUsers).containsExactlyInAnyOrder("blah-person8", "blah-person9", "blah-person10");
}
use of org.springframework.cloud.gcp.data.firestore.entities.User in project spring-cloud-gcp by spring-cloud.
the class FirestoreRepositoryIntegrationTests method transactionalOperatorTest.
// end::repository_built_in[]
@Test
public void transactionalOperatorTest() {
// tag::repository_transactional_operator[]
DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition();
transactionDefinition.setReadOnly(false);
TransactionalOperator operator = TransactionalOperator.create(this.txManager, transactionDefinition);
// end::repository_transactional_operator[]
// tag::repository_operations_in_a_transaction[]
User alice = new User("Alice", 29);
User bob = new User("Bob", 60);
this.userRepository.save(alice).then(this.userRepository.save(bob)).as(operator::transactional).block();
this.userRepository.findAll().flatMap(a -> {
a.setAge(a.getAge() - 1);
return this.userRepository.save(a);
}).as(operator::transactional).collectList().block();
assertThat(this.userRepository.findAll().map(User::getAge).collectList().block()).containsExactlyInAnyOrder(28, 59);
// end::repository_operations_in_a_transaction[]
}
Aggregations