Search in sources :

Example 6 with User

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");
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) User(com.google.cloud.spring.data.firestore.entities.User) Test(org.junit.jupiter.api.Test)

Example 7 with User

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");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Order(org.springframework.data.domain.Sort.Order) StepVerifier(reactor.test.StepVerifier) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Address(com.google.cloud.spring.data.firestore.entities.User.Address) Autowired(org.springframework.beans.factory.annotation.Autowired) AopTestUtils(org.springframework.test.util.AopTestUtils) User(com.google.cloud.spring.data.firestore.entities.User) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) EnabledIfSystemProperty(org.junit.jupiter.api.condition.EnabledIfSystemProperty) Sort(org.springframework.data.domain.Sort) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) PageRequest(org.springframework.data.domain.PageRequest) Mockito.times(org.mockito.Mockito.times) Mono(reactor.core.publisher.Mono) UserRepository(com.google.cloud.spring.data.firestore.entities.UserRepository) ReactiveFirestoreTransactionManager(com.google.cloud.spring.data.firestore.transaction.ReactiveFirestoreTransactionManager) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) List(java.util.List) SimpleFirestoreReactiveRepository(com.google.cloud.spring.data.firestore.SimpleFirestoreReactiveRepository) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Mockito.reset(org.mockito.Mockito.reset) Collections(java.util.Collections) User(com.google.cloud.spring.data.firestore.entities.User) Test(org.junit.jupiter.api.Test)

Example 8 with User

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");
}
Also used : User(com.google.cloud.spring.data.firestore.entities.User) Test(org.junit.jupiter.api.Test)

Example 9 with User

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();
}
Also used : User(com.google.cloud.spring.data.firestore.entities.User) Test(org.junit.jupiter.api.Test)

Example 10 with User

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);
}
Also used : User(com.google.cloud.spring.data.firestore.entities.User) Test(org.junit.jupiter.api.Test)

Aggregations

User (com.google.cloud.spring.data.firestore.entities.User)23 Test (org.junit.jupiter.api.Test)23 TransactionalOperator (org.springframework.transaction.reactive.TransactionalOperator)5 StepVerifier (reactor.test.StepVerifier)5 Address (com.google.cloud.spring.data.firestore.entities.User.Address)4 ReactiveFirestoreTransactionManager (com.google.cloud.spring.data.firestore.transaction.ReactiveFirestoreTransactionManager)4 List (java.util.List)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 EnabledIfSystemProperty (org.junit.jupiter.api.condition.EnabledIfSystemProperty)4 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4 Mockito.reset (org.mockito.Mockito.reset)4 Mockito.times (org.mockito.Mockito.times)4 Mockito.verify (org.mockito.Mockito.verify)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 ContextConfiguration (org.springframework.test.context.ContextConfiguration)4 SpringExtension (org.springframework.test.context.junit.jupiter.SpringExtension)4 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)4 Flux (reactor.core.publisher.Flux)4