package ${domain}.wsys;

import ${domain}.frame.auth.Token;
import ${domain}.module.wsys.mgr.TaskSqlManager;
import ${domain}.module.wsys.req.TaskSqlCreateRequest;
import ${domain}.module.wsys.req.TaskSqlDeleteRequest;
import ${domain}.module.wsys.req.TaskSqlFindRequest;
import ${domain}.module.wsys.req.TaskSqlUpdateRequest;
import ${domain}.module.wsys.rsp.TaskSqlCreateResponse;
import ${domain}.module.wsys.rsp.TaskSqlDeleteResponse;
import ${domain}.module.wsys.rsp.TaskSqlFindResponse;
import ${domain}.module.wsys.rsp.TaskSqlUpdateResponse;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;

import static junit.framework.TestCase.assertTrue;

/**
 * TaskSqlTest -  - SQL任务测试用例
 *
 * @author author
 * @version 0.0.1
 * @since 2020-05-24
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
public class TaskSqlTest {

    @Autowired
    private Token token;

    @Autowired
    private TaskSqlManager taskSqlManager;

    @Test
    public void testCreate() {
        TaskSqlCreateRequest request = new TaskSqlCreateRequest();
        request.setTaskName("任务名称");
        request.setTaskNote("详细注释");
        request.setTaskType("code");
        request.setTypeValue("任务类型值");
        request.setTaskSql("任务SQL");
        request.setValid(true);

        TaskSqlCreateResponse response = taskSqlManager.create(request,token);

        assertTrue(!response.hasError());
    }

    @Test
    public void testDelete() {

        //创建数据
        TaskSqlCreateRequest createRequest = new TaskSqlCreateRequest();
        createRequest.setTaskName("任务名称");
        createRequest.setTaskNote("详细注释");
        createRequest.setTaskType("code");
        createRequest.setTypeValue("任务类型值");
        createRequest.setTaskSql("任务SQL");
        createRequest.setValid(true);

        TaskSqlCreateResponse createResponse = taskSqlManager.create(createRequest,token);

        assertTrue(!createResponse.hasError() && createResponse.getId() > 0);
        //删除数据
        TaskSqlDeleteRequest request = new TaskSqlDeleteRequest();
        request.setId(createResponse.getId());

        TaskSqlDeleteResponse response = taskSqlManager.delete(request,token);

        assertTrue(!response.hasError() && response.getResult() == 1L);
    }

    @Test
    public void testUpdate() {
        //创建数据
        TaskSqlCreateRequest createRequest = new TaskSqlCreateRequest();
        createRequest.setTaskName("任务名称");
        createRequest.setTaskNote("详细注释");
        createRequest.setTaskType("code");
        createRequest.setTypeValue("任务类型值");
        createRequest.setTaskSql("任务SQL");
        createRequest.setValid(true);

        TaskSqlCreateResponse createResponse = taskSqlManager.create(createRequest, token);

        assertTrue(!createResponse.hasError());

        //更新数据
        TaskSqlUpdateRequest request = new TaskSqlUpdateRequest();
        request.setId(createResponse.getId());
        request.setTaskName("任务名称");
        request.setTaskNote("详细注释");
        request.setTaskType("code");
        request.setTypeValue("任务类型值");
        request.setTaskSql("任务SQL");
        request.setValid(true);

        TaskSqlUpdateResponse response = taskSqlManager.update(request,token);

        assertTrue(!response.hasError() && response.getResult() == 1L);
    }

    @Test
    public void testFind() {
        TaskSqlFindRequest request = new TaskSqlFindRequest();
        request.setTaskName("任务名称");
        request.setTaskNote("详细注释");
        request.setTaskType("code");
        request.setValid(true);

        TaskSqlFindResponse response = taskSqlManager.find(request,token);

        assertTrue(!response.hasError());
    }
}
