Search in sources :

Example 26 with StepVerifier

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

the class R2dbcTransactionManagerUnitTests method restoresAutoCommit.

@Test
void restoresAutoCommit() {
    when(connectionMock.isAutoCommit()).thenReturn(true);
    when(connectionMock.setAutoCommit(anyBoolean())).thenReturn(Mono.empty());
    when(connectionMock.commitTransaction()).thenReturn(Mono.empty());
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    TransactionalOperator operator = TransactionalOperator.create(tm, definition);
    ConnectionFactoryUtils.getConnection(connectionFactoryMock).as(operator::transactional).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    verify(connectionMock).beginTransaction();
    verify(connectionMock).setAutoCommit(false);
    verify(connectionMock).setAutoCommit(true);
    verify(connectionMock).commitTransaction();
    verify(connectionMock).close();
}
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 27 with StepVerifier

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

the class DefaultDatabaseClientUnitTests method selectShouldEmitAllValues.

@Test
void selectShouldEmitAllValues() {
    MockRowMetadata metadata = MockRowMetadata.builder().columnMetadata(MockColumnMetadata.builder().name("name").javaType(String.class).build()).build();
    MockResult result = MockResult.builder().row(MockRow.builder().identified(0, Object.class, "Walter").metadata(metadata).build(), MockRow.builder().identified(0, Object.class, "White").metadata(metadata).build()).build();
    mockStatementFor("SELECT * FROM person", result);
    DatabaseClient databaseClient = databaseClientBuilder.build();
    databaseClient.sql("SELECT * FROM person").map(row -> row.get(0)).all().as(StepVerifier::create).expectNext("Walter").expectNext("White").verifyComplete();
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) IncorrectResultSizeDataAccessException(org.springframework.dao.IncorrectResultSizeDataAccessException) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) StepVerifier(reactor.test.StepVerifier) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BDDMockito.inOrder(org.mockito.BDDMockito.inOrder) BDDMockito.times(org.mockito.BDDMockito.times) BDDMockito.when(org.mockito.BDDMockito.when) CoreSubscriber(reactor.core.CoreSubscriber) BDDMockito.verify(org.mockito.BDDMockito.verify) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BindMarkersFactory(org.springframework.r2dbc.core.binding.BindMarkersFactory) Result(io.r2dbc.spi.Result) Nullable(org.springframework.lang.Nullable) BDDMockito.doReturn(org.mockito.BDDMockito.doReturn) BDDMockito.verifyNoInteractions(org.mockito.BDDMockito.verifyNoInteractions) MockRow(io.r2dbc.spi.test.MockRow) BindTarget(org.springframework.r2dbc.core.binding.BindTarget) MockResult(io.r2dbc.spi.test.MockResult) MockRowMetadata(io.r2dbc.spi.test.MockRowMetadata) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) InOrder(org.mockito.InOrder) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) BDDMockito.verifyNoMoreInteractions(org.mockito.BDDMockito.verifyNoMoreInteractions) Connection(io.r2dbc.spi.Connection) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) Subscription(org.reactivestreams.Subscription) MockColumnMetadata(io.r2dbc.spi.test.MockColumnMetadata) BDDMockito.mock(org.mockito.BDDMockito.mock) Statement(io.r2dbc.spi.Statement) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockResult(io.r2dbc.spi.test.MockResult) MockRowMetadata(io.r2dbc.spi.test.MockRowMetadata) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 28 with StepVerifier

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

the class DefaultDatabaseClientUnitTests method shouldApplyStatementFilterFunctions.

@Test
void shouldApplyStatementFilterFunctions() {
    MockResult result = MockResult.builder().build();
    Statement statement = mockStatement(result);
    DatabaseClient databaseClient = databaseClientBuilder.build();
    databaseClient.sql("SELECT").filter((s, next) -> next.execute(s.returnGeneratedValues("foo"))).filter((s, next) -> next.execute(s.returnGeneratedValues("bar"))).fetch().all().as(StepVerifier::create).verifyComplete();
    InOrder inOrder = inOrder(statement);
    inOrder.verify(statement).returnGeneratedValues("foo");
    inOrder.verify(statement).returnGeneratedValues("bar");
    inOrder.verify(statement).execute();
    inOrder.verifyNoMoreInteractions();
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) IncorrectResultSizeDataAccessException(org.springframework.dao.IncorrectResultSizeDataAccessException) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) StepVerifier(reactor.test.StepVerifier) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BDDMockito.inOrder(org.mockito.BDDMockito.inOrder) BDDMockito.times(org.mockito.BDDMockito.times) BDDMockito.when(org.mockito.BDDMockito.when) CoreSubscriber(reactor.core.CoreSubscriber) BDDMockito.verify(org.mockito.BDDMockito.verify) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BindMarkersFactory(org.springframework.r2dbc.core.binding.BindMarkersFactory) Result(io.r2dbc.spi.Result) Nullable(org.springframework.lang.Nullable) BDDMockito.doReturn(org.mockito.BDDMockito.doReturn) BDDMockito.verifyNoInteractions(org.mockito.BDDMockito.verifyNoInteractions) MockRow(io.r2dbc.spi.test.MockRow) BindTarget(org.springframework.r2dbc.core.binding.BindTarget) MockResult(io.r2dbc.spi.test.MockResult) MockRowMetadata(io.r2dbc.spi.test.MockRowMetadata) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) InOrder(org.mockito.InOrder) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) BDDMockito.verifyNoMoreInteractions(org.mockito.BDDMockito.verifyNoMoreInteractions) Connection(io.r2dbc.spi.Connection) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) Subscription(org.reactivestreams.Subscription) MockColumnMetadata(io.r2dbc.spi.test.MockColumnMetadata) BDDMockito.mock(org.mockito.BDDMockito.mock) Statement(io.r2dbc.spi.Statement) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockResult(io.r2dbc.spi.test.MockResult) InOrder(org.mockito.InOrder) Statement(io.r2dbc.spi.Statement) Test(org.junit.jupiter.api.Test)

Example 29 with StepVerifier

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

the class DefaultDatabaseClientUnitTests method shouldApplySimpleStatementFilterFunctions.

@Test
void shouldApplySimpleStatementFilterFunctions() {
    MockResult result = mockSingleColumnEmptyResult();
    Statement statement = mockStatement(result);
    DatabaseClient databaseClient = databaseClientBuilder.build();
    databaseClient.sql("SELECT").filter(s -> s.returnGeneratedValues("foo")).filter(s -> s.returnGeneratedValues("bar")).fetch().all().as(StepVerifier::create).verifyComplete();
    InOrder inOrder = inOrder(statement);
    inOrder.verify(statement).returnGeneratedValues("foo");
    inOrder.verify(statement).returnGeneratedValues("bar");
    inOrder.verify(statement).execute();
    inOrder.verifyNoMoreInteractions();
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) IncorrectResultSizeDataAccessException(org.springframework.dao.IncorrectResultSizeDataAccessException) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) StepVerifier(reactor.test.StepVerifier) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BDDMockito.inOrder(org.mockito.BDDMockito.inOrder) BDDMockito.times(org.mockito.BDDMockito.times) BDDMockito.when(org.mockito.BDDMockito.when) CoreSubscriber(reactor.core.CoreSubscriber) BDDMockito.verify(org.mockito.BDDMockito.verify) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BindMarkersFactory(org.springframework.r2dbc.core.binding.BindMarkersFactory) Result(io.r2dbc.spi.Result) Nullable(org.springframework.lang.Nullable) BDDMockito.doReturn(org.mockito.BDDMockito.doReturn) BDDMockito.verifyNoInteractions(org.mockito.BDDMockito.verifyNoInteractions) MockRow(io.r2dbc.spi.test.MockRow) BindTarget(org.springframework.r2dbc.core.binding.BindTarget) MockResult(io.r2dbc.spi.test.MockResult) MockRowMetadata(io.r2dbc.spi.test.MockRowMetadata) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) InOrder(org.mockito.InOrder) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) BDDMockito.verifyNoMoreInteractions(org.mockito.BDDMockito.verifyNoMoreInteractions) Connection(io.r2dbc.spi.Connection) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) Subscription(org.reactivestreams.Subscription) MockColumnMetadata(io.r2dbc.spi.test.MockColumnMetadata) BDDMockito.mock(org.mockito.BDDMockito.mock) Statement(io.r2dbc.spi.Statement) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockResult(io.r2dbc.spi.test.MockResult) InOrder(org.mockito.InOrder) Statement(io.r2dbc.spi.Statement) Test(org.junit.jupiter.api.Test)

Example 30 with StepVerifier

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

the class DefaultDatabaseClientUnitTests method shouldApplyPreparedOperation.

@Test
void shouldApplyPreparedOperation() {
    MockResult result = mockSingleColumnResult(MockRow.builder().identified(0, Object.class, "Walter"));
    Statement statement = mockStatementFor("SELECT * FROM person", result);
    DatabaseClient databaseClient = databaseClientBuilder.build();
    databaseClient.sql(new PreparedOperation<String>() {

        @Override
        public String toQuery() {
            return "SELECT * FROM person";
        }

        @Override
        public String getSource() {
            return "SELECT";
        }

        @Override
        public void bindTo(BindTarget target) {
            target.bind("index", "value");
        }
    }).fetch().all().as(StepVerifier::create).expectNextCount(1).verifyComplete();
    verify(statement).bind("index", "value");
}
Also used : MockResult(io.r2dbc.spi.test.MockResult) Statement(io.r2dbc.spi.Statement) BindTarget(org.springframework.r2dbc.core.binding.BindTarget) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Aggregations

StepVerifier (reactor.test.StepVerifier)234 Test (org.junit.jupiter.api.Test)176 Mono (reactor.core.publisher.Mono)111 Flux (reactor.core.publisher.Flux)92 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)77 Duration (java.time.Duration)76 BeforeEach (org.junit.jupiter.api.BeforeEach)60 Test (org.junit.Test)55 Query (org.springframework.data.mongodb.core.query.Query)54 Assertions (org.assertj.core.api.Assertions)53 Document (org.bson.Document)49 Arrays (java.util.Arrays)46 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)44 Criteria (org.springframework.data.mongodb.core.query.Criteria)44 TimeUnit (java.util.concurrent.TimeUnit)42 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)42 Disposable (reactor.core.Disposable)39 List (java.util.List)38 ClassPathResource (org.springframework.core.io.ClassPathResource)38 AtomicReference (java.util.concurrent.atomic.AtomicReference)37