use of com.google.cloud.spring.data.firestore.entities.User in project spring-cloud-gcp by GoogleCloudPlatform.
the class FirestoreRepositoryIntegrationTests method inFilterQueryTest.
@Test
void inFilterQueryTest() {
User u1 = new User("Cloud", 22);
User u2 = new User("Squall", 17);
Flux<User> users = Flux.fromArray(new User[] { u1, u2 });
this.userRepository.saveAll(users).blockLast();
List<String> pagedUsers = this.userRepository.findByAgeIn(Arrays.asList(22, 23, 24)).map(User::getName).collectList().block();
assertThat(pagedUsers).containsExactly("Cloud");
pagedUsers = this.userRepository.findByAgeIn(Arrays.asList(17, 22)).map(User::getName).collectList().block();
assertThat(pagedUsers).containsExactly("Cloud", "Squall");
pagedUsers = this.userRepository.findByAgeIn(Arrays.asList(18, 23)).map(User::getName).collectList().block();
assertThat(pagedUsers).isEmpty();
pagedUsers = this.userRepository.findByAgeNotIn(Arrays.asList(17, 22, 33)).map(User::getName).collectList().block();
assertThat(pagedUsers).isEmpty();
pagedUsers = this.userRepository.findByAgeNotIn(Arrays.asList(10, 20, 30)).map(User::getName).collectList().block();
assertThat(pagedUsers).containsExactlyInAnyOrder("Cloud", "Squall");
pagedUsers = this.userRepository.findByAgeNotIn(Arrays.asList(17, 33)).map(User::getName).collectList().block();
assertThat(pagedUsers).containsExactly("Cloud");
}
use of com.google.cloud.spring.data.firestore.entities.User in project spring-cloud-gcp by GoogleCloudPlatform.
the class FirestoreRepositoryIntegrationTests method transactionalOperatorTest.
// end::repository_built_in[]
@Test
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[]
}
use of com.google.cloud.spring.data.firestore.entities.User in project spring-cloud-gcp by GoogleCloudPlatform.
the class FirestoreRepositoryIntegrationTests method countTest.
@Test
void countTest() {
Flux<User> users = Flux.fromStream(IntStream.range(1, 10).boxed()).map(n -> new User("blah-person" + n, n));
this.userRepository.saveAll(users).blockLast();
long count = this.userRepository.countByAgeIsGreaterThan(5).block();
assertThat(count).isEqualTo(4);
}
Aggregations