Search in sources :

Example 1 with ApiException

use of io.nem.symbol.sdk.openapi.vertx.invoker.ApiException in project nem2-sdk-java by nemtech.

the class AbstractVertxRespositoryTest method mockErrorCodeRawResponse.

/**
 * Mocks the api client telling that the next time there is remote call, an error should be
 * returned.
 *
 * @param statusCode the status code of the response (404 for example)
 * @param errorResponse the raw response, it may or may not be a json string.
 */
protected void mockErrorCodeRawResponse(int statusCode, String errorResponse) {
    String reasonPhrase = HttpStatus.valueOf(statusCode).getReasonPhrase();
    VertxHttpHeaders headers = new VertxHttpHeaders();
    ApiException exception = new ApiException(reasonPhrase, statusCode, headers, errorResponse);
    Mockito.doAnswer((Answer<Void>) invocationOnMock -> {
        Handler<AsyncResult<Object>> resultHandler = (Handler<AsyncResult<Object>>) invocationOnMock.getArguments()[invocationOnMock.getArguments().length - 1];
        resultHandler.handle(Future.failedFuture(exception));
        return null;
    }).when(apiClientMock).invokeAPI(Mockito.anyString(), Mockito.anyString(), Mockito.anyList(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
}
Also used : NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) BeforeEach(org.junit.jupiter.api.BeforeEach) ApiClient(io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) HashMap(java.util.HashMap) Future(io.vertx.core.Future) HttpStatus(io.nem.symbol.core.utils.HttpStatus) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) VertxHttpHeaders(io.vertx.core.http.impl.headers.VertxHttpHeaders) JsonHelper(io.nem.symbol.sdk.model.transaction.JsonHelper) Map(java.util.Map) Pair(io.nem.symbol.sdk.openapi.vertx.invoker.Pair) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) AsyncResult(io.vertx.core.AsyncResult) Address(io.nem.symbol.sdk.model.account.Address) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) ApiException(io.nem.symbol.sdk.openapi.vertx.invoker.ApiException) Handler(io.vertx.core.Handler) Handler(io.vertx.core.Handler) AsyncResult(io.vertx.core.AsyncResult) VertxHttpHeaders(io.vertx.core.http.impl.headers.VertxHttpHeaders) ApiException(io.nem.symbol.sdk.openapi.vertx.invoker.ApiException)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HttpStatus (io.nem.symbol.core.utils.HttpStatus)1 Address (io.nem.symbol.sdk.model.account.Address)1 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)1 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)1 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)1 JsonHelper (io.nem.symbol.sdk.model.transaction.JsonHelper)1 ApiClient (io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient)1 ApiException (io.nem.symbol.sdk.openapi.vertx.invoker.ApiException)1 Pair (io.nem.symbol.sdk.openapi.vertx.invoker.Pair)1 Observable (io.reactivex.Observable)1 AsyncResult (io.vertx.core.AsyncResult)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 VertxHttpHeaders (io.vertx.core.http.impl.headers.VertxHttpHeaders)1 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1