
io.rxmicro.test.mockito.r2dbc.SQLMockFactory Maven / Gradle / Ivy
/*
* Copyright (c) 2020. https://rxmicro.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.rxmicro.test.mockito.r2dbc;
import io.r2dbc.pool.ConnectionPool;
import io.rxmicro.test.mockito.r2dbc.internal.FailedInvocationSQLMockFactory;
import io.rxmicro.test.mockito.r2dbc.internal.SuccessInvocationSQLMockFactory;
import java.util.List;
import static io.rxmicro.test.mockito.r2dbc.ErrorDuringSQLInvocationType.RETURN_RESULT_SET_FAILED;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
/**
* Helper class with useful static methods that help to configure a SQL mocks.
*
* This class must be used for testing purposes
*
* @author nedis
* @since 0.1
* @see io.rxmicro.data.sql.operation.Select
* @see io.rxmicro.data.sql.operation.Insert
* @see io.rxmicro.data.sql.operation.Update
* @see io.rxmicro.data.sql.operation.Delete
* @see io.rxmicro.data.sql.model.reactor.Transaction
* @see io.rxmicro.data.sql.model.rxjava3.Transaction
* @see io.rxmicro.data.sql.model.completablefuture.Transaction
* @see io.rxmicro.data.sql.r2dbc.postgresql.PostgreSQLRepository
*/
public final class SQLMockFactory {
private static final SuccessInvocationSQLMockFactory SUCCESS_INVOCATION_SQL_MOCK_FACTORY =
new SuccessInvocationSQLMockFactory();
private static final FailedInvocationSQLMockFactory FAILED_INVOCATION_SQL_MOCK_FACTORY =
new FailedInvocationSQLMockFactory();
/**
* Configures the specified {@link ConnectionPool} mock.
* The specified result rows will be returned
* if the RxMicro framework will execute the specified {@link SQLQueryWithParamsMock}.
*
* (This method requires that {@link ConnectionPool} will be a mock!)
*
* @param connectionPool the configuring connection pool mock
* @param sqlQueryWithParamsMock the specified SQL query with parameters mock
* @param resultRows the specified result rows that must be returned
* @throws io.rxmicro.test.local.InvalidTestConfigException if the specified parameters are invalid
*/
public static void prepareSQLOperationMocks(final ConnectionPool connectionPool,
final SQLQueryWithParamsMock sqlQueryWithParamsMock,
final List> resultRows) {
SUCCESS_INVOCATION_SQL_MOCK_FACTORY.prepare(connectionPool, sqlQueryWithParamsMock, resultRows);
}
/**
* Configures the specified {@link ConnectionPool} mock.
* The specified result rows will be returned
* if the RxMicro framework will execute the specified {@link SQLQueryWithParamsMock}.
*
* (This method requires that {@link ConnectionPool} will be a mock!)
*
* @param connectionPool the configuring connection pool mock
* @param sqlQueryWithParamsMock the specified SQL query with parameters mock
* @param resultRows the specified result rows that must be returned
* @throws io.rxmicro.test.local.InvalidTestConfigException if the specified parameters are invalid
*/
@SafeVarargs
public static void prepareSQLOperationMocks(final ConnectionPool connectionPool,
final SQLQueryWithParamsMock sqlQueryWithParamsMock,
final List