PROX-458: change client, errors handling (#6)

This commit is contained in:
malkoas 2020-10-26 11:43:47 +03:00 committed by GitHub
parent 647f30deb7
commit 76757068c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 69 additions and 81 deletions

@ -1 +1 @@
Subproject commit e89b885839df8013df804d48ff24dff10c9c451e
Subproject commit f42e059d9ec93826ba4ad23232eed8ce67bd5486

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.rbkmoney</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<version>2.3.4.RELEASE</version>
<relativePath/>
</parent>
@ -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>
@ -102,6 +102,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.rbkmoney.geck</groupId>
<artifactId>serializer</artifactId>
<version>${geck.version}</version>
</dependency>
<!--Third party libs-->
<dependency>
<groupId>org.projectlombok</groupId>

View File

@ -1,32 +0,0 @@
package com.rbkmoney.adapter.starrys.handler.cashreg;
import com.rbkmoney.adapter.cashreg.spring.boot.starter.handler.CommonHandlerImpl;
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.EntryStateModel;
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.ExitStateModel;
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.Step;
import com.rbkmoney.adapter.cashreg.spring.boot.starter.processor.Processor;
import com.rbkmoney.adapter.starrys.service.starrys.StarRysClient;
import com.rbkmoney.adapter.starrys.service.starrys.model.request.ComplexRequest;
import com.rbkmoney.adapter.starrys.service.starrys.model.request.RequestWrapper;
import com.rbkmoney.adapter.starrys.service.starrys.model.response.FullResponse;
import org.springframework.core.convert.converter.Converter;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
@Component
public class StatusCommonHandler extends CommonHandlerImpl<ExitStateModel, RequestWrapper<ComplexRequest>, ResponseEntity<FullResponse>, EntryStateModel> {
public StatusCommonHandler(
StarRysClient client,
Converter<EntryStateModel, RequestWrapper<ComplexRequest>> converter,
Processor<ExitStateModel, EntryStateModel, ResponseEntity<FullResponse>> responseProcessorChain
) {
super(client::status, converter, responseProcessorChain);
}
@Override
public boolean isHandler(EntryStateModel entryStateModel) {
return Step.CHECK_STATUS.equals(entryStateModel.getState().getAdapterContext().getNextStep());
}
}

View File

@ -19,8 +19,13 @@ public class ErrorProcessor implements Processor<ExitStateModel, EntryStateModel
@Override
public ExitStateModel process(ResponseEntity<FullResponse> response, EntryStateModel entryStateModel) {
ExitStateModel exitStateModel = new ExitStateModel();
exitStateModel.setEntryStateModel(entryStateModel);
if (entryStateModel.getState().getAdapterContext() != null) {
exitStateModel.setAdapterContext(entryStateModel.getState().getAdapterContext());
}
if (ErrorUtils.hasError(response)) {
exitStateModel.setEntryStateModel(entryStateModel);
exitStateModel.setErrorCode(response.getBody().getResponse().getError().toString());
exitStateModel.setErrorMessage(response.getBody().getResponse().getDescription());
} else {
log.error("Unknown result code for response: {}!", response);
exitStateModel.setErrorCode(UNKNOWN.getCode());

View File

@ -48,7 +48,7 @@ public class SuccessProcessor implements Processor<ExitStateModel, EntryStateMod
public boolean isDelivered(ResponseEntity<FullResponse> entity) {
FullResponse fullResponse = entity.getBody();
return HttpStatus.SC_OK == entity.getStatusCode().value() && fullResponse != null && fullResponse.getResponse().getError() == 0;
return HttpStatus.SC_OK == entity.getStatusCode().value() && fullResponse != null && fullResponse.getResponse().getError() == 0;
}
}

View File

@ -15,6 +15,4 @@ public interface AdapterCashReg {
ResponseEntity<FullResponse> refundCredit(RequestWrapper<ComplexRequest> request);
ResponseEntity<FullResponse> status(RequestWrapper<ComplexRequest> request);
}

View File

@ -38,9 +38,4 @@ public class StarRysClient implements AdapterCashReg {
return api.complex(requestWrapper);
}
@Override
public ResponseEntity<FullResponse> status(RequestWrapper<ComplexRequest> request) {
throw new RuntimeException();
}
}

View File

@ -3,13 +3,12 @@ package com.rbkmoney.adapter.starrys.service.starrys.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Date {

View File

@ -3,13 +3,12 @@ package com.rbkmoney.adapter.starrys.service.starrys.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DateTime {

View File

@ -3,13 +3,12 @@ package com.rbkmoney.adapter.starrys.service.starrys.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Device {

View File

@ -3,13 +3,12 @@ package com.rbkmoney.adapter.starrys.service.starrys.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class FirstRequest {

View File

@ -3,15 +3,14 @@ package com.rbkmoney.adapter.starrys.service.starrys.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.List;
@Getter
@Setter
@ToString
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class FiscalDocument {

View File

@ -4,13 +4,12 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class FiscalDocumentValue {

View File

@ -3,15 +3,14 @@ package com.rbkmoney.adapter.starrys.service.starrys.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.math.BigInteger;
@Getter
@Setter
@ToString
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Lines {

View File

@ -3,13 +3,12 @@ package com.rbkmoney.adapter.starrys.service.starrys.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Time {

View File

@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.rbkmoney.adapter.starrys.service.starrys.constant.*;
import com.rbkmoney.adapter.starrys.service.starrys.model.Lines;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@ -12,9 +13,7 @@ import lombok.ToString;
import java.math.BigInteger;
import java.util.List;
@Getter
@Setter
@ToString
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ComplexRequest {

View File

@ -5,15 +5,14 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.rbkmoney.adapter.starrys.service.starrys.model.Device;
import com.rbkmoney.adapter.starrys.service.starrys.model.FirstRequest;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.List;
@Getter
@Setter
@ToString
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class FullResponse {

View File

@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.rbkmoney.adapter.starrys.service.starrys.model.DateTime;
import com.rbkmoney.adapter.starrys.service.starrys.model.FiscalDocument;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@ -12,9 +13,7 @@ import lombok.ToString;
import java.math.BigInteger;
import java.util.List;
@Getter
@Setter
@ToString
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Response {

View File

@ -3,13 +3,12 @@ package com.rbkmoney.adapter.starrys.service.starrys.model.response;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Responses {

View File

@ -0,0 +1,7 @@
[
{
"codeRegex": "1",
"descriptionRegex": "test",
"mapping": "authorization_failed:operation_blocked"
}
]

View File

@ -3,6 +3,8 @@ package com.rbkmoney.adapter.starrys.handler;
import com.rbkmoney.adapter.starrys.AbstractIntegrationTest;
import com.rbkmoney.adapter.starrys.MockUtils;
import com.rbkmoney.adapter.starrys.service.starrys.StarRysClient;
import com.rbkmoney.adapter.starrys.service.starrys.model.response.FullResponse;
import com.rbkmoney.adapter.starrys.service.starrys.model.response.Response;
import com.rbkmoney.damsel.cashreg.adapter.CashregContext;
import com.rbkmoney.damsel.cashreg.adapter.CashregResult;
import com.rbkmoney.damsel.cashreg.receipt.type.Debit;
@ -11,10 +13,15 @@ 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 org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class StarrysServerHandlerTest extends AbstractIntegrationTest {
@ -35,4 +42,19 @@ public class StarrysServerHandlerTest extends AbstractIntegrationTest {
assertTrue(result.getIntent().isSetFinish());
}
@Test
public void failureTest() throws TException {
doAnswer((Answer<ResponseEntity<FullResponse>>) invocation -> {
ResponseEntity<FullResponse> response = new ResponseEntity(new FullResponse(), HttpStatus.ACCEPTED);
response.getBody().setResponse(new Response());
response.getBody().getResponse().setError(1);
response.getBody().getResponse().setDescription("test");
return response;
}).when(client).debit(any());
CashregContext context = makeCashregContext(Type.debit(new Debit()));
CashregResult result = handler.register(context);
assertTrue(result.getIntent().getFinish().getStatus().isSetFailure());
}
}