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.FileManager;
import ${basePackage}.module.system.req.FileCreateRequest;
import ${basePackage}.module.system.req.FileDeleteRequest;
import ${basePackage}.module.system.req.FileFindRequest;
import ${basePackage}.module.system.req.FileGetRequest;
import ${basePackage}.module.system.rsp.FileCreateResponse;
import ${basePackage}.module.system.rsp.FileDeleteResponse;
import ${basePackage}.module.system.rsp.FileFindResponse;
import ${basePackage}.module.system.rsp.FileGetResponse;

import static org.junit.Assert.assertTrue;

/**
 * FileTest -  - 字典测试用例
 *
 * @author wangbing
 * @version 0.0.1
 * @since 2017-01-01
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
public class FileTest {

    @Autowired
    private Token token;

    @Autowired
    private FileManager fileManager;

    @Test
    public void testCreate() {
        FileCreateRequest request = new FileCreateRequest();
        request.setName("字文件名称");
        request.setFileType(null);
        request.setUrl("http://example.com/a.zip");
        request.setUrlDownload("http://example.com/a.zip");
        request.setAttribute1("Attribute1");
        request.setAttribute2("Attribute2");
        request.setAttribute2("Attribute3");

        FileCreateResponse response = fileManager.create(request, token);

        assertTrue(!response.hasError());
    }

    @Test
    public void testDelete() {

        //创建数据
        FileCreateRequest createRequest = new FileCreateRequest();
        createRequest.setName("字文件名称");
        createRequest.setFileType(null);
        createRequest.setUrl("http://example.com/a.zip");
        createRequest.setUrlDownload("http://example.com/a.zip");
        createRequest.setAttribute1("Attribute1");
        createRequest.setAttribute2("Attribute2");
        createRequest.setAttribute2("Attribute3");

        FileCreateResponse createResponse = fileManager.create(createRequest, token);

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

        FileDeleteResponse response = fileManager.delete(request, token);

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

    @Test
    public void testFind() {
        FileFindRequest request = new FileFindRequest();
        request.setName("字文件名称");
        request.setFileType(null);
        request.setAttribute1("Attribute1");
        request.setAttribute2("Attribute2");
        request.setAttribute2("Attribute3");

        FileFindResponse response = fileManager.find(request, token);

        assertTrue(!response.hasError());
    }

    @Test
    public void testGet() {
        //创建数据
        FileCreateRequest createRequest = new FileCreateRequest();
        createRequest.setName("字文件名称");
        createRequest.setFileType(null);
        createRequest.setUrl("http://example.com/a.zip");
        createRequest.setUrlDownload("http://example.com/a.zip");
        createRequest.setAttribute1("Attribute1");
        createRequest.setAttribute2("Attribute2");
        createRequest.setAttribute2("Attribute3");

        FileCreateResponse createResponse = fileManager.create(createRequest, token);

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

        FileGetResponse response = fileManager.get(request, token);

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