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;

@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.setValid(true);
            servicesCreateRequest.setFilter(false);
            servicesCreateRequest.setFilterConf("");
            ServicesCreateResponse servicesCreateResponse = servicesManager.create(servicesCreateRequest, token);

            {
                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);
            }
        }
    }
}
