mirror of
https://github.com/valitydev/cashreg-adapter-starrys.git
synced 2024-11-06 00:15:21 +00:00
PROX-458: change client, errors handling (#6)
This commit is contained in:
parent
647f30deb7
commit
76757068c6
@ -1 +1 @@
|
||||
Subproject commit e89b885839df8013df804d48ff24dff10c9c451e
|
||||
Subproject commit f42e059d9ec93826ba4ad23232eed8ce67bd5486
|
9
pom.xml
9
pom.xml
@ -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 <a.cherkasov@rbkmoney.com></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>
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
@ -19,8 +19,13 @@ public class ErrorProcessor implements Processor<ExitStateModel, EntryStateModel
|
||||
@Override
|
||||
public ExitStateModel process(ResponseEntity<FullResponse> response, EntryStateModel entryStateModel) {
|
||||
ExitStateModel exitStateModel = new ExitStateModel();
|
||||
if (ErrorUtils.hasError(response)) {
|
||||
exitStateModel.setEntryStateModel(entryStateModel);
|
||||
if (entryStateModel.getState().getAdapterContext() != null) {
|
||||
exitStateModel.setAdapterContext(entryStateModel.getState().getAdapterContext());
|
||||
}
|
||||
if (ErrorUtils.hasError(response)) {
|
||||
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());
|
||||
|
@ -15,6 +15,4 @@ public interface AdapterCashReg {
|
||||
|
||||
ResponseEntity<FullResponse> refundCredit(RequestWrapper<ComplexRequest> request);
|
||||
|
||||
ResponseEntity<FullResponse> status(RequestWrapper<ComplexRequest> request);
|
||||
|
||||
}
|
||||
|
@ -38,9 +38,4 @@ public class StarRysClient implements AdapterCashReg {
|
||||
return api.complex(requestWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<FullResponse> status(RequestWrapper<ComplexRequest> request) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
7
src/main/resources/fixture/errors.json
Normal file
7
src/main/resources/fixture/errors.json
Normal file
@ -0,0 +1,7 @@
|
||||
[
|
||||
{
|
||||
"codeRegex": "1",
|
||||
"descriptionRegex": "test",
|
||||
"mapping": "authorization_failed:operation_blocked"
|
||||
}
|
||||
]
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user