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.RoleManager;
import ${basePackage}.module.system.req.RoleCreateRequest;
import ${basePackage}.module.system.req.RoleDeleteRequest;
import ${basePackage}.module.system.req.RoleFindRequest;
import ${basePackage}.module.system.req.RoleGetRequest;
import ${basePackage}.module.system.req.RoleUpdateRequest;
import ${basePackage}.module.system.rsp.RoleCreateResponse;
import ${basePackage}.module.system.rsp.RoleDeleteResponse;
import ${basePackage}.module.system.rsp.RoleFindResponse;
import ${basePackage}.module.system.rsp.RoleGetResponse;
import ${basePackage}.module.system.rsp.RoleUpdateResponse;

import static org.junit.Assert.assertTrue;

/**
 * RoleTest -  - 角色测试用例
 *
 * @author wangbing
 * @version 0.0.1
 * @since 2019-12-27
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
public class RoleTest {

    @Autowired
    private Token token;

    @Autowired
    private RoleManager roleManager;

    @Test
    public void testCreate() {
        RoleCreateRequest request = new RoleCreateRequest();
        request.setCode("角色代码");
        request.setName("角色名称");
        request.setComment("角色描述");

        RoleCreateResponse response = roleManager.create(request, token);

        assertTrue(!response.hasError());
    }

    @Test
    public void testDelete() {

        //创建数据
        RoleCreateRequest createRequest = new RoleCreateRequest();
        createRequest.setCode("角色代码");
        createRequest.setName("角色名称");
        createRequest.setComment("角色描述");

        RoleCreateResponse createResponse = roleManager.create(createRequest, token);

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

        RoleDeleteResponse response = roleManager.delete(request, token);

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

    @Test
    public void testUpdate() {
        //创建数据
        RoleCreateRequest createRequest = new RoleCreateRequest();
        createRequest.setCode("角色代码");
        createRequest.setName("角色名称");
        createRequest.setComment("角色描述");

        RoleCreateResponse createResponse = roleManager.create(createRequest, token);

        assertTrue(!createResponse.hasError());

        //更新数据
        RoleUpdateRequest request = new RoleUpdateRequest();
        request.setId(createResponse.getId());
        request.setCode("角色代码");
        request.setName("角色名称");
        request.setComment("角色描述");

        RoleUpdateResponse response = roleManager.update(request, token);

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

    @Test
    public void testFind() {
        RoleFindRequest request = new RoleFindRequest();
        request.setCode("角色代码");
        request.setName("角色名称");
        request.setComment("角色描述");

        RoleFindResponse response = roleManager.find(request, token);

        assertTrue(!response.hasError());
    }

    @Test
    public void testGet() {
        //创建数据
        RoleCreateRequest createRequest = new RoleCreateRequest();
        createRequest.setCode("角色代码");
        createRequest.setName("角色名称");
        createRequest.setComment("角色描述");

        RoleCreateResponse createResponse = roleManager.create(createRequest, token);

        assertTrue(!createResponse.hasError());

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

        RoleGetResponse response = roleManager.get(request, token);

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