package ${domain}.wsvr;

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 ${domain}.frame.auth.Token;
import ${domain}.module.wsvr.mgr.LogerrManager;
import ${domain}.module.wsvr.req.LogerrCreateRequest;
import ${domain}.module.wsvr.req.LogerrDeleteRequest;
import ${domain}.module.wsvr.req.LogerrFindRequest;
import ${domain}.module.wsvr.req.LogerrUpdateRequest;
import ${domain}.module.wsvr.rsp.LogerrCreateResponse;
import ${domain}.module.wsvr.rsp.LogerrDeleteResponse;
import ${domain}.module.wsvr.rsp.LogerrFindResponse;
import ${domain}.module.wsvr.rsp.LogerrUpdateResponse;

import static junit.framework.TestCase.assertTrue;

/**
 * LogerrTest -  - 错误日志测试用例
 *
 * @author wangbing
 * @version 0.0.1
 * @since 2020-07-06
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
public class LogerrTest {

    @Autowired
    private Token token;

    @Autowired
    private LogerrManager logerrManager;

    @Test
    public void testCreate() {
        LogerrCreateRequest request = new LogerrCreateRequest();
        request.setLogType("value");
        request.setLogTitle("任务标题");
        request.setLogNote("日志描述");
        request.setLogState("value");

        LogerrCreateResponse response = logerrManager.create(request,token);

        assertTrue(!response.hasError());
    }

    @Test
    public void testDelete() {

        //创建数据
        LogerrCreateRequest createRequest = new LogerrCreateRequest();
        createRequest.setLogType("value");
        createRequest.setLogTitle("任务标题");
        createRequest.setLogNote("日志描述");
        createRequest.setLogState("value");

        LogerrCreateResponse createResponse = logerrManager.create(createRequest,token);

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

        LogerrDeleteResponse response = logerrManager.delete(request,token);

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

    @Test
    public void testUpdate() {
        //创建数据
        LogerrCreateRequest createRequest = new LogerrCreateRequest();
        createRequest.setLogType("value");
        createRequest.setLogTitle("任务标题");
        createRequest.setLogNote("日志描述");
        createRequest.setLogState("value");

        LogerrCreateResponse createResponse = logerrManager.create(createRequest, token);

        assertTrue(!createResponse.hasError());

        //更新数据
        LogerrUpdateRequest request = new LogerrUpdateRequest();
        request.setId(createResponse.getId());
        request.setLogType("value");
        request.setLogTitle("任务标题");
        request.setLogNote("日志描述");
        request.setLogState("value");

        LogerrUpdateResponse response = logerrManager.update(request,token);

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

    @Test
    public void testFind() {
        LogerrFindRequest request = new LogerrFindRequest();
        request.setLogType("value");
        request.setLogTitle("任务标题");
        request.setLogState("value");

        LogerrFindResponse response = logerrManager.find(request,token);

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