Search in sources :

Example 1 with Address

use of org.springframework.cloud.gcp.data.firestore.entities.User.Address 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);
}
Also used : User(org.springframework.cloud.gcp.data.firestore.entities.User) Address(org.springframework.cloud.gcp.data.firestore.entities.User.Address) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 User (org.springframework.cloud.gcp.data.firestore.entities.User)1 Address (org.springframework.cloud.gcp.data.firestore.entities.User.Address)1