package xyz.wbsite;


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.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import xyz.wbsite.frame.base.Token;
import xyz.wbsite.module.admin.mgr.LocationsManager;
import xyz.wbsite.module.admin.mgr.ServicesManager;
import xyz.wbsite.module.admin.req.LocationsCreateRequest;
import xyz.wbsite.module.admin.req.ServicesCreateRequest;
import xyz.wbsite.module.admin.rsp.LocationsCreateResponse;
import xyz.wbsite.module.admin.rsp.ServicesCreateResponse;

import javax.validation.constraints.AssertTrue;

import static junit.framework.TestCase.assertTrue;

@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
public class DataInit {
    @Autowired
    private Token token;
    @Autowired
    private ServicesManager servicesManager;
    @Autowired
    private LocationsManager locationsManager;

    @Test
    @Rollback(false)
    public void init() {
        {
            ServicesCreateRequest servicesCreateRequest = new ServicesCreateRequest();
            servicesCreateRequest.setTitle("默认主机");
            servicesCreateRequest.setDomain("location");
            servicesCreateRequest.setPort(80);
            servicesCreateRequest.setType("反向代理");
            servicesCreateRequest.setValid(true);
            servicesCreateRequest.setFilter(false);
            servicesCreateRequest.setFilterConf("");
            ServicesCreateResponse servicesCreateResponse = servicesManager.create(servicesCreateRequest, token);
            assertTrue(!servicesCreateResponse.hasError());
            {
                LocationsCreateRequest locationsCreateRequest = new LocationsCreateRequest();
                locationsCreateRequest.setServicesId(servicesCreateResponse.getId());
                locationsCreateRequest.setLocalTitle("默认路径");
                locationsCreateRequest.setLocalPath("/");
                locationsCreateRequest.setLocalValid(true);
                locationsCreateRequest.setFilter(false);
                locationsCreateRequest.setFilterConf("");
                LocationsCreateResponse locationsCreateResponse = locationsManager.create(locationsCreateRequest, token);
                assertTrue(!locationsCreateResponse.hasError());
            }
        }


        String[] strings1 = {"worker_processes","auto", "处理进程数","(auto)|([0-9]*)"};
        String[] strings2 = {"worker_connections","51200", "最大并发链接数","[0-9]*"};
        String[] strings3 = {"keepalive_timeout","60", "连接超时时间","[0-9]*"};
        String[] strings4 = {"gzip","60", "是否开启压缩传输","on|off"};
        String[] strings5 = {"gzip_min_length","1", "KB，最小压缩文件","[0-9]*"};
        String[] strings6 = {"gzip_comp_level","2", "压缩率","[0-9]*"};
        String[] strings7 = {"client_max_body_size","100", "MB，最大上传文件","[0-9]*"};
        String[] strings8 = {"server_names_hash_bucket_size","512", "服务器名字的hash表大小","[0-9]*"};
        String[] strings9 = {"client_body_buffer_size","51200", "KB，请求主体缓冲区","[0-9]*"};
        String[] strings10 = {"underscores_in_headers","on", "开启下划线头部信息","on|off"};
    }
}
