package com.usoftchina.bi.test.server.controller.dataSource;

import com.usoftchina.bi.core.base.RepEntity;
import com.usoftchina.bi.server.Application;
import com.usoftchina.bi.server.model.po.TokenData;
import com.usoftchina.bi.server.model.vo.configVo.LoginInfo;
import com.usoftchina.bi.server.service.user.UserService;
import com.usoftchina.bi.starter.test.BaseControllerTest;
import com.usoftchina.bi.test.server.controller.chart.ChartsConfigControllerTest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
public class DataBasesControllerTest extends BaseControllerTest {

    @Autowired
    private UserService userService;

    private static String token = null;
    private static final Logger logger = LoggerFactory.getLogger(ChartsConfigControllerTest.class);

    @Before
    public void init(){
        if (token == null) {
            LoginInfo loginInfo = new LoginInfo();
            loginInfo.setUserName("U0818");
            loginInfo.setPassWord("cw111111");
            RepEntity<TokenData> repEntity = userService.login(loginInfo);
            token = repEntity.getData().getToken();
            logger.info("token={}", token);
        }
    }

    /**
     * 获取数据连接列表
     * @throws Exception
     */
    @Test
    public void testA_getDatabases() throws Exception {
        mockMvc.perform(get("/DataBase/getDatabases")
                            .header("token", token)
                            .param("pageNum", "1")
                            .param("pageSize", "10"))
                    .andReturn();
    }

}