Search in sources :

Example 1 with MockRowMetadata

use of io.r2dbc.spi.test.MockRowMetadata 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 2 with MockRowMetadata

use of io.r2dbc.spi.test.MockRowMetadata in project spring-framework by spring-projects.

the class DefaultDatabaseClientUnitTests method selectOneShouldFailWithException.

@Test
void selectOneShouldFailWithException() {
    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)).one().as(StepVerifier::create).verifyError(IncorrectResultSizeDataAccessException.class);
}
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 3 with MockRowMetadata

use of io.r2dbc.spi.test.MockRowMetadata in project spring-framework by spring-projects.

the class DefaultDatabaseClientUnitTests method mockSingleColumnResult.

/**
 * Mocks a {@link Result} with a single column "name" and a single row if a non null
 * row is provided.
 */
private MockResult mockSingleColumnResult(@Nullable MockRow.Builder row) {
    MockResult.Builder resultBuilder = MockResult.builder();
    if (row != null) {
        MockRowMetadata metadata = MockRowMetadata.builder().columnMetadata(MockColumnMetadata.builder().name("name").javaType(String.class).build()).build();
        resultBuilder = resultBuilder.row(row.metadata(metadata).build());
    }
    return resultBuilder.build();
}
Also used : MockResult(io.r2dbc.spi.test.MockResult) MockRowMetadata(io.r2dbc.spi.test.MockRowMetadata) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 4 with MockRowMetadata

use of io.r2dbc.spi.test.MockRowMetadata in project spring-framework by spring-projects.

the class DefaultDatabaseClientUnitTests method selectShouldEmitFirstValue.

@Test
void selectShouldEmitFirstValue() {
    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)).first().as(StepVerifier::create).expectNext("Walter").verifyComplete();
}
Also used : MockResult(io.r2dbc.spi.test.MockResult) MockRowMetadata(io.r2dbc.spi.test.MockRowMetadata) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Aggregations

MockResult (io.r2dbc.spi.test.MockResult)4 MockRowMetadata (io.r2dbc.spi.test.MockRowMetadata)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Test (org.junit.jupiter.api.Test)3 StepVerifier (reactor.test.StepVerifier)3 Connection (io.r2dbc.spi.Connection)2 ConnectionFactory (io.r2dbc.spi.ConnectionFactory)2 Result (io.r2dbc.spi.Result)2 Statement (io.r2dbc.spi.Statement)2 MockColumnMetadata (io.r2dbc.spi.test.MockColumnMetadata)2 MockRow (io.r2dbc.spi.test.MockRow)2 Arrays (java.util.Arrays)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)2 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)2 BDDMockito.doReturn (org.mockito.BDDMockito.doReturn)2 BDDMockito.inOrder (org.mockito.BDDMockito.inOrder)2 BDDMockito.mock (org.mockito.BDDMockito.mock)2 BDDMockito.times (org.mockito.BDDMockito.times)2