Search in sources :

Example 1 with HMCMiraklInvoice

use of com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoice in project mirakl-hyperwallet-connector by paypal.

the class MiraklInvoicesExtractServiceImplTest method getAccountingDocument_whenRequestNeedsPagination_shouldRepeatRequestAndReturnAllInvoices.

@Test
void getAccountingDocument_whenRequestNeedsPagination_shouldRepeatRequestAndReturnAllInvoices() {
    TimeMachine.useFixedClockAt(LocalDateTime.of(2020, 11, 10, 20, 0, 55));
    final Date now = DateUtil.convertToDate(TimeMachine.now(), ZoneId.systemDefault());
    final List<HMCMiraklInvoice> firstPageResponseInvoices = getListOfHMCMiraklInvoiceMocks(MIRAKL_MAX_RESULTS_PER_PAGE);
    final List<HMCMiraklInvoice> secondPageResponseInvoices = getListOfHMCMiraklInvoiceMocks(MIRAKL_MAX_RESULTS_PER_PAGE / 2);
    final long totalResponseInvoices = firstPageResponseInvoices.size() + secondPageResponseInvoices.size();
    when(miraklMarketplacePlatformOperatorApiClientMock.getInvoices(argThat(request -> request != null && request.getOffset() == 0))).thenReturn(miraklInvoicesOneMock);
    when(miraklMarketplacePlatformOperatorApiClientMock.getInvoices(argThat(request -> request != null && request.getOffset() == MIRAKL_MAX_RESULTS_PER_PAGE))).thenReturn(miraklInvoicesTwoMock);
    when(miraklInvoicesOneMock.getTotalCount()).thenReturn(totalResponseInvoices);
    when(miraklInvoicesOneMock.getHmcInvoices()).thenReturn(firstPageResponseInvoices);
    when(miraklInvoicesTwoMock.getTotalCount()).thenReturn(totalResponseInvoices);
    when(miraklInvoicesTwoMock.getHmcInvoices()).thenReturn(secondPageResponseInvoices);
    final List<InvoiceModel> expectedCreditNotes = Stream.concat(firstPageResponseInvoices.stream(), secondPageResponseInvoices.stream()).map(invoice -> mockAndReturn(invoice)).collect(Collectors.toList());
    final List<InvoiceModel> result = testObj.getAccountingDocuments(now);
    assertThat(result).containsExactlyElementsOf(expectedCreditNotes);
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DateUtil(com.paypal.infrastructure.util.DateUtil) BeforeEach(org.junit.jupiter.api.BeforeEach) Converter(com.paypal.infrastructure.converter.Converter) MIRAKL_MAX_RESULTS_PER_PAGE(com.paypal.infrastructure.constants.HyperWalletConstants.MIRAKL_MAX_RESULTS_PER_PAGE) Mock(org.mockito.Mock) Date(java.util.Date) PENDING(com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentPaymentStatus.PENDING) MiraklGetInvoicesRequest(com.mirakl.client.mmp.operator.request.payment.invoice.MiraklGetInvoicesRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LocalDateTime(java.time.LocalDateTime) InvoiceModel(com.paypal.invoices.invoicesextract.model.InvoiceModel) Captor(org.mockito.Captor) AUTO_INVOICE(com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentType.AUTO_INVOICE) MiraklMarketplacePlatformOperatorApiWrapper(com.paypal.infrastructure.sdk.mirakl.MiraklMarketplacePlatformOperatorApiWrapper) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AccountingDocumentModel(com.paypal.invoices.invoicesextract.model.AccountingDocumentModel) MiraklApiException(com.mirakl.client.core.exception.MiraklApiException) MiraklAccountingDocumentState(com.mirakl.client.mmp.request.payment.invoice.MiraklAccountingDocumentState) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) MiraklShops(com.mirakl.client.mmp.domain.shop.MiraklShops) Set(java.util.Set) MiraklGetShopsRequest(com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest) HMCMiraklInvoice(com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoice) MiraklLoggingErrorsUtil(com.paypal.infrastructure.util.MiraklLoggingErrorsUtil) Collectors(java.util.stream.Collectors) MailNotificationUtil(com.paypal.infrastructure.mail.MailNotificationUtil) ZoneId(java.time.ZoneId) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) TimeMachine(com.paypal.infrastructure.util.TimeMachine) Stream(java.util.stream.Stream) InvoiceTypeEnum(com.paypal.invoices.invoicesextract.model.InvoiceTypeEnum) MiraklShop(com.mirakl.client.mmp.domain.shop.MiraklShop) MiraklErrorResponseBean(com.mirakl.client.core.error.MiraklErrorResponseBean) COMPLETE(com.mirakl.client.mmp.request.payment.invoice.MiraklAccountingDocumentState.COMPLETE) HMCMiraklInvoices(com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoices) MiraklAccountingDocumentPaymentStatus(com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentPaymentStatus) Collections(java.util.Collections) HMCMiraklInvoice(com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoice) Date(java.util.Date) InvoiceModel(com.paypal.invoices.invoicesextract.model.InvoiceModel) Test(org.junit.jupiter.api.Test)

Example 2 with HMCMiraklInvoice

use of com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoice in project mirakl-hyperwallet-connector by paypal.

the class MiraklCreditNotesExtractServiceImplTest method getAccountingDocuments_whenRequestNeedsPagination_shouldRepeatRequestAndReturnAllInvoices.

@Test
void getAccountingDocuments_whenRequestNeedsPagination_shouldRepeatRequestAndReturnAllInvoices() {
    TimeMachine.useFixedClockAt(LocalDateTime.of(2020, 11, 10, 20, 0, 55));
    final Date now = DateUtil.convertToDate(TimeMachine.now(), ZoneId.systemDefault());
    final List<HMCMiraklInvoice> firstPageResponseInvoices = getListOfHMCMiraklInvoiceMocks(MIRAKL_MAX_RESULTS_PER_PAGE);
    final List<HMCMiraklInvoice> secondPageResponseInvoices = getListOfHMCMiraklInvoiceMocks(MIRAKL_MAX_RESULTS_PER_PAGE / 2);
    final long totalResponseInvoices = firstPageResponseInvoices.size() + secondPageResponseInvoices.size();
    when(miraklMarketplacePlatformOperatorApiClientMock.getInvoices(argThat(request -> request != null && request.getOffset() == 0))).thenReturn(miraklInvoicesOneMock);
    when(miraklMarketplacePlatformOperatorApiClientMock.getInvoices(argThat(request -> request != null && request.getOffset() == MIRAKL_MAX_RESULTS_PER_PAGE))).thenReturn(miraklInvoicesTwoMock);
    when(miraklInvoicesOneMock.getTotalCount()).thenReturn(totalResponseInvoices);
    when(miraklInvoicesOneMock.getHmcInvoices()).thenReturn(firstPageResponseInvoices);
    when(miraklInvoicesTwoMock.getTotalCount()).thenReturn(totalResponseInvoices);
    when(miraklInvoicesTwoMock.getHmcInvoices()).thenReturn(secondPageResponseInvoices);
    final List<CreditNoteModel> expectedCreditNotes = Stream.concat(firstPageResponseInvoices.stream(), secondPageResponseInvoices.stream()).map(invoice -> mockAndReturn(invoice)).collect(Collectors.toList());
    final List<CreditNoteModel> result = testObj.getAccountingDocuments(now);
    assertThat(result).containsExactlyElementsOf(expectedCreditNotes);
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DateUtil(com.paypal.infrastructure.util.DateUtil) BeforeEach(org.junit.jupiter.api.BeforeEach) Converter(com.paypal.infrastructure.converter.Converter) MIRAKL_MAX_RESULTS_PER_PAGE(com.paypal.infrastructure.constants.HyperWalletConstants.MIRAKL_MAX_RESULTS_PER_PAGE) Mock(org.mockito.Mock) Date(java.util.Date) PENDING(com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentPaymentStatus.PENDING) MiraklGetInvoicesRequest(com.mirakl.client.mmp.operator.request.payment.invoice.MiraklGetInvoicesRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MiraklInvoice(com.mirakl.client.mmp.domain.invoice.MiraklInvoice) LocalDateTime(java.time.LocalDateTime) Captor(org.mockito.Captor) MiraklMarketplacePlatformOperatorApiWrapper(com.paypal.infrastructure.sdk.mirakl.MiraklMarketplacePlatformOperatorApiWrapper) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AccountingDocumentModel(com.paypal.invoices.invoicesextract.model.AccountingDocumentModel) MANUAL_CREDIT(com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentType.MANUAL_CREDIT) CreditNoteModel(com.paypal.invoices.invoicesextract.model.CreditNoteModel) MiraklApiException(com.mirakl.client.core.exception.MiraklApiException) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) MiraklShops(com.mirakl.client.mmp.domain.shop.MiraklShops) Set(java.util.Set) MiraklGetShopsRequest(com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest) HMCMiraklInvoice(com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoice) MiraklLoggingErrorsUtil(com.paypal.infrastructure.util.MiraklLoggingErrorsUtil) Collectors(java.util.stream.Collectors) MailNotificationUtil(com.paypal.infrastructure.mail.MailNotificationUtil) ZoneId(java.time.ZoneId) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) TimeMachine(com.paypal.infrastructure.util.TimeMachine) Stream(java.util.stream.Stream) InvoiceTypeEnum(com.paypal.invoices.invoicesextract.model.InvoiceTypeEnum) MiraklShop(com.mirakl.client.mmp.domain.shop.MiraklShop) MiraklErrorResponseBean(com.mirakl.client.core.error.MiraklErrorResponseBean) COMPLETE(com.mirakl.client.mmp.request.payment.invoice.MiraklAccountingDocumentState.COMPLETE) HMCMiraklInvoices(com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoices) Collections(java.util.Collections) HMCMiraklInvoice(com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoice) CreditNoteModel(com.paypal.invoices.invoicesextract.model.CreditNoteModel) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 3 with HMCMiraklInvoice

use of com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoice in project mirakl-hyperwallet-connector by paypal.

the class AbstractAccountingDocumentsExtractServiceImpl method getInvoicesForDateAndType.

protected List<HMCMiraklInvoice> getInvoicesForDateAndType(final Date delta, final InvoiceTypeEnum invoiceType) {
    final List<HMCMiraklInvoice> invoices = new ArrayList<>();
    int offset = 0;
    final MiraklGetInvoicesRequest accountingDocumentRequest = createAccountingDocumentRequest(delta, invoiceType);
    while (true) {
        accountingDocumentRequest.setOffset(offset);
        final HMCMiraklInvoices receivedInvoices = miraklMarketplacePlatformOperatorApiClient.getInvoices(accountingDocumentRequest);
        invoices.addAll(receivedInvoices.getHmcInvoices());
        if (receivedInvoices.getTotalCount() <= invoices.size()) {
            break;
        }
        offset += MIRAKL_MAX_RESULTS_PER_PAGE;
    }
    return invoices;
}
Also used : HMCMiraklInvoices(com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoices) HMCMiraklInvoice(com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoice) MiraklGetInvoicesRequest(com.mirakl.client.mmp.operator.request.payment.invoice.MiraklGetInvoicesRequest)

Aggregations

MiraklGetInvoicesRequest (com.mirakl.client.mmp.operator.request.payment.invoice.MiraklGetInvoicesRequest)3 HMCMiraklInvoice (com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoice)3 HMCMiraklInvoices (com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoices)3 MiraklErrorResponseBean (com.mirakl.client.core.error.MiraklErrorResponseBean)2 MiraklApiException (com.mirakl.client.core.exception.MiraklApiException)2 PENDING (com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentPaymentStatus.PENDING)2 MiraklShop (com.mirakl.client.mmp.domain.shop.MiraklShop)2 MiraklShops (com.mirakl.client.mmp.domain.shop.MiraklShops)2 COMPLETE (com.mirakl.client.mmp.request.payment.invoice.MiraklAccountingDocumentState.COMPLETE)2 MiraklGetShopsRequest (com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest)2 MIRAKL_MAX_RESULTS_PER_PAGE (com.paypal.infrastructure.constants.HyperWalletConstants.MIRAKL_MAX_RESULTS_PER_PAGE)2 Converter (com.paypal.infrastructure.converter.Converter)2 MailNotificationUtil (com.paypal.infrastructure.mail.MailNotificationUtil)2 MiraklMarketplacePlatformOperatorApiWrapper (com.paypal.infrastructure.sdk.mirakl.MiraklMarketplacePlatformOperatorApiWrapper)2 DateUtil (com.paypal.infrastructure.util.DateUtil)2 MiraklLoggingErrorsUtil (com.paypal.infrastructure.util.MiraklLoggingErrorsUtil)2 TimeMachine (com.paypal.infrastructure.util.TimeMachine)2 AccountingDocumentModel (com.paypal.invoices.invoicesextract.model.AccountingDocumentModel)2 InvoiceTypeEnum (com.paypal.invoices.invoicesextract.model.InvoiceTypeEnum)2 LocalDateTime (java.time.LocalDateTime)2