 package test.com.leanwo.activiti.rest.base;


import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import com.leanwo.activiti.dto.BaseObjectResponse;
import com.leanwo.activiti.dto.base.TaskCountResponse;

import test.com.leanwo.BaseRestTemplateTest;
import test.com.leanwo.BaseTest;

/**
 * @author YangZhiJie
 * @date 2022/05/05
 */
public class WorkflowResourceTest1 extends BaseTest{


    @Test
    public void testCountTaskByUserIdRecordId() {
        BaseRestTemplateTest restfulResource = new BaseRestTemplateTest();
        String url = restfulResource.getProdogServerApiUrl("/workflow-prodog/workflowResource/countTaskByUserIdRecordId");
        RestTemplate restTemplate = restfulResource.getRestTemplate();
        HttpHeaders httpHeaders = restfulResource.getHttpHeaders();
        HttpEntity requestEntity = new HttpEntity(httpHeaders);
        Map<String, Object> maps = new HashMap<String, Object>();
        maps.put("userId", 1L);
        maps.put("recordId", 1L);
        ResponseEntity<BaseObjectResponse<TaskCountResponse>> responseEntity = restTemplate.exchange(
                url + "?userId={userId}&recordId={recordId}", HttpMethod.GET, requestEntity,
                new ParameterizedTypeReference<BaseObjectResponse<TaskCountResponse>>() {
                }, maps);
        BaseObjectResponse<TaskCountResponse> baseObjectResponse = responseEntity.getBody();
        
        assertTrue(baseObjectResponse.getErrorCode() == 0 && baseObjectResponse.getData() != null);
        assertTrue(baseObjectResponse.getData().getTaskCount().equals(0L));
        assertTrue(baseObjectResponse.getData().getHistoricTaskInstanceCount().equals(0L));
    }
    
    
    @Test
    public void testCountTaskByUserIdRecordId1() {
        BaseRestTemplateTest restfulResource = new BaseRestTemplateTest();
        String url = restfulResource.getProdogServerApiUrl("/workflow-prodog/workflowResource/countTaskByUserIdRecordId");
        RestTemplate restTemplate = restfulResource.getRestTemplate();
        HttpHeaders httpHeaders = restfulResource.getHttpHeaders();
        HttpEntity requestEntity = new HttpEntity(httpHeaders);
        Map<String, Object> maps = new HashMap<String, Object>();
        maps.put("userId", 5401L);
        maps.put("recordId", 55201L);
        ResponseEntity<BaseObjectResponse<TaskCountResponse>> responseEntity = restTemplate.exchange(
                url + "?userId={userId}&recordId={recordId}", HttpMethod.GET, requestEntity,
                new ParameterizedTypeReference<BaseObjectResponse<TaskCountResponse>>() {
                }, maps);
        BaseObjectResponse<TaskCountResponse> baseObjectResponse = responseEntity.getBody();
        
        assertTrue(baseObjectResponse.getErrorCode() == 0 && baseObjectResponse.getData() != null);
        assertTrue(baseObjectResponse.getData().getTaskCount().equals(1L));
        assertTrue(baseObjectResponse.getData().getHistoricTaskInstanceCount().equals(1L));
    }
    
    
}
