package ${basePackage}.system;

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 ${basePackage}.frame.auth.Token;
import ${basePackage}.module.system.mgr.LogErrManager;
import ${basePackage}.module.system.req.LogErrCreateRequest;
import ${basePackage}.module.system.req.LogErrDeleteRequest;
import ${basePackage}.module.system.req.LogErrFindRequest;
import ${basePackage}.module.system.req.LogErrGetRequest;
import ${basePackage}.module.system.req.LogErrUpdateRequest;
import ${basePackage}.module.system.rsp.LogErrCreateResponse;
import ${basePackage}.module.system.rsp.LogErrDeleteResponse;
import ${basePackage}.module.system.rsp.LogErrFindResponse;
import ${basePackage}.module.system.rsp.LogErrGetResponse;
import ${basePackage}.module.system.rsp.LogErrUpdateResponse;

import static junit.framework.TestCase.assertTrue;

/**
 * LogErrTest -  - 错误日志测试用例
 *
 * @author wangbing
 * @version 0.0.1
 * @since 2020-01-29
 */
@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.setTitle("错误标题");
        request.setContent("content");
        request.setLogErrResult("code");
        request.setAttribute1("属性1");
        request.setAttribute2("属性2");
        request.setAttribute3("属性3");

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

        assertTrue(!response.hasError());
    }

    @Test
    public void testDelete() {

        //创建数据
        LogErrCreateRequest createRequest = new LogErrCreateRequest();
        createRequest.setLogErrType("code");
        createRequest.setTitle("错误标题");
        createRequest.setContent("content");
        createRequest.setLogErrResult("code");
        createRequest.setAttribute1("属性1");
        createRequest.setAttribute2("属性2");
        createRequest.setAttribute3("属性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.setTitle("错误标题");
        createRequest.setContent("content");
        createRequest.setLogErrResult("code");
        createRequest.setAttribute1("属性1");
        createRequest.setAttribute2("属性2");
        createRequest.setAttribute3("属性3");

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

        assertTrue(!createResponse.hasError());

        //更新数据
        LogErrUpdateRequest request = new LogErrUpdateRequest();
        request.setId(createResponse.getId());
        request.setLogErrType("code");
        request.setTitle("错误标题");
        request.setContent("content");
        request.setLogErrResult("code");
        request.setAttribute1("属性1");
        request.setAttribute2("属性2");
        request.setAttribute3("属性3");

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

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

    @Test
    public void testFind() {
        LogErrFindRequest request = new LogErrFindRequest();
        request.setLogErrType("code");
        request.setTitle("错误标题");
        request.setLogErrResult("code");
        request.setAttribute1("属性1");
        request.setAttribute2("属性2");
        request.setAttribute3("属性3");

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

        assertTrue(!response.hasError());
    }

    @Test
    public void testGet() {
        //创建数据
        LogErrCreateRequest createRequest = new LogErrCreateRequest();
        createRequest.setLogErrType("code");
        createRequest.setTitle("错误标题");
        createRequest.setContent("content");
        createRequest.setLogErrResult("code");
        createRequest.setAttribute1("属性1");
        createRequest.setAttribute2("属性2");
        createRequest.setAttribute3("属性3");

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

        assertTrue(!createResponse.hasError());

        //获得数据
        LogErrGetRequest request = new LogErrGetRequest();
        request.setId(createResponse.getId());

        LogErrGetResponse response = logErrManager.get(request,token);

        assertTrue(!response.hasError() && response.getLogErr() != null);
    }
}
