lenboo
4 years ago
191 changed files with 3325 additions and 1329 deletions
@ -1,69 +0,0 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.apache.dolphinscheduler.alert.utils; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONArray; |
||||
import org.apache.dolphinscheduler.common.utils.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* json utils |
||||
*/ |
||||
public class JSONUtils { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(JSONUtils.class); |
||||
|
||||
/** |
||||
* object to json string |
||||
* @param object the object to be converted to json |
||||
* @return json string |
||||
*/ |
||||
public static String toJsonString(Object object) { |
||||
try{ |
||||
return JSON.toJSONString(object,false); |
||||
} catch (Exception e) { |
||||
throw new RuntimeException("Json deserialization exception.", e); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* json to list |
||||
* |
||||
* @param json the json |
||||
* @param clazz c |
||||
* @param <T> the generic clazz |
||||
* @return the result list or empty list |
||||
*/ |
||||
public static <T> List<T> toList(String json, Class<T> clazz) { |
||||
if (StringUtils.isEmpty(json)) { |
||||
return Collections.emptyList(); |
||||
} |
||||
try { |
||||
return JSON.parseArray(json, clazz); |
||||
} catch (Exception e) { |
||||
logger.error("JSONArray.parseArray exception!",e); |
||||
} |
||||
|
||||
return Collections.emptyList(); |
||||
} |
||||
|
||||
} |
@ -1,114 +0,0 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.apache.dolphinscheduler.alert.utils; |
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode; |
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.List; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
public class JSONUtilsTest { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(JSONUtilsTest.class); |
||||
|
||||
public List<LinkedHashMap<String, Object>> list = new ArrayList<>(); |
||||
|
||||
public String expected = null; |
||||
|
||||
@Before |
||||
public void setUp() throws Exception { |
||||
|
||||
//Define expected json string
|
||||
expected = "[{\"mysql service name\":\"mysql200\",\"mysql address\":\"192.168.xx.xx\",\"port\":\"3306\",\"no index of number\":\"80\",\"database client connections\":\"190\"}]"; |
||||
|
||||
//Initial map
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<>(); |
||||
map.put("mysql service name","mysql200"); |
||||
map.put("mysql address","192.168.xx.xx"); |
||||
map.put("port","3306"); |
||||
map.put("no index of number","80"); |
||||
map.put("database client connections","190"); |
||||
|
||||
//Add map into list
|
||||
list.add(map); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Test toJsonString |
||||
*/ |
||||
@Test |
||||
public void testToJsonString() { |
||||
|
||||
//Invoke toJsonString
|
||||
String result = JSONUtils.toJsonString(list); |
||||
logger.info(result); |
||||
|
||||
//Equal result with expected string
|
||||
assertEquals(result,expected); |
||||
|
||||
//If param is null, then return null string
|
||||
result = JSONUtils.toJsonString(null); |
||||
logger.info(result); |
||||
|
||||
assertEquals("null", result); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Test toList |
||||
*/ |
||||
@Test |
||||
public void testToList() { |
||||
|
||||
//Invoke toList
|
||||
List<LinkedHashMap> result = JSONUtils.toList(expected ,LinkedHashMap.class); |
||||
//Equal list size=1
|
||||
assertEquals(1,result.size()); |
||||
|
||||
//Transform entity to LinkedHashMap<String, Object>
|
||||
LinkedHashMap<String, Object> entity = result.get(0); |
||||
|
||||
//Equal expected values
|
||||
assertEquals("mysql200",entity.get("mysql service name")); |
||||
assertEquals("192.168.xx.xx", entity.get("mysql address")); |
||||
assertEquals("3306", entity.get("port")); |
||||
assertEquals("80", entity.get("no index of number")); |
||||
assertEquals("190", entity.get("database client connections")); |
||||
|
||||
//If param is null, then return empty list
|
||||
result = JSONUtils.toList(null ,LinkedHashMap.class); |
||||
assertNotNull(result); |
||||
assertTrue(result.isEmpty()); |
||||
|
||||
//If param is incorrect, then return empty list and log error message
|
||||
result = JSONUtils.toList("}{" ,LinkedHashMap.class); |
||||
assertNotNull(result); |
||||
assertTrue(result.isEmpty()); |
||||
|
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,41 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.apache.dolphinscheduler.common.enums; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue; |
||||
|
||||
public enum SqoopJobType { |
||||
CUSTOM(0, "CUSTOM"), |
||||
TEMPLATE(1, "TEMPLATE"); |
||||
|
||||
SqoopJobType(int code, String descp){ |
||||
this.code = code; |
||||
this.descp = descp; |
||||
} |
||||
|
||||
@EnumValue |
||||
private final int code; |
||||
private final String descp; |
||||
|
||||
public int getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public String getDescp() { |
||||
return descp; |
||||
} |
||||
} |
@ -0,0 +1,84 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.apache.dolphinscheduler.common.task; |
||||
|
||||
import org.apache.dolphinscheduler.common.enums.HttpCheckCondition; |
||||
import org.apache.dolphinscheduler.common.enums.HttpMethod; |
||||
import org.apache.dolphinscheduler.common.task.http.HttpParameters; |
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
/** |
||||
* http parameter |
||||
*/ |
||||
public class HttpParametersTest { |
||||
|
||||
|
||||
@Test |
||||
public void testGenerator(){ |
||||
String paramData = "{\"localParams\":[],\"httpParams\":[],\"url\":\"https://www.baidu.com/\"," + |
||||
"\"httpMethod\":\"GET\",\"httpCheckCondition\":\"STATUS_CODE_DEFAULT\",\"condition\":\"\",\"connectTimeout\":\"10000\",\"socketTimeout\":\"10000\"}"; |
||||
HttpParameters httpParameters = JSONUtils.parseObject(paramData, HttpParameters.class); |
||||
|
||||
|
||||
Assert.assertEquals(10000,httpParameters.getConnectTimeout() ); |
||||
Assert.assertEquals(10000,httpParameters.getSocketTimeout()); |
||||
Assert.assertEquals("https://www.baidu.com/",httpParameters.getUrl()); |
||||
Assert.assertEquals(HttpMethod.GET,httpParameters.getHttpMethod()); |
||||
Assert.assertEquals(HttpCheckCondition.STATUS_CODE_DEFAULT,httpParameters.getHttpCheckCondition()); |
||||
Assert.assertEquals("",httpParameters.getCondition()); |
||||
|
||||
} |
||||
|
||||
|
||||
@Test |
||||
public void testCheckParameters(){ |
||||
String paramData = "{\"localParams\":[],\"httpParams\":[],\"url\":\"https://www.baidu.com/\"," + |
||||
"\"httpMethod\":\"GET\",\"httpCheckCondition\":\"STATUS_CODE_DEFAULT\",\"condition\":\"\",\"connectTimeout\":\"10000\",\"socketTimeout\":\"10000\"}"; |
||||
HttpParameters httpParameters = JSONUtils.parseObject(paramData, HttpParameters.class); |
||||
|
||||
Assert.assertTrue( httpParameters.checkParameters()); |
||||
Assert.assertEquals(10000,httpParameters.getConnectTimeout() ); |
||||
Assert.assertEquals(10000,httpParameters.getSocketTimeout()); |
||||
Assert.assertEquals("https://www.baidu.com/",httpParameters.getUrl()); |
||||
Assert.assertEquals(HttpMethod.GET,httpParameters.getHttpMethod()); |
||||
Assert.assertEquals(HttpCheckCondition.STATUS_CODE_DEFAULT,httpParameters.getHttpCheckCondition()); |
||||
Assert.assertEquals("",httpParameters.getCondition()); |
||||
|
||||
} |
||||
|
||||
|
||||
@Test |
||||
public void testCheckValues() { |
||||
String paramData = "{\"localParams\":[],\"httpParams\":[],\"url\":\"https://www.baidu.com/\"," + |
||||
"\"httpMethod\":\"GET\",\"httpCheckCondition\":\"STATUS_CODE_DEFAULT\",\"condition\":\"\",\"connectTimeout\":\"10000\",\"socketTimeout\":\"10000\"}"; |
||||
HttpParameters httpParameters = JSONUtils.parseObject(paramData, HttpParameters.class); |
||||
|
||||
Assert.assertTrue( httpParameters.checkParameters()); |
||||
Assert.assertEquals(10000,httpParameters.getConnectTimeout() ); |
||||
Assert.assertEquals(10000,httpParameters.getSocketTimeout()); |
||||
Assert.assertEquals("https://www.baidu.com/",httpParameters.getUrl()); |
||||
Assert.assertEquals(HttpMethod.GET,httpParameters.getHttpMethod()); |
||||
Assert.assertEquals(HttpCheckCondition.STATUS_CODE_DEFAULT,httpParameters.getHttpCheckCondition()); |
||||
Assert.assertEquals("",httpParameters.getCondition()); |
||||
Assert.assertEquals(0,httpParameters.getLocalParametersMap().size()); |
||||
Assert.assertEquals(0,httpParameters.getResourceFilesList().size()); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,74 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.apache.dolphinscheduler.dao.datasource; |
||||
|
||||
import org.apache.dolphinscheduler.common.enums.DbConnectType; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
public class OracleDataSourceTest { |
||||
|
||||
@Test |
||||
public void testGetOracleJdbcUrl() { |
||||
OracleDataSource oracleDataSource = new OracleDataSource(); |
||||
oracleDataSource.setType(DbConnectType.ORACLE_SERVICE_NAME); |
||||
oracleDataSource.setAddress("jdbc:oracle:thin:@//127.0.0.1:1521"); |
||||
oracleDataSource.setDatabase("test"); |
||||
oracleDataSource.setPassword("123456"); |
||||
oracleDataSource.setUser("test"); |
||||
Assert.assertEquals("jdbc:oracle:thin:@//127.0.0.1:1521/test", oracleDataSource.getJdbcUrl()); |
||||
//set fake principal
|
||||
oracleDataSource.setPrincipal("fake principal"); |
||||
Assert.assertEquals("jdbc:oracle:thin:@//127.0.0.1:1521/test", oracleDataSource.getJdbcUrl()); |
||||
//set fake other
|
||||
oracleDataSource.setOther("charset=UTF-8"); |
||||
Assert.assertEquals("jdbc:oracle:thin:@//127.0.0.1:1521/test?charset=UTF-8", oracleDataSource.getJdbcUrl()); |
||||
|
||||
OracleDataSource oracleDataSource2 = new OracleDataSource(); |
||||
oracleDataSource2.setAddress("jdbc:oracle:thin:@127.0.0.1:1521"); |
||||
oracleDataSource2.setDatabase("orcl"); |
||||
oracleDataSource2.setPassword("123456"); |
||||
oracleDataSource2.setUser("test"); |
||||
oracleDataSource2.setType(DbConnectType.ORACLE_SID); |
||||
Assert.assertEquals("jdbc:oracle:thin:@127.0.0.1:1521:orcl", oracleDataSource2.getJdbcUrl()); |
||||
//set fake principal
|
||||
oracleDataSource2.setPrincipal("fake principal"); |
||||
Assert.assertEquals("jdbc:oracle:thin:@127.0.0.1:1521:orcl", oracleDataSource2.getJdbcUrl()); |
||||
//set fake other
|
||||
oracleDataSource2.setOther("charset=UTF-8"); |
||||
Assert.assertEquals("jdbc:oracle:thin:@127.0.0.1:1521:orcl?charset=UTF-8", oracleDataSource2.getJdbcUrl()); |
||||
} |
||||
|
||||
@Test |
||||
public void testAppendDatabase() { |
||||
OracleDataSource oracleDataSource = new OracleDataSource(); |
||||
oracleDataSource.setAddress("jdbc:oracle:thin:@//127.0.0.1:1521"); |
||||
oracleDataSource.setDatabase("test"); |
||||
oracleDataSource.setType(DbConnectType.ORACLE_SERVICE_NAME); |
||||
StringBuilder jdbcUrl = new StringBuilder(oracleDataSource.getAddress()); |
||||
oracleDataSource.appendDatabase(jdbcUrl); |
||||
Assert.assertEquals("jdbc:oracle:thin:@//127.0.0.1:1521/test", jdbcUrl.toString()); |
||||
|
||||
OracleDataSource oracleDataSource2 = new OracleDataSource(); |
||||
oracleDataSource2.setAddress("jdbc:oracle:thin:@127.0.0.1:1521"); |
||||
oracleDataSource2.setDatabase("orcl"); |
||||
oracleDataSource2.setType(DbConnectType.ORACLE_SID); |
||||
StringBuilder jdbcUrl2 = new StringBuilder(oracleDataSource2.getAddress()); |
||||
oracleDataSource2.appendDatabase(jdbcUrl2); |
||||
Assert.assertEquals("jdbc:oracle:thin:@127.0.0.1:1521:orcl", jdbcUrl2.toString()); |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.apache.dolphinscheduler.dao.entity; |
||||
|
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
public class ProcessDefinitionTest { |
||||
|
||||
/** |
||||
* task instance sub process |
||||
*/ |
||||
@Test |
||||
public void getGlobalParamMapTest() { |
||||
ProcessDefinition taskInstance = new ProcessDefinition(); |
||||
|
||||
//sub process
|
||||
taskInstance.setGlobalParams("[{\"prop\":\"selenium_global_parameters_1\",\"direct\":\"IN\",\"type\":\"VARCHAR\",\"value\":\"selenium_global_parameters_value_1\"}]"); |
||||
|
||||
taskInstance.getGlobalParamMap(); |
||||
Assert.assertEquals("{selenium_global_parameters_1=selenium_global_parameters_value_1}",taskInstance.getGlobalParamMap().toString()); |
||||
|
||||
|
||||
|
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue