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.RoleResManager;
import ${domain}.module.wsys.req.RoleResCreateRequest;
import ${domain}.module.wsys.req.RoleResDeleteRequest;
import ${domain}.module.wsys.req.RoleResFindRequest;
import ${domain}.module.wsys.req.RoleResUpdateRequest;
import ${domain}.module.wsys.rsp.RoleResCreateResponse;
import ${domain}.module.wsys.rsp.RoleResDeleteResponse;
import ${domain}.module.wsys.rsp.RoleResFindResponse;
import ${domain}.module.wsys.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());
    }
}
