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.RoleResManager;
import ${basePackage}.module.system.req.RoleResCreateRequest;
import ${basePackage}.module.system.req.RoleResDeleteRequest;
import ${basePackage}.module.system.req.RoleResFindRequest;
import ${basePackage}.module.system.req.RoleResGetRequest;
import ${basePackage}.module.system.req.RoleResUpdateRequest;
import ${basePackage}.module.system.rsp.RoleResCreateResponse;
import ${basePackage}.module.system.rsp.RoleResDeleteResponse;
import ${basePackage}.module.system.rsp.RoleResFindResponse;
import ${basePackage}.module.system.rsp.RoleResGetResponse;
import ${basePackage}.module.system.rsp.RoleResUpdateResponse;

import static org.junit.Assert.assertTrue;

/**
 * RoleResTest -  - 角色资源关系测试用例
 *
 * @author wangbing
 * @version 0.0.1
 * @since 2020-01-05
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
public class RoleResTest {

    @Autowired
    private Token token;

    @Autowired
    private RoleResManager roleResManager;

    @Test
    public void testCreate() {
        RoleResCreateRequest request = new RoleResCreateRequest();
        request.setRoleId(1L);
        request.setRoleCode("角色代码");
        request.setResId(1L);
        request.setResCode("资源代码");

        RoleResCreateResponse response = roleResManager.create(request, token);

        assertTrue(!response.hasError());
    }

    @Test
    public void testDelete() {

        //创建数据
        RoleResCreateRequest createRequest = new RoleResCreateRequest();
        createRequest.setRoleId(1L);
        createRequest.setRoleCode("角色代码");
        createRequest.setResId(1L);
        createRequest.setResCode("资源代码");

        RoleResCreateResponse createResponse = roleResManager.create(createRequest, token);

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

        RoleResDeleteResponse response = roleResManager.delete(request, token);

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

    @Test
    public void testUpdate() {
        //创建数据
        RoleResCreateRequest createRequest = new RoleResCreateRequest();
        createRequest.setRoleId(1L);
        createRequest.setRoleCode("角色代码");
        createRequest.setResId(1L);
        createRequest.setResCode("资源代码");

        RoleResCreateResponse createResponse = roleResManager.create(createRequest, token);

        assertTrue(!createResponse.hasError());

        //更新数据
        RoleResUpdateRequest request = new RoleResUpdateRequest();
        request.setId(createResponse.getId());
        request.setRoleId(1L);
        request.setRoleCode("角色代码");
        request.setResId(1L);
        request.setResCode("资源代码");

        RoleResUpdateResponse response = roleResManager.update(request, token);

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

    @Test
    public void testFind() {
        RoleResFindRequest request = new RoleResFindRequest();
        request.setRoleId(1L);
        request.setRoleCode("角色代码");
        request.setResId(1L);
        request.setResCode("资源代码");

        RoleResFindResponse response = roleResManager.find(request, token);

        assertTrue(!response.hasError());
    }

    @Test
    public void testGet() {
        //创建数据
        RoleResCreateRequest createRequest = new RoleResCreateRequest();
        createRequest.setRoleId(1L);
        createRequest.setRoleCode("角色代码");
        createRequest.setResId(1L);
        createRequest.setResCode("资源代码");

        RoleResCreateResponse createResponse = roleResManager.create(createRequest, token);

        assertTrue(!createResponse.hasError());

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

        RoleResGetResponse response = roleResManager.get(request, token);

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