package ${domain}.wsys;

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.wsys.mgr.LogErrManager;
import ${domain}.module.wsys.req.LogErrCreateRequest;
import ${domain}.module.wsys.req.LogErrDeleteRequest;
import ${domain}.module.wsys.req.LogErrFindRequest;
import ${domain}.module.wsys.req.LogErrUpdateRequest;
import ${domain}.module.wsys.rsp.LogErrCreateResponse;
import ${domain}.module.wsys.rsp.LogErrDeleteResponse;
import ${domain}.module.wsys.rsp.LogErrFindResponse;
import ${domain}.module.wsys.rsp.LogErrUpdateResponse;

import static junit.framework.TestCase.assertTrue;

/**
 * LogErrTest -  - 错误日志测试用例
 *
 * @author wangbing
 * @version 0.0.1
 * @since 2020-06-07
 */
@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.setLogErrType("code");
        request.setLogTitle("日志标题");
        request.setLogNote("content");
        request.setLogErrResult("code");
        request.setLogAttr1("属性1");
        request.setLogAttr2("属性2");
        request.setLogAttr3("属性3");

        LogErrCreateResponse response = logErrManager.create(request,token);

        assertTrue(!response.hasError());
    }

    @Test
    public void testDelete() {

        //创建数据
        LogErrCreateRequest createRequest = new LogErrCreateRequest();
        createRequest.setLogErrType("code");
        createRequest.setLogTitle("日志标题");
        createRequest.setLogNote("content");
        createRequest.setLogErrResult("code");
        createRequest.setLogAttr1("属性1");
        createRequest.setLogAttr2("属性2");
        createRequest.setLogAttr3("属性3");

        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.setLogErrType("code");
        createRequest.setLogTitle("日志标题");
        createRequest.setLogNote("content");
        createRequest.setLogErrResult("code");
        createRequest.setLogAttr1("属性1");
        createRequest.setLogAttr2("属性2");
        createRequest.setLogAttr3("属性3");

        LogErrCreateResponse createResponse = logErrManager.create(createRequest, token);

        assertTrue(!createResponse.hasError());

        //更新数据
        LogErrUpdateRequest request = new LogErrUpdateRequest();
        request.setId(createResponse.getId());
        request.setLogErrResult("code");

        LogErrUpdateResponse response = logErrManager.update(request,token);

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

    @Test
    public void testFind() {
        LogErrFindRequest request = new LogErrFindRequest();
        request.setLogErrType("code");
        request.setLogTitle("日志标题");
        request.setLogErrResult("code");

        LogErrFindResponse response = logErrManager.find(request,token);

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