package ${domain}.wsvr;

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.wsvr.mgr.ProfilesManager;
import ${domain}.module.wsvr.req.ProfilesCreateRequest;
import ${domain}.module.wsvr.req.ProfilesDeleteRequest;
import ${domain}.module.wsvr.req.ProfilesFindRequest;
import ${domain}.module.wsvr.req.ProfilesUpdateRequest;
import ${domain}.module.wsvr.rsp.ProfilesCreateResponse;
import ${domain}.module.wsvr.rsp.ProfilesDeleteResponse;
import ${domain}.module.wsvr.rsp.ProfilesFindResponse;
import ${domain}.module.wsvr.rsp.ProfilesUpdateResponse;

import static junit.framework.TestCase.assertTrue;

/**
 * ProfilesTest -  - 系统配置测试用例
 *
 * @author wangbing
 * @version 0.0.1
 * @since 2020-07-06
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
public class ProfilesTest {

    @Autowired
    private Token token;

    @Autowired
    private ProfilesManager profilesManager;

    @Test
    public void testCreate() {
        ProfilesCreateRequest request = new ProfilesCreateRequest();
        request.setActive("value");
        request.setKey("配置键");
        request.setValue("配置值");

        ProfilesCreateResponse response = profilesManager.create(request,token);

        assertTrue(!response.hasError());
    }

    @Test
    public void testDelete() {

        //创建数据
        ProfilesCreateRequest createRequest = new ProfilesCreateRequest();
        createRequest.setActive("value");
        createRequest.setKey("配置键");
        createRequest.setValue("配置值");

        ProfilesCreateResponse createResponse = profilesManager.create(createRequest,token);

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

        ProfilesDeleteResponse response = profilesManager.delete(request,token);

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

    @Test
    public void testUpdate() {
        //创建数据
        ProfilesCreateRequest createRequest = new ProfilesCreateRequest();
        createRequest.setActive("value");
        createRequest.setKey("配置键");
        createRequest.setValue("配置值");

        ProfilesCreateResponse createResponse = profilesManager.create(createRequest, token);

        assertTrue(!createResponse.hasError());

        //更新数据
        ProfilesUpdateRequest request = new ProfilesUpdateRequest();
        request.setId(createResponse.getId());
        request.setActive("value");
        request.setKey("配置键");
        request.setValue("配置值");

        ProfilesUpdateResponse response = profilesManager.update(request,token);

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

    @Test
    public void testFind() {
        ProfilesFindRequest request = new ProfilesFindRequest();
        request.setActive("value");
        request.setKey("配置键");

        ProfilesFindResponse response = profilesManager.find(request,token);

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