Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.1 kB
1
Indexable
Never
package br.com.senior.erpxcomven.pedido.handlers;

import br.com.senior.erpxcomven.pedido.*;
import br.com.senior.erpxcomven.pedido.repository.E120ipdBaseItemRepository;
import br.com.senior.erpxcomven.pedido.service.CalculateSaleOrderItemService;
import br.com.senior.erpxcomven.pedido.service.ItemStatusService;
import br.com.senior.erpxcomven.pedido.service.OrderStatusService;
import br.com.senior.erpxcomven.pedido.service.RateioInformacoesAdicionais;
import br.com.senior.erpxcomven.pedido.service.RecalculateInstallmentsService;
import br.com.senior.messaging.ErrorCategory;
import br.com.senior.messaging.model.ServiceException;
import br.com.senior.platform.translationhub.api.TranslationHubApi;
import org.apache.commons.collections4.CollectionUtils;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.Arrays;
import java.util.UUID;

import static org.mockito.Mockito.*;

public class CalculateApportionmentRequiredHandlerImplTest {
    
    @Mock
    private CalculateSaleOrderItemService calculateSaleOrderItemService;
    
    @Mock
    private E120ipdBaseItemRepository e120ipdBaseRepository;
    
    @Mock
    private ItemStatusService itemStatusService;
    
    @Mock
    private OrderStatusService orderStatusService;
    
    @Mock
    private TranslationHubApi translationHubApi;
    
    @Mock
    private RateioInformacoesAdicionais rateioInformacoesAdicionais;
    
    @Mock
    private RecalculateInstallmentsService recalculateInstallmentsService;
    
    @InjectMocks
    private CalculateApportionmentRequiredHandlerImpl calculateApportionmentRequiredHandler;
    
    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
    }
    
    @Test
    public void testCalculateApportionmentRequired() {
        CalculateApportionmentRequiredPayload payload = new CalculateApportionmentRequiredPayload();
        payload.setOrderId("12345");
        
        E120pedEntity order = new E120pedEntity();
        E120ipdEntity item1 = new E120ipdEntity();
        E120ipdEntity item2 = new E120ipdEntity();
        order.setE120ipd(Arrays.asList(item1, item2));
        
        when(e120ipdBaseRepository.findById(UUID.fromString(payload.getOrderId()))).thenReturn(java.util.Optional.of(order));
        when(rateioInformacoesAdicionais.ratearInformacoesAdicionais(order.getE120inf())).thenReturn(order);
        
        calculateApportionmentRequiredHandler.calculateApportionmentRequired(payload);
        
        verify(rateioInformacoesAdicionais, times(1)).ratearInformacoesAdicionais(order.getE120inf());
        verify(calculateSaleOrderItemService, times(2)).startCalculation(any());
        verify(recalculateInstallmentsService, times(1)).recalculateInstallments(order);
        verify(recalculateInstallmentsService, times(1)).recalculateAlternativePaymentTermsIfExists(order.getId().toString());
        verify(orderStatusService, times(1)).updateOrderCalcSituation(order.getId());
    }
    
}