This is an automated email from the ASF dual-hosted git repository.
casion pushed a commit to branch dev-1.3.1
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git
The following commit(s) were added to refs/heads/dev-1.3.1 by this push:
new 921da46a4 feat: linkis-computation-governance-common unit test add
(#3820)
921da46a4 is described below
commit 921da46a446b1f5262ad13c4305da674ac58ed16
Author: ruY <[email protected]>
AuthorDate: Sun Dec 4 16:52:40 2022 +0800
feat: linkis-computation-governance-common unit test add (#3820)
* feat: linkis-computation-governance-common unit test add
* feat: add abnormal code and some special characters in code test
---
.../common/entity/ExecutionNodeStatusTest.java | 63 ++++++++++++++++
.../common/entity/NodeExistStatusTest.java | 38 ++++++++++
.../EngineConnExecutorErrorCodeTest.java | 42 +++++++++++
.../common/conf/GovernanceCommonConfTest.scala | 64 ++++++++++++++++
.../constant/job/JobRequestConstantsTest.scala | 41 +++++++++++
.../constant/job/TaskInfoConstantsTest.scala | 39 ++++++++++
.../exception/LinkisJobRetryExceptionTest.scala | 33 +++++++++
.../common/paser/EmptyCodeParserTest.scala | 35 +++++++++
.../common/paser/JsonCodeParserTest.scala | 46 ++++++++++++
.../common/paser/ScalaCodeParserTest.scala | 86 ++++++++++++++++++++++
.../common/utils/GovernanceConstantTest.scala | 46 ++++++++++++
.../utils/OnceExecutorContentUtilsTest.scala | 44 +++++++++++
12 files changed, 577 insertions(+)
diff --git
a/linkis-computation-governance/linkis-computation-governance-common/src/test/java/org/apache/linkis/governance/common/entity/ExecutionNodeStatusTest.java
b/linkis-computation-governance/linkis-computation-governance-common/src/test/java/org/apache/linkis/governance/common/entity/ExecutionNodeStatusTest.java
new file mode 100644
index 000000000..9c3b637b1
--- /dev/null
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/test/java/org/apache/linkis/governance/common/entity/ExecutionNodeStatusTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.linkis.governance.common.entity;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+public class ExecutionNodeStatusTest {
+
+ @Test
+ @DisplayName("isRunningTest")
+ public void isRunningTest() {
+
+ boolean running =
ExecutionNodeStatus.isRunning(ExecutionNodeStatus.Running);
+ Assertions.assertTrue(running);
+ }
+
+ @Test
+ @DisplayName("isScheduledTest")
+ public void isScheduledTest() {
+
+ boolean scheduledByTrue =
ExecutionNodeStatus.isScheduled(ExecutionNodeStatus.Running);
+ boolean scheduledByFalse =
ExecutionNodeStatus.isScheduled(ExecutionNodeStatus.Inited);
+
+ Assertions.assertTrue(scheduledByTrue);
+ Assertions.assertFalse(scheduledByFalse);
+ }
+
+ @Test
+ @DisplayName("isSucceedTest")
+ public void isSucceedTest() {
+
+ boolean succeed =
ExecutionNodeStatus.isSucceed(ExecutionNodeStatus.Succeed);
+ Assertions.assertTrue(succeed);
+ }
+
+ @Test
+ @DisplayName("isCompletedTest")
+ public void isCompletedTest() {
+
+ boolean completedByTrue =
ExecutionNodeStatus.isCompleted(ExecutionNodeStatus.Cancelled);
+ boolean completedByFalse =
ExecutionNodeStatus.isCompleted(ExecutionNodeStatus.Running);
+
+ Assertions.assertTrue(completedByTrue);
+ Assertions.assertFalse(completedByFalse);
+ }
+}
diff --git
a/linkis-computation-governance/linkis-computation-governance-common/src/test/java/org/apache/linkis/governance/common/entity/NodeExistStatusTest.java
b/linkis-computation-governance/linkis-computation-governance-common/src/test/java/org/apache/linkis/governance/common/entity/NodeExistStatusTest.java
new file mode 100644
index 000000000..4f660ec89
--- /dev/null
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/test/java/org/apache/linkis/governance/common/entity/NodeExistStatusTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.linkis.governance.common.entity;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+public class NodeExistStatusTest {
+
+ @Test
+ @DisplayName("enumTest")
+ public void enumTest() {
+
+ String exist = NodeExistStatus.Exist.toString();
+ String unexist = NodeExistStatus.UnExist.toString();
+ String unknown = NodeExistStatus.Unknown.toString();
+
+ Assertions.assertEquals("Exist", exist);
+ Assertions.assertEquals("UnExist", unexist);
+ Assertions.assertEquals("Unknown", unknown);
+ }
+}
diff --git
a/linkis-computation-governance/linkis-computation-governance-common/src/test/java/org/apache/linkis/governance/common/exception/engineconn/EngineConnExecutorErrorCodeTest.java
b/linkis-computation-governance/linkis-computation-governance-common/src/test/java/org/apache/linkis/governance/common/exception/engineconn/EngineConnExecutorErrorCodeTest.java
new file mode 100644
index 000000000..a9299580a
--- /dev/null
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/test/java/org/apache/linkis/governance/common/exception/engineconn/EngineConnExecutorErrorCodeTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.linkis.governance.common.exception.engineconn;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+public class EngineConnExecutorErrorCodeTest {
+
+ @Test
+ @DisplayName("constTest")
+ public void constTest() {
+
+ int initExecutorFailed = EngineConnExecutorErrorCode.INIT_EXECUTOR_FAILED;
+ int invalidEngineType = EngineConnExecutorErrorCode.INVALID_ENGINE_TYPE;
+ int invalidLock = EngineConnExecutorErrorCode.INVALID_LOCK;
+ int invalidMethod = EngineConnExecutorErrorCode.INVALID_METHOD;
+ int invalidParams = EngineConnExecutorErrorCode.INVALID_PARAMS;
+
+ Assertions.assertTrue(40106 == initExecutorFailed);
+ Assertions.assertTrue(40100 == invalidEngineType);
+ Assertions.assertTrue(40103 == invalidLock);
+ Assertions.assertTrue(40101 == invalidMethod);
+ Assertions.assertTrue(40102 == invalidParams);
+ }
+}
diff --git
a/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/conf/GovernanceCommonConfTest.scala
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/conf/GovernanceCommonConfTest.scala
new file mode 100644
index 000000000..8daebc790
--- /dev/null
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/conf/GovernanceCommonConfTest.scala
@@ -0,0 +1,64 @@
+/*
+ * 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.linkis.governance.common.conf
+
+import org.junit.jupiter.api.{Assertions, DisplayName, Test}
+
+class GovernanceCommonConfTest {
+
+ @Test
+ @DisplayName("constTest")
+ def constTest(): Unit = {
+
+ val conffilterrm = GovernanceCommonConf.CONF_FILTER_RM
+ val sparkengineversion = GovernanceCommonConf.SPARK_ENGINE_VERSION.getValue
+ val hiveengineversion = GovernanceCommonConf.HIVE_ENGINE_VERSION.getValue
+ val pythonengineversion =
GovernanceCommonConf.PYTHON_ENGINE_VERSION.getValue
+ val pythoncodeparserswitch =
GovernanceCommonConf.PYTHON_CODE_PARSER_SWITCH.getValue
+ val scalacodeparserswitch =
GovernanceCommonConf.SCALA_CODE_PARSER_SWITCH.getValue
+ val engineconnspringname =
GovernanceCommonConf.ENGINE_CONN_SPRING_NAME.getValue
+ val engineconnpluginspringname =
GovernanceCommonConf.ENGINE_CONN_PLUGIN_SPRING_NAME.getValue
+ val engineconnmanagerspringname =
GovernanceCommonConf.ENGINE_CONN_MANAGER_SPRING_NAME.getValue
+ val engineconnportrange =
GovernanceCommonConf.ENGINE_CONN_PORT_RANGE.getValue
+ val managerservicename = GovernanceCommonConf.MANAGER_SERVICE_NAME.getValue
+ val entranceservicename =
GovernanceCommonConf.ENTRANCE_SERVICE_NAME.getValue
+ val enginedefaultlimit = GovernanceCommonConf.ENGINE_DEFAULT_LIMIT.getValue
+ val skippythonparser = GovernanceCommonConf.SKIP_PYTHON_PARSER.getValue
+ val resultsetstorepath =
GovernanceCommonConf.RESULT_SET_STORE_PATH.getValue
+ val errorcodedesclen = GovernanceCommonConf.ERROR_CODE_DESC_LEN
+
+ Assertions.assertEquals("wds.linkis.rm", conffilterrm)
+ Assertions.assertEquals("2.4.3", sparkengineversion)
+ Assertions.assertEquals("1.2.1", hiveengineversion)
+ Assertions.assertEquals("python2", pythonengineversion)
+ Assertions.assertFalse(pythoncodeparserswitch)
+ Assertions.assertFalse(scalacodeparserswitch)
+ Assertions.assertEquals("linkis-cg-engineconn", engineconnspringname)
+ Assertions.assertEquals("linkis-cg-engineplugin",
engineconnpluginspringname)
+ Assertions.assertEquals("linkis-cg-engineconnmanager",
engineconnmanagerspringname)
+ Assertions.assertEquals("-", engineconnportrange)
+ Assertions.assertEquals("linkis-cg-linkismanager", managerservicename)
+ Assertions.assertEquals("linkis-cg-entrance", entranceservicename)
+ Assertions.assertTrue(5000 == enginedefaultlimit.intValue())
+ Assertions.assertTrue(skippythonparser)
+ Assertions.assertEquals("hdfs:///tmp/linkis/", resultsetstorepath)
+ Assertions.assertTrue(512 == errorcodedesclen)
+
+ }
+
+}
diff --git
a/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/constant/job/JobRequestConstantsTest.scala
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/constant/job/JobRequestConstantsTest.scala
new file mode 100644
index 000000000..f65726404
--- /dev/null
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/constant/job/JobRequestConstantsTest.scala
@@ -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.linkis.governance.common.constant.job
+
+import org.junit.jupiter.api.{Assertions, DisplayName, Test}
+
+class JobRequestConstantsTest {
+
+ @Test
+ @DisplayName("constTest")
+ def constTest(): Unit = {
+
+ val jobid = JobRequestConstants.JOB_ID
+ val jobhistorylist = JobRequestConstants.JOB_HISTORY_LIST
+ val jobrequestlist = JobRequestConstants.JOB_REQUEST_LIST
+ val jobdetaillist = JobRequestConstants.JOB_DETAIL_LIST
+ val totalpage = JobRequestConstants.TOTAL_PAGE
+
+ Assertions.assertEquals("jobId", jobid)
+ Assertions.assertEquals("jobHistoryList", jobhistorylist)
+ Assertions.assertEquals("jobRequestList", jobrequestlist)
+ Assertions.assertEquals("jobDetailList", jobdetaillist)
+ Assertions.assertEquals("totalPage", totalpage)
+ }
+
+}
diff --git
a/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/constant/job/TaskInfoConstantsTest.scala
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/constant/job/TaskInfoConstantsTest.scala
new file mode 100644
index 000000000..43eb140c7
--- /dev/null
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/constant/job/TaskInfoConstantsTest.scala
@@ -0,0 +1,39 @@
+/*
+ * 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.linkis.governance.common.constant.job
+
+import org.junit.jupiter.api.{Assertions, DisplayName, Test}
+
+class TaskInfoConstantsTest {
+
+ @Test
+ @DisplayName("constTest")
+ def constTest(): Unit = {
+
+ val execid = TaskInfoConstants.EXEC_ID
+ val idinfo = TaskInfoConstants.ID_INFO
+ val taskclassname = TaskInfoConstants.TASK_CLASSNAME
+ val taskname = TaskInfoConstants.TASK_NAME
+
+ Assertions.assertEquals("execId", execid)
+ Assertions.assertEquals("idInfo", idinfo)
+ Assertions.assertEquals("taskClassname", taskclassname)
+ Assertions.assertEquals("taskName", taskname)
+ }
+
+}
diff --git
a/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/exception/LinkisJobRetryExceptionTest.scala
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/exception/LinkisJobRetryExceptionTest.scala
new file mode 100644
index 000000000..4bfe53d03
--- /dev/null
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/exception/LinkisJobRetryExceptionTest.scala
@@ -0,0 +1,33 @@
+/*
+ * 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.linkis.governance.common.exception
+
+import org.junit.jupiter.api.{Assertions, DisplayName, Test}
+
+class LinkisJobRetryExceptionTest {
+
+ @Test
+ @DisplayName("constTest")
+ def constTest(): Unit = {
+
+ val jobretryerrorcode = LinkisJobRetryException.JOB_RETRY_ERROR_CODE
+ Assertions.assertTrue(25000 == jobretryerrorcode.intValue())
+
+ }
+
+}
diff --git
a/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/EmptyCodeParserTest.scala
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/EmptyCodeParserTest.scala
new file mode 100644
index 000000000..471e33f4c
--- /dev/null
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/EmptyCodeParserTest.scala
@@ -0,0 +1,35 @@
+/*
+ * 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.linkis.governance.common.paser
+
+import org.junit.jupiter.api.{Assertions, DisplayName, Test}
+
+class EmptyCodeParserTest {
+
+ @Test
+ @DisplayName("parseTest")
+ def parseTest(): Unit = {
+
+ val code = "show databases;"
+ val parser = new EmptyCodeParser
+ val array = parser.parse(code)
+ Assertions.assertTrue(array.size == 1)
+
+ }
+
+}
diff --git
a/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/JsonCodeParserTest.scala
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/JsonCodeParserTest.scala
new file mode 100644
index 000000000..9aae1aac8
--- /dev/null
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/JsonCodeParserTest.scala
@@ -0,0 +1,46 @@
+/*
+ * 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.linkis.governance.common.paser
+
+import org.junit.jupiter.api.{Assertions, DisplayName, Test}
+
+class JsonCodeParserTest {
+
+ @Test
+ @DisplayName("parseTest")
+ def parseTest(): Unit = {
+
+ val jsonStr = "{\"nane\":\"hadoop\",\"jobId\":\"0001\"}"
+ val parser = new JsonCodeParser
+ val array = parser.parse(jsonStr)
+
+ Assertions.assertTrue(array.size == 1)
+ }
+
+ @Test
+ @DisplayName("noJsonParseTest")
+ def noJsonParseTest(): Unit = {
+
+ val jsonStr = "{\"nane\":\"hadoop\",\"jobId\":\"0001\""
+ val parser = new JsonCodeParser
+ val array = parser.parse(jsonStr)
+
+ Assertions.assertTrue(array.length == 1)
+ }
+
+}
diff --git
a/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/ScalaCodeParserTest.scala
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/ScalaCodeParserTest.scala
new file mode 100644
index 000000000..3cfe787f6
--- /dev/null
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/ScalaCodeParserTest.scala
@@ -0,0 +1,86 @@
+/*
+ * 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.linkis.governance.common.paser
+
+import org.junit.jupiter.api.{Assertions, DisplayName, Test}
+
+class ScalaCodeParserTest {
+
+ @Test
+ @DisplayName("parseTest")
+ def parseTest(): Unit = {
+
+ val scalaCode =
+ "val codeBuffer = new ArrayBuffer[String]()\n val statementBuffer =
new ArrayBuffer[String]()"
+ val scalaCodeParser = new ScalaCodeParser
+ val array = scalaCodeParser.parse(scalaCode)
+ Assertions.assertTrue(array.size == 1)
+
+ }
+
+ @Test
+ @DisplayName("parseAbnormalCodeTest")
+ def parseAbnormalCodeTest(): Unit = {
+
+ val abnormalCode =
+ " def addInt( a:Int, b:Int )\n var sum:Int = 0\n sum = a +
b\n return sum\n }"
+ val scalaCodeParser = new ScalaCodeParser
+ val array = scalaCodeParser.parse(abnormalCode)
+ Assertions.assertTrue(array.length == 1)
+
+ }
+
+ @Test
+ @DisplayName("parseImportCodeTest")
+ def parseImportCodeTest(): Unit = {
+
+ val importCode = "import java.io._\nobject Test {\n def main(args:
Array[String]) {\n " +
+ "val writer = new PrintWriter(new File(\"test.txt\" ))\n
writer.write(\"θιΈζη¨\")\n writer.close()\n }\n}"
+
+ val scalaCodeParser = new ScalaCodeParser
+ val array = scalaCodeParser.parse(importCode)
+ Assertions.assertTrue(array.length == 2)
+
+ }
+
+ @Test
+ @DisplayName("parseSpecialCharCodeTest")
+ def parseSpecialCharCodeTest(): Unit = {
+
+ val specialCodeExp1 = "def sum(args: Int*) : Int = {\n var result = 0
;\n for(s2 <- args) {\n result += s2 ;\n }\n result ;\n}\n\n" +
+ "def main(args: Array[String]): Unit = {\n val s = sum(1 to 5:_*)
\n println(s)\n}"
+
+ val scalaCodeParser = new ScalaCodeParser
+ val arrayResult1 = scalaCodeParser.parse(specialCodeExp1)
+
+ Assertions.assertTrue(arrayResult1.length == 2)
+
+ val specialCodeExp2 =
+ " @BeanProperty\n var id: Long = _\n @BeanProperty\n var status: Int
= 0\n " +
+ "@BeanProperty\n var msg: String = _\n @BeanProperty\n var
exception: Exception = _\n " +
+ "@BeanProperty\n var data: util.Map[String, Object] = new
util.HashMap[String, Object]()\n " +
+ "override def equals(o: Any): Boolean = {\n if (this == o) return
true\n if (o == null || (getClass != o.getClass)) return false\n " +
+ "val that = o.asInstanceOf[JobRespProtocol]\n new EqualsBuilder()\n
.append(status, that.status)\n .append(msg, that.msg)\n
.append(exception, that.exception)\n " +
+ ".append(data, that.data)\n .isEquals\n }"
+
+ val arrayResult2 = scalaCodeParser.parse(specialCodeExp2)
+ Assertions.assertTrue(arrayResult2.length == 1)
+
+ }
+
+}
diff --git
a/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/utils/GovernanceConstantTest.scala
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/utils/GovernanceConstantTest.scala
new file mode 100644
index 000000000..891d43c8b
--- /dev/null
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/utils/GovernanceConstantTest.scala
@@ -0,0 +1,46 @@
+/*
+ * 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.linkis.governance.common.utils
+
+import org.junit.jupiter.api.{Assertions, DisplayName, Test}
+
+class GovernanceConstantTest {
+
+ @Test
+ @DisplayName("constTest")
+ def constTest(): Unit = {
+
+ val tasksourcemapkey = GovernanceConstant.TASK_SOURCE_MAP_KEY
+ val taskresourcesstr = GovernanceConstant.TASK_RESOURCES_STR
+ val taskresourceidstr = GovernanceConstant.TASK_RESOURCE_ID_STR
+ val taskresourceversionstr = GovernanceConstant.TASK_RESOURCE_VERSION_STR
+ val taskresourcefilenamestr =
GovernanceConstant.TASK_RESOURCE_FILE_NAME_STR
+ val requestenginestatusbatchlimit =
GovernanceConstant.REQUEST_ENGINE_STATUS_BATCH_LIMIT
+ val resultsetindex = GovernanceConstant.RESULTSET_INDEX
+
+ Assertions.assertEquals("source", tasksourcemapkey)
+ Assertions.assertEquals("resources", taskresourcesstr)
+ Assertions.assertEquals("resourceId", taskresourceidstr)
+ Assertions.assertEquals("version", taskresourceversionstr)
+ Assertions.assertEquals("fileName", taskresourcefilenamestr)
+ Assertions.assertTrue(500 == requestenginestatusbatchlimit.intValue())
+ Assertions.assertEquals("resultsetIndex", resultsetindex)
+
+ }
+
+}
diff --git
a/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/utils/OnceExecutorContentUtilsTest.scala
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/utils/OnceExecutorContentUtilsTest.scala
new file mode 100644
index 000000000..3f2604e35
--- /dev/null
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/utils/OnceExecutorContentUtilsTest.scala
@@ -0,0 +1,44 @@
+/*
+ * 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.linkis.governance.common.utils
+
+import
org.apache.linkis.governance.common.utils.OnceExecutorContentUtils.BmlResource
+
+import org.junit.jupiter.api.{Assertions, DisplayName, Test}
+
+class OnceExecutorContentUtilsTest {
+
+ @Test
+ @DisplayName("constTest")
+ def constTest(): Unit = {
+
+ val onceexecutorcontentkey =
OnceExecutorContentUtils.ONCE_EXECUTOR_CONTENT_KEY
+ Assertions.assertEquals("onceExecutorContent", onceexecutorcontentkey)
+
+ }
+
+ @Test
+ @DisplayName("resourceToValueTest")
+ def resourceToValueTest(): Unit = {
+
+ val bmlResource = BmlResource("0001", "v1")
+ val str = OnceExecutorContentUtils.resourceToValue(bmlResource)
+ Assertions.assertNotNull(str)
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]