|
|
@ -17,21 +17,26 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.api.controller; |
|
|
|
package org.apache.dolphinscheduler.api.controller; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; |
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; |
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; |
|
|
|
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; |
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; |
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; |
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
import org.apache.dolphinscheduler.api.utils.Result; |
|
|
|
import org.apache.dolphinscheduler.api.utils.Result; |
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
import org.apache.dolphinscheduler.plugin.datasource.mysql.param.MySQLDataSourceParamDTO; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Ignore; |
|
|
|
import org.junit.Ignore; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
import org.junit.jupiter.api.AfterEach; |
|
|
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest; |
|
|
|
|
|
|
|
import org.junit.jupiter.params.provider.CsvSource; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.http.MediaType; |
|
|
@ -45,22 +50,33 @@ import org.springframework.util.MultiValueMap; |
|
|
|
public class DataSourceControllerTest extends AbstractControllerTest { |
|
|
|
public class DataSourceControllerTest extends AbstractControllerTest { |
|
|
|
private static final Logger logger = LoggerFactory.getLogger(DataSourceControllerTest.class); |
|
|
|
private static final Logger logger = LoggerFactory.getLogger(DataSourceControllerTest.class); |
|
|
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
@BeforeEach |
|
|
|
|
|
|
|
public void initSetUp() { |
|
|
|
|
|
|
|
setUp(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AfterEach |
|
|
|
|
|
|
|
public void afterEach() throws Exception { |
|
|
|
|
|
|
|
after(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Ignore("unknown yourself connection information") |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCreateDataSource() throws Exception { |
|
|
|
public void testCreateDataSource() throws Exception { |
|
|
|
MySQLDataSourceParamDTO mysqlDatasourceParam = new MySQLDataSourceParamDTO(); |
|
|
|
HashMap<String, Object> paramsMap = new HashMap<>(); |
|
|
|
mysqlDatasourceParam.setName("mysql"); |
|
|
|
paramsMap.put("name","mysql"); |
|
|
|
mysqlDatasourceParam.setNote("mysql data source test"); |
|
|
|
paramsMap.put("node","mysql data source test"); |
|
|
|
mysqlDatasourceParam.setHost("192.168.xxxx.xx"); |
|
|
|
paramsMap.put("type","mysql"); |
|
|
|
mysqlDatasourceParam.setPort(3306); |
|
|
|
paramsMap.put("host","127.0.0.1"); |
|
|
|
mysqlDatasourceParam.setDatabase("dolphinscheduler"); |
|
|
|
paramsMap.put("port",3306); |
|
|
|
mysqlDatasourceParam.setUserName("root"); |
|
|
|
paramsMap.put("database","mysql"); |
|
|
|
mysqlDatasourceParam.setPassword("root@123"); |
|
|
|
paramsMap.put("userName","root"); |
|
|
|
mysqlDatasourceParam.setOther(new HashMap<>()); |
|
|
|
paramsMap.put("password","123456"); |
|
|
|
MvcResult mvcResult = mockMvc.perform(post("/datasources/create") |
|
|
|
paramsMap.put("other",new HashMap<>()); |
|
|
|
|
|
|
|
MvcResult mvcResult = mockMvc.perform(post("/datasources") |
|
|
|
.header("sessionId", sessionId) |
|
|
|
.header("sessionId", sessionId) |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(JSONUtils.toJsonString(mysqlDatasourceParam))) |
|
|
|
.content(JSONUtils.toJsonString(paramsMap))) |
|
|
|
.andExpect(status().isCreated()) |
|
|
|
.andExpect(status().isCreated()) |
|
|
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
|
|
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
|
|
|
.andReturn(); |
|
|
|
.andReturn(); |
|
|
@ -69,25 +85,25 @@ public class DataSourceControllerTest extends AbstractControllerTest { |
|
|
|
logger.info(mvcResult.getResponse().getContentAsString()); |
|
|
|
logger.info(mvcResult.getResponse().getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
@Ignore("unknown yourself connection information") |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testUpdateDataSource() throws Exception { |
|
|
|
public void testUpdateDataSource() throws Exception { |
|
|
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
|
|
|
HashMap<String, Object> paramsMap = new HashMap<>(); |
|
|
|
paramsMap.add("id","2"); |
|
|
|
paramsMap.put("id",2); |
|
|
|
paramsMap.add("name","mysql"); |
|
|
|
paramsMap.put("name","mysql"); |
|
|
|
paramsMap.add("node","mysql data source test"); |
|
|
|
paramsMap.put("node","mysql data source test"); |
|
|
|
paramsMap.add("type","MYSQL"); |
|
|
|
paramsMap.put("type","mysql"); |
|
|
|
paramsMap.add("host","192.168.xxxx.xx"); |
|
|
|
paramsMap.put("host","192.168.xxxx.xx"); |
|
|
|
paramsMap.add("port","3306"); |
|
|
|
paramsMap.put("port",3306); |
|
|
|
paramsMap.add("principal",""); |
|
|
|
paramsMap.put("principal",""); |
|
|
|
paramsMap.add("database","dolphinscheduler"); |
|
|
|
paramsMap.put("database","dolphinscheduler"); |
|
|
|
paramsMap.add("userName","root"); |
|
|
|
paramsMap.put("userName","root"); |
|
|
|
paramsMap.add("password","root@123"); |
|
|
|
paramsMap.put("password","root@123"); |
|
|
|
paramsMap.add("other",""); |
|
|
|
paramsMap.put("other",new HashMap<>()); |
|
|
|
MvcResult mvcResult = mockMvc.perform(post("/datasources/update") |
|
|
|
MvcResult mvcResult = mockMvc.perform(put("/datasources/2") |
|
|
|
.header("sessionId", sessionId) |
|
|
|
.header("sessionId", sessionId) |
|
|
|
.params(paramsMap)) |
|
|
|
.content(JSONUtils.toJsonString(paramsMap))) |
|
|
|
.andExpect(status().isCreated()) |
|
|
|
.andExpect(status().isOk()) |
|
|
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
|
|
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
|
|
|
.andReturn(); |
|
|
|
.andReturn(); |
|
|
|
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); |
|
|
|
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); |
|
|
@ -95,14 +111,11 @@ public class DataSourceControllerTest extends AbstractControllerTest { |
|
|
|
logger.info(mvcResult.getResponse().getContentAsString()); |
|
|
|
logger.info(mvcResult.getResponse().getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
@Ignore("unknown you datasources id") |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testQueryDataSource() throws Exception { |
|
|
|
public void testQueryDataSource() throws Exception { |
|
|
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
|
|
|
MvcResult mvcResult = mockMvc.perform(get("/datasources/2") |
|
|
|
paramsMap.add("id","2"); |
|
|
|
.header("sessionId", sessionId)) |
|
|
|
MvcResult mvcResult = mockMvc.perform(post("/datasources/update-ui") |
|
|
|
|
|
|
|
.header("sessionId", sessionId) |
|
|
|
|
|
|
|
.params(paramsMap)) |
|
|
|
|
|
|
|
.andExpect(status().isOk()) |
|
|
|
.andExpect(status().isOk()) |
|
|
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
|
|
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
|
|
|
.andReturn(); |
|
|
|
.andReturn(); |
|
|
@ -111,10 +124,13 @@ public class DataSourceControllerTest extends AbstractControllerTest { |
|
|
|
logger.info(mvcResult.getResponse().getContentAsString()); |
|
|
|
logger.info(mvcResult.getResponse().getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ParameterizedTest |
|
|
|
public void testQueryDataSourceList() throws Exception { |
|
|
|
@CsvSource({ |
|
|
|
|
|
|
|
"type, MYSQL" |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
public void testQueryDataSourceList(String key, String dbType) throws Exception { |
|
|
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
|
|
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
|
|
|
paramsMap.add("type","MYSQL"); |
|
|
|
paramsMap.add(key,dbType); |
|
|
|
MvcResult mvcResult = mockMvc.perform(get("/datasources/list") |
|
|
|
MvcResult mvcResult = mockMvc.perform(get("/datasources/list") |
|
|
|
.header("sessionId", sessionId) |
|
|
|
.header("sessionId", sessionId) |
|
|
|
.params(paramsMap)) |
|
|
|
.params(paramsMap)) |
|
|
@ -143,21 +159,21 @@ public class DataSourceControllerTest extends AbstractControllerTest { |
|
|
|
logger.info(mvcResult.getResponse().getContentAsString()); |
|
|
|
logger.info(mvcResult.getResponse().getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
@Ignore("unknown yourself connection information") |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testConnectDataSource() throws Exception { |
|
|
|
public void testConnectDataSource() throws Exception { |
|
|
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
|
|
|
HashMap<String, Object> paramsMap = new HashMap<>(); |
|
|
|
paramsMap.add("name","hive data source"); |
|
|
|
paramsMap.put("name","mysql data source"); |
|
|
|
paramsMap.add("type","HIVE"); |
|
|
|
paramsMap.put("type","mysql"); |
|
|
|
paramsMap.add("host","192.168.xx.xx"); |
|
|
|
paramsMap.put("host","127.0.0.1"); |
|
|
|
paramsMap.add("port","10000"); |
|
|
|
paramsMap.put("port",3306); |
|
|
|
paramsMap.add("database","default"); |
|
|
|
paramsMap.put("database","mysql"); |
|
|
|
paramsMap.add("userName","hive"); |
|
|
|
paramsMap.put("userName","root"); |
|
|
|
paramsMap.add("password",""); |
|
|
|
paramsMap.put("password","123456"); |
|
|
|
paramsMap.add("other",""); |
|
|
|
paramsMap.put("other",null); |
|
|
|
MvcResult mvcResult = mockMvc.perform(post("/datasources/connect") |
|
|
|
MvcResult mvcResult = mockMvc.perform(post("/datasources/connect") |
|
|
|
.header("sessionId", sessionId) |
|
|
|
.header("sessionId", sessionId) |
|
|
|
.params(paramsMap)) |
|
|
|
.content(JSONUtils.toJsonString(paramsMap))) |
|
|
|
.andExpect(status().isOk()) |
|
|
|
.andExpect(status().isOk()) |
|
|
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
|
|
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
|
|
|
.andReturn(); |
|
|
|
.andReturn(); |
|
|
@ -166,14 +182,11 @@ public class DataSourceControllerTest extends AbstractControllerTest { |
|
|
|
logger.info(mvcResult.getResponse().getContentAsString()); |
|
|
|
logger.info(mvcResult.getResponse().getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
@Ignore("unknown your datasource id") |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testConnectionTest() throws Exception { |
|
|
|
public void testConnectionTest() throws Exception { |
|
|
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
|
|
|
MvcResult mvcResult = mockMvc.perform(get("/datasources/2/connect-test") |
|
|
|
paramsMap.add("id","2"); |
|
|
|
.header("sessionId", sessionId)) |
|
|
|
MvcResult mvcResult = mockMvc.perform(get("/datasources/connect-by-id") |
|
|
|
|
|
|
|
.header("sessionId", sessionId) |
|
|
|
|
|
|
|
.params(paramsMap)) |
|
|
|
|
|
|
|
.andExpect(status().isOk()) |
|
|
|
.andExpect(status().isOk()) |
|
|
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
|
|
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
|
|
|
.andReturn(); |
|
|
|
.andReturn(); |
|
|
@ -182,10 +195,13 @@ public class DataSourceControllerTest extends AbstractControllerTest { |
|
|
|
logger.info(mvcResult.getResponse().getContentAsString()); |
|
|
|
logger.info(mvcResult.getResponse().getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ParameterizedTest |
|
|
|
public void testVerifyDataSourceName() throws Exception { |
|
|
|
@CsvSource({ |
|
|
|
|
|
|
|
"name, sourceName" |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
public void testVerifyDataSourceName(String key, String dbType) throws Exception { |
|
|
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
|
|
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
|
|
|
paramsMap.add("name","mysql"); |
|
|
|
paramsMap.add(key,dbType); |
|
|
|
MvcResult mvcResult = mockMvc.perform(get("/datasources/verify-name") |
|
|
|
MvcResult mvcResult = mockMvc.perform(get("/datasources/verify-name") |
|
|
|
.header("sessionId", sessionId) |
|
|
|
.header("sessionId", sessionId) |
|
|
|
.params(paramsMap)) |
|
|
|
.params(paramsMap)) |
|
|
@ -239,14 +255,11 @@ public class DataSourceControllerTest extends AbstractControllerTest { |
|
|
|
logger.info(mvcResult.getResponse().getContentAsString()); |
|
|
|
logger.info(mvcResult.getResponse().getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
@Ignore("unknown your datasource id") |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testDelete() throws Exception { |
|
|
|
public void testDelete() throws Exception { |
|
|
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
|
|
|
MvcResult mvcResult = mockMvc.perform(delete("/datasources/2") |
|
|
|
paramsMap.add("id","16"); |
|
|
|
.header("sessionId", sessionId)) |
|
|
|
MvcResult mvcResult = mockMvc.perform(get("/datasources/delete") |
|
|
|
|
|
|
|
.header("sessionId", sessionId) |
|
|
|
|
|
|
|
.params(paramsMap)) |
|
|
|
|
|
|
|
.andExpect(status().isOk()) |
|
|
|
.andExpect(status().isOk()) |
|
|
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
|
|
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
|
|
|
.andReturn(); |
|
|
|
.andReturn(); |
|
|
|