CustomerControllerTest.java 4.23 KB
Newer Older
eddie.woo's avatar
eddie.woo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
package pwc.taxtech.atms.controller;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.customer.CustomerDto;
import pwc.taxtech.atms.dto.customer.CustomerValidateInfoDto;
import pwc.taxtech.atms.service.CustomerService;

@RunWith(MockitoJUnitRunner.class)
public class CustomerControllerTest {
    @Mock
    private CustomerService customerService;
    @Mock
    private CommonsMultipartFile commonsMultipartFile;
    @InjectMocks
    private CustomerController customerController;

    @Test
    public void addRangeNotNullResult() {
        List<CustomerDto> customerDtoList = new ArrayList<>();
        CustomerDto customerDto = new CustomerDto();
        customerDto.setID(CommonUtils.getUUID());
        customerDto.setName("customer-name");
        customerDto.setCode("customer-code");
        customerDto.setEnterPriseAccountID(CommonUtils.getUUID());
        customerDtoList.add(customerDto);
        List<OperationResultDto<CustomerDto>> operationResultDtoList = new ArrayList<>();
        when(customerService.addRange(customerDtoList)).thenReturn(operationResultDtoList);
        assertThat(customerController.addRange(customerDtoList)).isNotNull();
    }

    @Test
    public void getByIDNotNullResult() {
        String setId = CommonUtils.getUUID();
        when(customerService.getByEnterpriseAccountSetID(setId)).thenReturn(new CustomerValidateInfoDto());
        assertThat(customerController.getByID(setId)).isNotNull();
    }

    @Test
    public void getNotNullResult() {
        List<CustomerDto> customerDtoList = new ArrayList<>();
        when(customerService.getCustomer()).thenReturn(customerDtoList);
        assertThat(customerController.getCustomer()).isNotNull();
    }

    @Test
    public void deleteRangeNotNullResult() {
        List<CustomerDto> customerDtoList = new ArrayList<>();
        CustomerDto customerDto = new CustomerDto();
        customerDto.setID(CommonUtils.getUUID());
        customerDto.setName("customer-name");
        customerDto.setCode("customer-code");
        customerDto.setEnterPriseAccountID(CommonUtils.getUUID());
        customerDtoList.add(customerDto);
        OperationResultDto<String> operationResultDto = new OperationResultDto<>();
        when(customerService.deleteRange(customerDtoList)).thenReturn(operationResultDto);
        assertThat(customerController.deleteRange(customerDtoList)).isNotNull();
    }

    @Test
    public void updateRangeNotNullResult() {
        List<CustomerDto> customerDtoList = new ArrayList<>();
        CustomerDto customerDto = new CustomerDto();
        customerDto.setID(CommonUtils.getUUID());
        customerDto.setName("customer-name");
        customerDto.setCode("customer-code");
        customerDto.setEnterPriseAccountID(CommonUtils.getUUID());
        customerDtoList.add(customerDto);
        List<OperationResultDto<CustomerDto>> operationResultDtoList = new ArrayList<>();
        when(customerService.updateRange(customerDtoList)).thenReturn(operationResultDtoList);
        assertThat(customerController.updateRange(customerDtoList)).isNotNull();
    }

    @SuppressWarnings("rawtypes")
    @Test
    public void uploadNullFile() {
        CommonsMultipartFile inputFile = null;
        String enterpriseAccountID = "enterpriseAccountID1";
        String action = "1";
        Object obj = customerController.upload(inputFile, enterpriseAccountID, action);
        OperationResultDto result = (OperationResultDto) obj;
        Assert.assertEquals(Boolean.FALSE, result.getResult());
    }

    @Test
    public void uploadFile() {
        String enterpriseAccountID = "enterpriseAccountID1";
        String action = "1";
        when(commonsMultipartFile.getSize()).thenReturn(1L);
        Object obj = customerController.upload(commonsMultipartFile, enterpriseAccountID, action);
        Assert.assertNull(obj);

    }

}