From cc9a3d69a373c272694a5e0f08b243ec6c799dbf Mon Sep 17 00:00:00 2001 From: Inal Arsanukaev Date: Tue, 23 Aug 2022 14:03:13 +0300 Subject: [PATCH] Bump deps (#24) * Bump deps * refactoring * fix test Co-authored-by: Inal Arsanukaev --- pom.xml | 2 +- .../hooker/service/CustomerEventService.java | 9 ++++++--- .../hooker/service/InvoicingEventService.java | 12 ++++++------ .../vality/hooker/utils/HellgateUtils.java | 19 ------------------- .../vality/hooker/utils/PaymentToolUtils.java | 4 ++-- .../service/InvoicingEventServiceTest.java | 7 ++++--- .../dev/vality/hooker/utils/BuildUtils.java | 10 ++++++++-- .../hooker/utils/PaymentToolUtilsTest.java | 1 - 8 files changed, 27 insertions(+), 37 deletions(-) delete mode 100644 src/main/java/dev/vality/hooker/utils/HellgateUtils.java diff --git a/pom.xml b/pom.xml index ecaa7d6..7019568 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ dev.vality service-parent-pom - 1.0.11 + 1.0.18 diff --git a/src/main/java/dev/vality/hooker/service/CustomerEventService.java b/src/main/java/dev/vality/hooker/service/CustomerEventService.java index e546db1..cfc08f1 100644 --- a/src/main/java/dev/vality/hooker/service/CustomerEventService.java +++ b/src/main/java/dev/vality/hooker/service/CustomerEventService.java @@ -3,6 +3,7 @@ package dev.vality.hooker.service; import dev.vality.damsel.payment_processing.Customer; import dev.vality.damsel.payment_processing.CustomerManagementSrv; import dev.vality.damsel.payment_processing.CustomerNotFound; +import dev.vality.damsel.payment_processing.EventRange; import dev.vality.hooker.configuration.meta.UserIdentityIdExtensionKit; import dev.vality.hooker.configuration.meta.UserIdentityRealmExtensionKit; import dev.vality.hooker.converter.CustomerBindingConverter; @@ -10,7 +11,6 @@ import dev.vality.hooker.converter.CustomerConverter; import dev.vality.hooker.exception.NotFoundException; import dev.vality.hooker.exception.RemoteHostException; import dev.vality.hooker.model.CustomerMessage; -import dev.vality.hooker.utils.HellgateUtils; import dev.vality.hooker.utils.TimeUtils; import dev.vality.swag_webhook_events.model.*; import dev.vality.woody.api.flow.WFlow; @@ -32,8 +32,7 @@ public class CustomerEventService implements EventService { try { Customer customer = woodyFlow.createServiceFork(() -> { addWoodyContext(); - return customerClient.get(message.getSourceId(), - HellgateUtils.getEventRange(message.getSequenceId().intValue())); + return customerClient.get(message.getSourceId(), getEventRange(message)); } ).call(); @@ -48,6 +47,10 @@ public class CustomerEventService implements EventService { } } + private EventRange getEventRange(CustomerMessage message) { + return new EventRange().setLimit(message.getSequenceId().intValue()); + } + private void addWoodyContext() { ContextUtils.setCustomMetadataValue(UserIdentityIdExtensionKit.KEY, "hooker"); ContextUtils.setCustomMetadataValue(UserIdentityRealmExtensionKit.KEY, "service"); diff --git a/src/main/java/dev/vality/hooker/service/InvoicingEventService.java b/src/main/java/dev/vality/hooker/service/InvoicingEventService.java index 71b3731..93184dd 100644 --- a/src/main/java/dev/vality/hooker/service/InvoicingEventService.java +++ b/src/main/java/dev/vality/hooker/service/InvoicingEventService.java @@ -1,5 +1,6 @@ package dev.vality.hooker.service; +import dev.vality.damsel.payment_processing.EventRange; import dev.vality.damsel.payment_processing.InvoiceNotFound; import dev.vality.damsel.payment_processing.InvoicePayment; import dev.vality.damsel.payment_processing.InvoicingSrv; @@ -9,7 +10,6 @@ import dev.vality.hooker.converter.RefundConverter; import dev.vality.hooker.exception.NotFoundException; import dev.vality.hooker.exception.RemoteHostException; import dev.vality.hooker.model.InvoicingMessage; -import dev.vality.hooker.utils.HellgateUtils; import dev.vality.hooker.utils.TimeUtils; import dev.vality.swag_webhook_events.model.*; import lombok.RequiredArgsConstructor; @@ -42,11 +42,7 @@ public class InvoicingEventService @Override public dev.vality.damsel.payment_processing.Invoice getInvoiceByMessage(InvoicingMessage message) { try { - return invoicingClient.get( - HellgateUtils.USER_INFO, - message.getSourceId(), - HellgateUtils.getEventRange(message.getSequenceId().intValue()) - ); + return invoicingClient.get(message.getSourceId(), getEventRange(message)); } catch (InvoiceNotFound e) { throw new NotFoundException("Invoice not found, invoiceId=" + message.getSourceId()); } catch (TException e) { @@ -54,6 +50,10 @@ public class InvoicingEventService } } + private EventRange getEventRange(InvoicingMessage message) { + return new EventRange().setLimit(message.getSequenceId().intValue()); + } + private Event resolveEvent(InvoicingMessage m, dev.vality.damsel.payment_processing.Invoice invoiceInfo) { return switch (m.getEventType()) { case INVOICE_CREATED -> new InvoiceCreated() diff --git a/src/main/java/dev/vality/hooker/utils/HellgateUtils.java b/src/main/java/dev/vality/hooker/utils/HellgateUtils.java deleted file mode 100644 index 324679b..0000000 --- a/src/main/java/dev/vality/hooker/utils/HellgateUtils.java +++ /dev/null @@ -1,19 +0,0 @@ -package dev.vality.hooker.utils; - -import dev.vality.damsel.payment_processing.EventRange; -import dev.vality.damsel.payment_processing.ServiceUser; -import dev.vality.damsel.payment_processing.UserInfo; -import dev.vality.damsel.payment_processing.UserType; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class HellgateUtils { - - public static final UserInfo USER_INFO = new UserInfo("hooker", UserType.service_user(new ServiceUser())); - - public static EventRange getEventRange(Integer limit) { - return new EventRange().setLimit(limit); - } - -} diff --git a/src/main/java/dev/vality/hooker/utils/PaymentToolUtils.java b/src/main/java/dev/vality/hooker/utils/PaymentToolUtils.java index c501670..c93b912 100644 --- a/src/main/java/dev/vality/hooker/utils/PaymentToolUtils.java +++ b/src/main/java/dev/vality/hooker/utils/PaymentToolUtils.java @@ -84,7 +84,7 @@ public class PaymentToolUtils { .detailsType(PaymentToolDetails.DetailsTypeEnum.PAYMENTTOOLDETAILSMOBILECOMMERCE); } else { throw new UnsupportedOperationException( - "Unknown payment tool type. Must be bank card, terminal or digital wallet"); + "Unknown payment tool type " + paymentTool); } } @@ -123,7 +123,7 @@ public class PaymentToolUtils { rootNode.put("mobile_commerce", mobilePhone.getCc() + mobilePhone.getCtn()); } else { throw new UnsupportedOperationException( - "Unknown payment tool type. Must be bank card, terminal or digital wallet"); + "Unknown payment tool type " + paymentTool); } return Base64.getUrlEncoder().encodeToString(rootNode.toString().getBytes(StandardCharsets.UTF_8)); } diff --git a/src/test/java/dev/vality/hooker/service/InvoicingEventServiceTest.java b/src/test/java/dev/vality/hooker/service/InvoicingEventServiceTest.java index 1a97e20..08c5ab4 100644 --- a/src/test/java/dev/vality/hooker/service/InvoicingEventServiceTest.java +++ b/src/test/java/dev/vality/hooker/service/InvoicingEventServiceTest.java @@ -13,6 +13,7 @@ import dev.vality.hooker.utils.BuildUtils; import dev.vality.swag_webhook_events.model.Event; import dev.vality.swag_webhook_events.model.RefundSucceeded; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -37,13 +38,13 @@ public class InvoicingEventServiceTest { @BeforeEach public void setUp() throws Exception { - Mockito.when(invoicingClient.get(any(), any(), any())) + Mockito.when(invoicingClient.get(any(), any())) .thenReturn(BuildUtils.buildInvoice("partyId", "invoiceId", "1", "1", InvoiceStatus.paid(new InvoicePaid()), InvoicePaymentStatus.pending(new InvoicePaymentPending()))); } - @Test + @RepeatedTest(7) public void testRefundSucceeded() { InvoicingMessage message = random(InvoicingMessage.class); message.setPaymentId("1"); @@ -62,7 +63,7 @@ public class InvoicingEventServiceTest { assertEquals("chicken-teriyaki", refundSucceded.getRefund().getRrn()); } - @Test + @RepeatedTest(7) public void testJson() throws JsonProcessingException { InvoicingMessage message = random(InvoicingMessage.class); message.setPaymentId("1"); diff --git a/src/test/java/dev/vality/hooker/utils/BuildUtils.java b/src/test/java/dev/vality/hooker/utils/BuildUtils.java index 79261f4..ec9f06d 100644 --- a/src/test/java/dev/vality/hooker/utils/BuildUtils.java +++ b/src/test/java/dev/vality/hooker/utils/BuildUtils.java @@ -80,12 +80,18 @@ public class BuildUtils { dev.vality.damsel.payment_processing.Invoice invoice = new dev.vality.damsel.payment_processing.Invoice() .setInvoice(buildInvoice(partyId, invoiceId, invoiceStatus, thriftBaseProcessor)) .setPayments(buildPayments(partyId, paymentId, refundId, paymentStatus, thriftBaseProcessor)); - if (invoice.getPayments().get(0).getPayment().getPayer().isSetPaymentResource()) { + Payer payer = invoice.getPayments().get(0).getPayment().getPayer(); + if (payer.isSetPaymentResource()) { PaymentTool paymentTool = PaymentTool.bank_card( thriftBaseProcessor.process(new BankCard(), new TBaseHandler<>(BankCard.class)) ); - invoice.getPayments().get(0).getPayment().getPayer().getPaymentResource().getResource() + payer.getPaymentResource().getResource() .setPaymentTool(paymentTool); + } else if (payer.isSetCustomer()) { + PaymentTool paymentTool = PaymentTool.bank_card( + thriftBaseProcessor.process(new BankCard(), new TBaseHandler<>(BankCard.class)) + ); + payer.getCustomer().setPaymentTool(paymentTool); } return invoice; } diff --git a/src/test/java/dev/vality/hooker/utils/PaymentToolUtilsTest.java b/src/test/java/dev/vality/hooker/utils/PaymentToolUtilsTest.java index 34407df..38257c0 100644 --- a/src/test/java/dev/vality/hooker/utils/PaymentToolUtilsTest.java +++ b/src/test/java/dev/vality/hooker/utils/PaymentToolUtilsTest.java @@ -34,7 +34,6 @@ public class PaymentToolUtilsTest { public void testDigitalWalletJson() throws JsonProcessingException { PaymentTool paymentTool = PaymentTool.digital_wallet(new DigitalWallet("kke")); - paymentTool.getDigitalWallet().setProviderDeprecated(LegacyDigitalWalletProvider.qiwi); paymentTool.getDigitalWallet().setPaymentService(new PaymentServiceRef("qiwi")); PaymentToolDetails paymentToolDetails = PaymentToolUtils.getPaymentToolDetails(paymentTool); String json = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL)