Search in sources :

Example 6 with User

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

Example 7 with User

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

Example 8 with User

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

Example 9 with User

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

Example 10 with User

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);
}
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)18 User (org.springframework.cloud.gcp.data.firestore.entities.User)18 Address (org.springframework.cloud.gcp.data.firestore.entities.User.Address)4 List (java.util.List)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Matchers.is (org.hamcrest.Matchers.is)3 Assume.assumeThat (org.junit.Assume.assumeThat)3 Before (org.junit.Before)3 BeforeClass (org.junit.BeforeClass)3 RunWith (org.junit.runner.RunWith)3 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)3 Mockito.reset (org.mockito.Mockito.reset)3 Mockito.times (org.mockito.Mockito.times)3 Mockito.verify (org.mockito.Mockito.verify)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 ReactiveFirestoreTransactionManager (org.springframework.cloud.gcp.data.firestore.transaction.ReactiveFirestoreTransactionManager)3 PageRequest (org.springframework.data.domain.PageRequest)3 ContextConfiguration (org.springframework.test.context.ContextConfiguration)3 SpringRunner (org.springframework.test.context.junit4.SpringRunner)3 TransactionalOperator (org.springframework.transaction.reactive.TransactionalOperator)3