use of org.springframework.cloud.gcp.data.firestore.entities.User in project spring-cloud-gcp by spring-cloud.
the class FirestoreRepositoryIntegrationTests method transactionPropagationTest.
@Test
public void transactionPropagationTest() {
User alice = new User("Alice", 29);
User bob = new User("Bob", 60);
this.userRepository.save(alice).then(this.userRepository.save(bob)).block();
this.userService.updateUsersTransactionPropagation().block();
verify(this.transactionManager, times(1)).commit(any());
verify(this.transactionManager, times(0)).rollback(any());
verify(this.transactionManager, times(1)).getReactiveTransaction(any());
assertThat(this.userRepository.findAll().map(User::getAge).collectList().block()).containsExactlyInAnyOrder(28, 59);
}
use of org.springframework.cloud.gcp.data.firestore.entities.User in project spring-cloud-gcp by spring-cloud.
the class FirestoreRepositoryIntegrationTests method pageableQueryTest.
// end::repository_part_tree[]
@Test
public void pageableQueryTest() {
Flux<User> users = Flux.fromStream(IntStream.range(1, 11).boxed()).map(n -> new User("blah-person" + n, n));
this.userRepository.saveAll(users).blockLast();
PageRequest pageRequest = PageRequest.of(2, 3, Sort.by(Order.desc("age")));
List<String> pagedUsers = this.userRepository.findByAgeGreaterThan(0, pageRequest).map(User::getName).collectList().block();
assertThat(pagedUsers).containsExactlyInAnyOrder("blah-person4", "blah-person3", "blah-person2");
}
use of org.springframework.cloud.gcp.data.firestore.entities.User in project spring-cloud-gcp by spring-cloud.
the class FirestoreRepositoryIntegrationTests method inFilterQueryTest.
@Test
public 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 org.springframework.cloud.gcp.data.firestore.entities.User in project spring-cloud-gcp by spring-cloud.
the class FirestoreRepositoryIntegrationTests method countTest.
@Test
public 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);
}
use of org.springframework.cloud.gcp.data.firestore.entities.User in project spring-cloud-gcp by spring-cloud.
the class FirestoreRepositoryIntegrationTests method partTreeRepositoryMethodTest.
@Test
public // tag::repository_part_tree[]
void partTreeRepositoryMethodTest() {
User u1 = new User("Cloud", 22, null, null, new Address("1 First st., NYC", "USA"));
u1.favoriteDrink = "tea";
User u2 = new User("Squall", 17, null, null, new Address("2 Second st., London", "UK"));
u2.favoriteDrink = "wine";
Flux<User> users = Flux.fromArray(new User[] { u1, u2 });
this.userRepository.saveAll(users).blockLast();
assertThat(this.userRepository.count().block()).isEqualTo(2);
assertThat(this.userRepository.findByAge(22).collectList().block()).containsExactly(u1);
assertThat(this.userRepository.findByAgeNot(22).collectList().block()).containsExactly(u2);
assertThat(this.userRepository.findByHomeAddressCountry("USA").collectList().block()).containsExactly(u1);
assertThat(this.userRepository.findByFavoriteDrink("wine").collectList().block()).containsExactly(u2);
assertThat(this.userRepository.findByAgeGreaterThanAndAgeLessThan(20, 30).collectList().block()).containsExactly(u1);
assertThat(this.userRepository.findByAgeGreaterThan(10).collectList().block()).containsExactlyInAnyOrder(u1, u2);
}
Aggregations