Search in sources :

Example 61 with StepVerifier

use of reactor.test.StepVerifier in project cf-java-client by cloudfoundry.

the class PaginationUtilsTest method requestClientV2ResourcesEmpty.

@Test
public void requestClientV2ResourcesEmpty() {
    Spaces spaces = mock(Spaces.class, RETURNS_SMART_NULLS);
    requestListSpacesEmpty(spaces);
    PaginationUtils.requestClientV2Resources(page -> spaces.list(ListSpacesRequest.builder().page(page).build())).as(StepVerifier::create).expectComplete().verify(Duration.ofSeconds(1));
}
Also used : ListPackagesResponse(org.cloudfoundry.client.v3.packages.ListPackagesResponse) StepVerifier(reactor.test.StepVerifier) ListSpacesRequest(org.cloudfoundry.client.v2.spaces.ListSpacesRequest) TimeoutException(java.util.concurrent.TimeoutException) SpaceEntity(org.cloudfoundry.client.v2.spaces.SpaceEntity) BitsData(org.cloudfoundry.client.v3.packages.BitsData) ListUsersRequest(org.cloudfoundry.uaa.users.ListUsersRequest) Spaces(org.cloudfoundry.client.v2.spaces.Spaces) ListPackagesRequest(org.cloudfoundry.client.v3.packages.ListPackagesRequest) SpaceResource(org.cloudfoundry.client.v2.spaces.SpaceResource) PackageResource(org.cloudfoundry.client.v3.packages.PackageResource) Duration(java.time.Duration) User(org.cloudfoundry.uaa.users.User) Name(org.cloudfoundry.uaa.users.Name) Packages(org.cloudfoundry.client.v3.packages.Packages) ListUsersResponse(org.cloudfoundry.uaa.users.ListUsersResponse) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Meta(org.cloudfoundry.uaa.users.Meta) Mockito.when(org.mockito.Mockito.when) ListSpacesResponse(org.cloudfoundry.client.v2.spaces.ListSpacesResponse) Users(org.cloudfoundry.uaa.users.Users) RETURNS_SMART_NULLS(org.mockito.Mockito.RETURNS_SMART_NULLS) PackageType(org.cloudfoundry.client.v3.packages.PackageType) Pagination(org.cloudfoundry.client.v3.Pagination) PackageState(org.cloudfoundry.client.v3.packages.PackageState) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Spaces(org.cloudfoundry.client.v2.spaces.Spaces) StepVerifier(reactor.test.StepVerifier) Test(org.junit.Test)

Example 62 with StepVerifier

use of reactor.test.StepVerifier in project cf-java-client by cloudfoundry.

the class PaginationUtilsTest method requestUaaResourcesEmpty.

@Test
public void requestUaaResourcesEmpty() {
    Users users = mock(Users.class, RETURNS_SMART_NULLS);
    requestListUsersEmpty(users, 1, 100);
    PaginationUtils.requestUaaResources(startIndex -> users.list(ListUsersRequest.builder().startIndex(startIndex).build())).as(StepVerifier::create).expectComplete().verify(Duration.ofSeconds(1));
}
Also used : ListPackagesResponse(org.cloudfoundry.client.v3.packages.ListPackagesResponse) StepVerifier(reactor.test.StepVerifier) ListSpacesRequest(org.cloudfoundry.client.v2.spaces.ListSpacesRequest) TimeoutException(java.util.concurrent.TimeoutException) SpaceEntity(org.cloudfoundry.client.v2.spaces.SpaceEntity) BitsData(org.cloudfoundry.client.v3.packages.BitsData) ListUsersRequest(org.cloudfoundry.uaa.users.ListUsersRequest) Spaces(org.cloudfoundry.client.v2.spaces.Spaces) ListPackagesRequest(org.cloudfoundry.client.v3.packages.ListPackagesRequest) SpaceResource(org.cloudfoundry.client.v2.spaces.SpaceResource) PackageResource(org.cloudfoundry.client.v3.packages.PackageResource) Duration(java.time.Duration) User(org.cloudfoundry.uaa.users.User) Name(org.cloudfoundry.uaa.users.Name) Packages(org.cloudfoundry.client.v3.packages.Packages) ListUsersResponse(org.cloudfoundry.uaa.users.ListUsersResponse) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Meta(org.cloudfoundry.uaa.users.Meta) Mockito.when(org.mockito.Mockito.when) ListSpacesResponse(org.cloudfoundry.client.v2.spaces.ListSpacesResponse) Users(org.cloudfoundry.uaa.users.Users) RETURNS_SMART_NULLS(org.mockito.Mockito.RETURNS_SMART_NULLS) PackageType(org.cloudfoundry.client.v3.packages.PackageType) Pagination(org.cloudfoundry.client.v3.Pagination) PackageState(org.cloudfoundry.client.v3.packages.PackageState) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Users(org.cloudfoundry.uaa.users.Users) StepVerifier(reactor.test.StepVerifier) Test(org.junit.Test)

Example 63 with StepVerifier

use of reactor.test.StepVerifier in project spring-framework by spring-projects.

the class R2dbcTransactionManagerUnitTests method doesNotSetIsolationLevelIfMatch.

@Test
void doesNotSetIsolationLevelIfMatch() {
    when(connectionMock.getTransactionIsolationLevel()).thenReturn(IsolationLevel.READ_COMMITTED);
    when(connectionMock.commitTransaction()).thenReturn(Mono.empty());
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    definition.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
    TransactionalOperator operator = TransactionalOperator.create(tm, definition);
    ConnectionFactoryUtils.getConnection(connectionFactoryMock).as(operator::transactional).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    verify(connectionMock).beginTransaction();
    verify(connectionMock, never()).setTransactionIsolationLevel(any());
    verify(connectionMock).commitTransaction();
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 64 with StepVerifier

use of reactor.test.StepVerifier in project spring-framework by spring-projects.

the class R2dbcTransactionManagerUnitTests method testBeginFails.

@Test
void testBeginFails() {
    reset(connectionFactoryMock);
    when(connectionFactoryMock.create()).thenReturn(Mono.error(new R2dbcBadGrammarException("fail")));
    when(connectionMock.rollbackTransaction()).thenReturn(Mono.empty());
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    definition.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
    TransactionalOperator operator = TransactionalOperator.create(tm, definition);
    ConnectionFactoryUtils.getConnection(connectionFactoryMock).as(operator::transactional).as(StepVerifier::create).expectErrorSatisfies(actual -> assertThat(actual).isInstanceOf(CannotCreateTransactionException.class).hasCauseInstanceOf(R2dbcBadGrammarException.class)).verify();
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) ConnectionFactory(io.r2dbc.spi.ConnectionFactory) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) TransactionDefinition(org.springframework.transaction.TransactionDefinition) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IllegalTransactionStateException(org.springframework.transaction.IllegalTransactionStateException) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) BDDMockito.when(org.mockito.BDDMockito.when) BDDMockito.verify(org.mockito.BDDMockito.verify) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionSynchronization(org.springframework.transaction.reactive.TransactionSynchronization) BDDMockito.never(org.mockito.BDDMockito.never) R2dbcBadGrammarException(io.r2dbc.spi.R2dbcBadGrammarException) TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) Mono(reactor.core.publisher.Mono) BDDMockito.verifyNoMoreInteractions(org.mockito.BDDMockito.verifyNoMoreInteractions) Connection(io.r2dbc.spi.Connection) Test(org.junit.jupiter.api.Test) TransactionSynchronizationManager(org.springframework.transaction.reactive.TransactionSynchronizationManager) IsolationLevel(io.r2dbc.spi.IsolationLevel) Assertions.fail(org.assertj.core.api.Assertions.fail) BDDMockito.mock(org.mockito.BDDMockito.mock) Statement(io.r2dbc.spi.Statement) BDDMockito.reset(org.mockito.BDDMockito.reset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) R2dbcBadGrammarException(io.r2dbc.spi.R2dbcBadGrammarException) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 65 with StepVerifier

use of reactor.test.StepVerifier in project spring-framework by spring-projects.

the class R2dbcTransactionManagerUnitTests method testTransactionSetRollbackOnly.

@Test
void testTransactionSetRollbackOnly() {
    when(connectionMock.rollbackTransaction()).thenReturn(Mono.empty());
    TestTransactionSynchronization sync = new TestTransactionSynchronization(TransactionSynchronization.STATUS_ROLLED_BACK);
    TransactionalOperator operator = TransactionalOperator.create(tm);
    operator.execute(tx -> {
        tx.setRollbackOnly();
        assertThat(tx.isNewTransaction()).isTrue();
        return TransactionSynchronizationManager.forCurrentTransaction().doOnNext(synchronizationManager -> {
            assertThat(synchronizationManager.hasResource(connectionFactoryMock)).isTrue();
            synchronizationManager.registerSynchronization(sync);
        }).then();
    }).as(StepVerifier::create).verifyComplete();
    verify(connectionMock).isAutoCommit();
    verify(connectionMock).beginTransaction();
    verify(connectionMock).rollbackTransaction();
    verify(connectionMock).close();
    verifyNoMoreInteractions(connectionMock);
    assertThat(sync.beforeCommitCalled).isFalse();
    assertThat(sync.afterCommitCalled).isFalse();
    assertThat(sync.beforeCompletionCalled).isTrue();
    assertThat(sync.afterCompletionCalled).isTrue();
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) ConnectionFactory(io.r2dbc.spi.ConnectionFactory) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) TransactionDefinition(org.springframework.transaction.TransactionDefinition) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IllegalTransactionStateException(org.springframework.transaction.IllegalTransactionStateException) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) BDDMockito.when(org.mockito.BDDMockito.when) BDDMockito.verify(org.mockito.BDDMockito.verify) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionSynchronization(org.springframework.transaction.reactive.TransactionSynchronization) BDDMockito.never(org.mockito.BDDMockito.never) R2dbcBadGrammarException(io.r2dbc.spi.R2dbcBadGrammarException) TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) Mono(reactor.core.publisher.Mono) BDDMockito.verifyNoMoreInteractions(org.mockito.BDDMockito.verifyNoMoreInteractions) Connection(io.r2dbc.spi.Connection) Test(org.junit.jupiter.api.Test) TransactionSynchronizationManager(org.springframework.transaction.reactive.TransactionSynchronizationManager) IsolationLevel(io.r2dbc.spi.IsolationLevel) Assertions.fail(org.assertj.core.api.Assertions.fail) BDDMockito.mock(org.mockito.BDDMockito.mock) Statement(io.r2dbc.spi.Statement) BDDMockito.reset(org.mockito.BDDMockito.reset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

StepVerifier (reactor.test.StepVerifier)82 Mono (reactor.core.publisher.Mono)56 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)48 Test (org.junit.jupiter.api.Test)45 Flux (reactor.core.publisher.Flux)41 Test (org.junit.Test)37 Duration (java.time.Duration)31 ClassPathResource (org.springframework.core.io.ClassPathResource)28 AbstractIntegrationTest (org.cloudfoundry.AbstractIntegrationTest)24 Collections (java.util.Collections)20 Mockito.mock (org.mockito.Mockito.mock)20 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)20 ConnectionFactory (io.r2dbc.spi.ConnectionFactory)19 Connection (io.r2dbc.spi.Connection)17 IOException (java.io.IOException)17 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)17 BeforeEach (org.junit.jupiter.api.BeforeEach)16 Autowired (org.springframework.beans.factory.annotation.Autowired)16 Result (io.r2dbc.spi.Result)14 Path (java.nio.file.Path)14