use of com.google.cloud.spring.data.firestore.entities.User in project spring-cloud-gcp by GoogleCloudPlatform.
the class FirestoreRepositoryIntegrationTests method pageableQueryTest.
// end::repository_part_tree[]
@Test
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 com.google.cloud.spring.data.firestore.entities.User in project spring-cloud-gcp by GoogleCloudPlatform.
the class FirestoreRepositoryIntegrationTests method testDoubleSub.
@Test
void testDoubleSub() {
User alice = new User("Alice", 29);
User bob = new User("Bob", 60);
this.userRepository.save(alice).then(this.userRepository.save(bob)).block();
Mono<User> testUser = this.userRepository.findByAge(29).next();
Flux<String> stringFlux = userRepository.findAll().flatMap(user -> testUser.flatMap(user1 -> Mono.just(user.getName() + " " + user1.getName())));
List<String> list = stringFlux.collectList().block();
assertThat(list).contains("Alice Alice", "Bob Alice");
}
use of com.google.cloud.spring.data.firestore.entities.User in project spring-cloud-gcp by GoogleCloudPlatform.
the class FirestoreRepositoryIntegrationTests method containsFilterQueryTest.
@Test
void containsFilterQueryTest() {
User u1 = new User("Cloud", 22, Arrays.asList("cat", "dog"));
User u2 = new User("Squall", 17, Collections.singletonList("pony"));
Flux<User> users = Flux.fromArray(new User[] { u1, u2 });
this.userRepository.saveAll(users).blockLast();
List<String> pagedUsers = this.userRepository.findByPetsContains(Arrays.asList("cat", "dog")).map(User::getName).collectList().block();
assertThat(pagedUsers).containsExactly("Cloud");
pagedUsers = this.userRepository.findByPetsContains(Arrays.asList("cat", "pony")).map(User::getName).collectList().block();
assertThat(pagedUsers).containsExactlyInAnyOrder("Cloud", "Squall");
pagedUsers = this.userRepository.findByAgeAndPetsContains(17, Arrays.asList("cat", "pony")).map(User::getName).collectList().block();
assertThat(pagedUsers).containsExactlyInAnyOrder("Squall");
pagedUsers = this.userRepository.findByPetsContainsAndAgeIn("cat", Arrays.asList(22, 23)).map(User::getName).collectList().block();
assertThat(pagedUsers).containsExactlyInAnyOrder("Cloud");
}
use of com.google.cloud.spring.data.firestore.entities.User in project spring-cloud-gcp by GoogleCloudPlatform.
the class FirestoreRepositoryIntegrationTests method testOrderBy.
@Test
void testOrderBy() {
User alice = new User("Alice", 99);
User bob = new User("Bob", 99);
User zelda = new User("Zelda", 99);
User claire = new User("Claire", 80);
User dave = new User("Dave", 70);
Flux<User> users = Flux.fromArray(new User[] { alice, bob, zelda, claire, dave });
this.userRepository.saveAll(users).blockLast();
StepVerifier.create(this.userRepository.findByAge(99, Sort.by(Order.desc("name"))).map(User::getName)).expectNext("Zelda", "Bob", "Alice").verifyComplete();
StepVerifier.create(this.userRepository.findByAgeOrderByNameDesc(99).map(User::getName)).expectNext("Zelda", "Bob", "Alice").verifyComplete();
StepVerifier.create(this.userRepository.findAllByOrderByAge().map(User::getName)).expectNext("Dave", "Claire", "Alice", "Bob", "Zelda").verifyComplete();
}
use of com.google.cloud.spring.data.firestore.entities.User in project spring-cloud-gcp by GoogleCloudPlatform.
the class FirestoreIntegrationTests method saveTest.
@Test
void saveTest() {
assertThat(this.firestoreTemplate.count(User.class).block()).isZero();
User u1 = new User("Cloud", 22);
this.firestoreTemplate.save(u1).block();
assertThat(this.firestoreTemplate.findAll(User.class).collectList().block()).containsExactly(u1);
}
Aggregations