Selaa lähdekoodia

update escheduler-api unit test

lidongdai 5 vuotta sitten
vanhempi
commit
7a7e5ea4f2

+ 2 - 0
escheduler-api/src/test/java/cn/escheduler/api/HttpClientTest.java

@@ -26,6 +26,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.message.BasicNameValuePair;
 import org.apache.http.util.EntityUtils;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -34,6 +35,7 @@ import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
 
+@Ignore
 public class HttpClientTest {
 
     private static final Logger logger = LoggerFactory.getLogger(HttpClientTest.class);

+ 1 - 0
escheduler-api/src/test/java/cn/escheduler/api/controller/AbstractControllerTest.java

@@ -44,6 +44,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 
+@Ignore
 @RunWith(SpringRunner.class)
 @SpringBootTest(classes = ApiApplicationServer.class)
 public class AbstractControllerTest {

+ 4 - 3
escheduler-api/src/test/java/cn/escheduler/api/controller/ExecutorControllerTest.java

@@ -20,6 +20,7 @@ import cn.escheduler.api.enums.Status;
 import cn.escheduler.api.utils.Result;
 import cn.escheduler.common.utils.JSONUtils;
 import org.junit.Assert;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -36,6 +37,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
 /**
  * executor controller test
  */
+@Ignore
 public class ExecutorControllerTest extends AbstractControllerTest{
     private static Logger logger = LoggerFactory.getLogger(ExecutorControllerTest.class);
 
@@ -44,7 +46,7 @@ public class ExecutorControllerTest extends AbstractControllerTest{
     public void startCheckProcessDefinition() throws Exception {
 
         MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/executors/start-check","project_test1")
-                .header("sessionId", "08fae8bf-fe2d-4fc0-8129-23c37fbfac82")
+                .header(SESSION_ID, sessionId)
                 .param("processDefinitionId","226"))
                 .andExpect(status().isOk())
                 .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
@@ -59,9 +61,8 @@ public class ExecutorControllerTest extends AbstractControllerTest{
         MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
         //paramsMap.add("processDefinitionId","4");
         paramsMap.add("processInstanceId","13");
-        //paramsMap.add("processInstanceId","13");
         MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/executors/get-receiver-cc","li_sql_test")
-                .header("sessionId", "e79b3353-e227-4680-88c0-544194e64025")
+                .header(SESSION_ID, sessionId)
                 .params(paramsMap))
                 .andExpect(status().isOk())
                 .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))

+ 4 - 4
escheduler-api/src/test/java/cn/escheduler/api/controller/ProjectControllerTest.java

@@ -41,10 +41,10 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 
-@Ignore
-@RunWith(SpringRunner.class)
-@SpringBootTest
-public class ProjectControllerTest {
+/**
+ * project controller
+ */
+public class ProjectControllerTest extends AbstractControllerTest{
     private static Logger logger = LoggerFactory.getLogger(ProcessInstanceControllerTest.class);
 
     private MockMvc mockMvc;

+ 1 - 1
escheduler-api/src/test/java/cn/escheduler/api/service/ProcessInstanceServiceTest.java

@@ -45,7 +45,7 @@ public class ProcessInstanceServiceTest {
     ProcessInstanceService processInstanceService;
 
     @Test
-    public void viewVariables() throws Exception {
+    public void viewVariables() {
         try {
             Map<String, Object> map = processInstanceService.viewVariables(-1);
             Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));

+ 4 - 3
escheduler-common/src/test/java/cn/escheduler/common/utils/HttpUtilsTestInner.java

@@ -18,6 +18,7 @@ package cn.escheduler.common.utils;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -25,13 +26,13 @@ import org.slf4j.LoggerFactory;
 /**
  * HttpClient utils test
  */
-public class HttpUtilsTestInner {
+public class HttpUtilsTest {
 	
 	
-	public static final Logger logger = LoggerFactory.getLogger(HttpUtilsTestInner.class);
-
+	public static final Logger logger = LoggerFactory.getLogger(HttpUtilsTest.class);
 
 
+	@Ignore
 	@Test
 	public void getTest(){
 

+ 53 - 0
escheduler-common/src/test/resources/dao/data_source.properties

@@ -0,0 +1,53 @@
+# base spring data source configuration
+spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
+spring.datasource.driver-class-name=com.mysql.jdbc.Driver
+spring.datasource.url=jdbc:mysql://192.168.10.32:3306/escheduler?characterEncoding=UTF-8
+spring.datasource.username=root
+spring.datasource.password=root@123
+
+# connection configuration
+spring.datasource.initialSize=5
+# min connection number
+spring.datasource.minIdle=5
+# max connection number
+spring.datasource.maxActive=50
+
+# max wait time for get a connection in milliseconds. if configuring maxWait, fair locks are enabled by default and concurrency efficiency decreases.
+# If necessary, unfair locks can be used by configuring the useUnfairLock attribute to true.
+spring.datasource.maxWait=60000
+
+# milliseconds for check to close free connections
+spring.datasource.timeBetweenEvictionRunsMillis=60000
+
+# the Destroy thread detects the connection interval and closes the physical connection in milliseconds if the connection idle time is greater than or equal to minEvictableIdleTimeMillis.
+spring.datasource.timeBetweenConnectErrorMillis=60000
+
+# the longest time a connection remains idle without being evicted, in milliseconds
+spring.datasource.minEvictableIdleTimeMillis=300000
+
+#the SQL used to check whether the connection is valid requires a query statement. If validation Query is null, testOnBorrow, testOnReturn, and testWhileIdle will not work.
+spring.datasource.validationQuery=SELECT 1
+#check whether the connection is valid for timeout, in seconds
+spring.datasource.validationQueryTimeout=3
+
+# when applying for a connection, if it is detected that the connection is idle longer than time Between Eviction Runs Millis,
+# validation Query is performed to check whether the connection is valid
+spring.datasource.testWhileIdle=true
+
+#execute validation to check if the connection is valid when applying for a connection
+spring.datasource.testOnBorrow=true
+#execute validation to check if the connection is valid when the connection is returned
+spring.datasource.testOnReturn=false
+spring.datasource.defaultAutoCommit=true
+spring.datasource.keepAlive=true
+
+# open PSCache, specify count PSCache for every connection
+spring.datasource.poolPreparedStatements=true
+spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
+
+# data quality analysis is not currently in use. please ignore the following configuration
+# task record flag
+task.record.flag=false
+task.record.datasource.url=jdbc:mysql://192.168.xx.xx:3306/etl?characterEncoding=UTF-8
+task.record.datasource.username=xx
+task.record.datasource.password=xx

+ 11 - 6
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/UserMapperTest.java

@@ -20,6 +20,7 @@ import cn.escheduler.common.enums.UserType;
 import cn.escheduler.dao.datasource.ConnectionFactory;
 import cn.escheduler.dao.model.AccessToken;
 import cn.escheduler.dao.model.User;
+import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -43,6 +44,14 @@ public class UserMapperTest {
         accessTokenMapper = ConnectionFactory.getSqlSession().getMapper(AccessTokenMapper.class);
     }
 
+
+    @After
+    public void testDelete() {
+        int delete = userMapper.delete(userId);
+        Assert.assertTrue(delete >= 0);
+    }
+
+
     @Test
     public void testInsert(){
         User user = new User();
@@ -57,7 +66,7 @@ public class UserMapperTest {
         userMapper.insert(user);
         Assert.assertNotEquals(user.getId(), 0);
 
-        user.setUserName("Dr.chemistry" + new Random().nextInt(10));
+        user.setUserName("Dr.chemistry" + new Date().getTime());
         int update = userMapper.update(user);
         Assert.assertEquals(update, 1);
 
@@ -88,9 +97,5 @@ public class UserMapperTest {
     }
 
 
-    @Test
-    public void testDelete() {
-        int delete = userMapper.delete(userId);
-        Assert.assertTrue(delete >= 0);
-    }
+
 }

+ 2 - 0
escheduler-server/src/test/java/cn/escheduler/server/zk/StandaloneZKServerForTest.java

@@ -21,6 +21,7 @@ import org.apache.zookeeper.server.ServerConfig;
 import org.apache.zookeeper.server.ZooKeeperServerMain;
 import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -31,6 +32,7 @@ import java.util.Properties;
 /**
  * just for test
  */
+@Ignore
 public class StandaloneZKServerForTest {
 
     private static final Logger logger = LoggerFactory.getLogger(StandaloneZKServerForTest.class);

+ 53 - 0
escheduler-server/src/test/resources/dao/data_source.properties

@@ -0,0 +1,53 @@
+# base spring data source configuration
+spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
+spring.datasource.driver-class-name=com.mysql.jdbc.Driver
+spring.datasource.url=jdbc:mysql://192.168.10.32:3306/escheduler?characterEncoding=UTF-8
+spring.datasource.username=root
+spring.datasource.password=root@123
+
+# connection configuration
+spring.datasource.initialSize=5
+# min connection number
+spring.datasource.minIdle=5
+# max connection number
+spring.datasource.maxActive=50
+
+# max wait time for get a connection in milliseconds. if configuring maxWait, fair locks are enabled by default and concurrency efficiency decreases.
+# If necessary, unfair locks can be used by configuring the useUnfairLock attribute to true.
+spring.datasource.maxWait=60000
+
+# milliseconds for check to close free connections
+spring.datasource.timeBetweenEvictionRunsMillis=60000
+
+# the Destroy thread detects the connection interval and closes the physical connection in milliseconds if the connection idle time is greater than or equal to minEvictableIdleTimeMillis.
+spring.datasource.timeBetweenConnectErrorMillis=60000
+
+# the longest time a connection remains idle without being evicted, in milliseconds
+spring.datasource.minEvictableIdleTimeMillis=300000
+
+#the SQL used to check whether the connection is valid requires a query statement. If validation Query is null, testOnBorrow, testOnReturn, and testWhileIdle will not work.
+spring.datasource.validationQuery=SELECT 1
+#check whether the connection is valid for timeout, in seconds
+spring.datasource.validationQueryTimeout=3
+
+# when applying for a connection, if it is detected that the connection is idle longer than time Between Eviction Runs Millis,
+# validation Query is performed to check whether the connection is valid
+spring.datasource.testWhileIdle=true
+
+#execute validation to check if the connection is valid when applying for a connection
+spring.datasource.testOnBorrow=true
+#execute validation to check if the connection is valid when the connection is returned
+spring.datasource.testOnReturn=false
+spring.datasource.defaultAutoCommit=true
+spring.datasource.keepAlive=true
+
+# open PSCache, specify count PSCache for every connection
+spring.datasource.poolPreparedStatements=true
+spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
+
+# data quality analysis is not currently in use. please ignore the following configuration
+# task record flag
+task.record.flag=false
+task.record.datasource.url=jdbc:mysql://192.168.xx.xx:3306/etl?characterEncoding=UTF-8
+task.record.datasource.username=xx
+task.record.datasource.password=xx