PROX-458: fix failure result (#5)

This commit is contained in:
Anatoly Cherkasov 2020-10-02 17:02:46 +03:00 committed by GitHub
parent bbfe74dcd7
commit 8de9b3de49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 5 deletions

View File

@ -26,7 +26,7 @@
<exposed.ports>${server.port}</exposed.ports>
<project.maintainer>Anatoly Cherkasov &lt;a.cherkasov@rbkmoney.com&gt;</project.maintainer>
<dockerfile.Template>GENERATED DOCKER FILE</dockerfile.Template>
<dockerfile.base.service.tag>bc95d0d6dc13c693acd2b274531a7d604b877bf3</dockerfile.base.service.tag>
<dockerfile.base.service.tag>57e26d8ee999d7b0b50248c22afc63e6f926d276</dockerfile.base.service.tag>
<dockerfile.registry>dr2.rbkmoney.com</dockerfile.registry>
<shared.resources.version>0.3.8</shared.resources.version>
<logstash-logback-encoder.version>5.2</logstash-logback-encoder.version>
@ -86,6 +86,11 @@
<artifactId>woody-thrift</artifactId>
<version>${woody.version}</version>
</dependency>
<dependency>
<groupId>com.rbkmoney.geck</groupId>
<artifactId>serializer</artifactId>
<version>${geck.version}</version>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>shared-resources</artifactId>

View File

@ -47,6 +47,7 @@ public class ExitModelToProxyResultConverter implements Converter<ExitStateModel
exitStateModel.getErrorMessage()
);
intent = CashregAdapterCreators.createFinishIntentFailure(failure);
return new CashregResult().setIntent(intent).setState(serializer.writeByte(adapterState));
}
if (exitStateModel.getInfo() == null) {

View File

@ -27,8 +27,13 @@ public class ErrorProcessor implements Processor<ExitStateModel, EntryStateModel
}
ExitStateModel exitStateModel = new ExitStateModel();
exitStateModel.setAdapterContext(adapterState);
exitStateModel.setEntryStateModel(entryStateModel);
if (ErrorUtils.hasError(response)) {
exitStateModel.setEntryStateModel(entryStateModel);
com.rbkmoney.adapter.businessru.service.businessru.model.Error error = response.getError();
String errorCode = String.format("%d-%s-%s", error.getCode(), error.getErrorId(), error.getType());
exitStateModel.setErrorCode(errorCode);
exitStateModel.setErrorMessage(error.getText());
} else if (adapterState.getMaxDateTimePolling().getEpochSecond() < currentTime.getEpochSecond()) {
log.error("Sleep Timeout for response: {}!", response);
exitStateModel.setErrorCode(SLEEP_TIMEOUT.getCode());

View File

@ -35,10 +35,10 @@ public class CommonResponse {
/**
* Тип источника ошибки
* {@link Error Error}
* {@link com.rbkmoney.adapter.businessru.service.businessru.model.Error Error}
*/
@JsonProperty("error")
private Error error;
private com.rbkmoney.adapter.businessru.service.businessru.model.Error error;
/**
* {@link Status Status}

View File

@ -4,5 +4,10 @@
"descriptionRegex": "Invalid cardholder",
"mapping": "authorization_failed:operation_blocked",
"state": "payment"
},
{
"codeRegex": "1-errorId-system",
"descriptionRegex": "test",
"mapping": "authorization_failed:operation_blocked"
}
]

View File

@ -3,15 +3,21 @@ package com.rbkmoney.adapter.businessru.handler;
import com.rbkmoney.adapter.businessru.IntegrationTest;
import com.rbkmoney.adapter.businessru.MockUtils;
import com.rbkmoney.adapter.businessru.service.businessru.BusinessRuClient;
import com.rbkmoney.adapter.businessru.service.businessru.constant.ErrorType;
import com.rbkmoney.adapter.businessru.service.businessru.constant.Status;
import com.rbkmoney.adapter.businessru.service.businessru.model.response.CommonResponse;
import com.rbkmoney.damsel.cashreg.adapter.CashregContext;
import com.rbkmoney.damsel.cashreg.adapter.CashregResult;
import org.apache.thrift.TException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.mockito.stubbing.Answer;
import org.springframework.boot.test.mock.mockito.MockBean;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
public class BusinessRuServerHandlerTest extends IntegrationTest {
@ -25,7 +31,7 @@ public class BusinessRuServerHandlerTest extends IntegrationTest {
}
@Test
public void testBusinessRuServerHandler() throws TException {
public void businessRuServerHandlerTest() throws TException {
CashregContext context = makeCashRegContext();
CashregResult result = handler.register(context);
assertTrue(result.getIntent().isSetSleep());
@ -36,4 +42,24 @@ public class BusinessRuServerHandlerTest extends IntegrationTest {
assertTrue(result.getIntent().isSetFinish());
}
@Test
public void businessRuServerHandlerFailureTest() throws TException {
doAnswer((Answer<CommonResponse>) invocation -> {
CommonResponse response = new CommonResponse();
response.setStatus(Status.FAIL.getValue());
com.rbkmoney.adapter.businessru.service.businessru.model.Error error = new com.rbkmoney.adapter.businessru.service.businessru.model.Error();
error.setCode(1);
error.setText("test");
error.setErrorId("errorId");
error.setType(ErrorType.SYSTEM.getValue());
response.setError(error);
return response;
}).when(client).debit(any());
CashregContext context = makeCashRegContext();
CashregResult result = handler.register(context);
assertTrue(result.getIntent().getFinish().getStatus().isSetFailure());
}
}