diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/AbstractTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/AbstractTaskTest.java index 0027698e4a..a7439aef67 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/AbstractTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/AbstractTaskTest.java @@ -16,11 +16,12 @@ */ package org.apache.dolphinscheduler.plugin.task.api; + import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class AbstractTaskTest { @@ -33,8 +34,8 @@ public class AbstractTaskTest { if (matcher.find()) { str = matcher.group(); } - Assert.assertNotNull(str); - Assert.assertEquals(jobId, str.substring(6)); + Assertions.assertNotNull(str); + Assertions.assertEquals(jobId, str.substring(6)); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/TaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/TaskTest.java deleted file mode 100644 index e388d7a7dc..0000000000 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/TaskTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.apache.dolphinscheduler.plugin.task.api;/* - * 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. - */ - -public class TaskTest { - - - -} diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/CheckTypeTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/CheckTypeTest.java index 14d6fbb18b..e95db724d9 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/CheckTypeTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/CheckTypeTest.java @@ -17,30 +17,31 @@ package org.apache.dolphinscheduler.plugin.task.api.enums.dp; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CheckTypeTest { @Test public void testGetCode() { - assertEquals(0, CheckType.COMPARISON_MINUS_STATISTICS.getCode()); - assertEquals(1, CheckType.STATISTICS_MINUS_COMPARISON.getCode()); - assertEquals(2, CheckType.STATISTICS_COMPARISON_PERCENTAGE.getCode()); - assertEquals(3, CheckType.STATISTICS_COMPARISON_DIFFERENCE_COMPARISON_PERCENTAGE.getCode()); + Assertions.assertEquals(0, CheckType.COMPARISON_MINUS_STATISTICS.getCode()); + Assertions.assertEquals(1, CheckType.STATISTICS_MINUS_COMPARISON.getCode()); + Assertions.assertEquals(2, CheckType.STATISTICS_COMPARISON_PERCENTAGE.getCode()); + Assertions.assertEquals(3, CheckType.STATISTICS_COMPARISON_DIFFERENCE_COMPARISON_PERCENTAGE.getCode()); } @Test public void testGetDescription() { - assertEquals("comparison_minus_statistics", CheckType.COMPARISON_MINUS_STATISTICS.getDescription()); - assertEquals("statistics_minus_comparison", CheckType.STATISTICS_MINUS_COMPARISON.getDescription()); - assertEquals("statistics_comparison_percentage", CheckType.STATISTICS_COMPARISON_PERCENTAGE.getDescription()); - assertEquals("statistics_comparison_difference_comparison_percentage", CheckType.STATISTICS_COMPARISON_DIFFERENCE_COMPARISON_PERCENTAGE.getDescription()); + Assertions.assertEquals("comparison_minus_statistics", CheckType.COMPARISON_MINUS_STATISTICS.getDescription()); + Assertions.assertEquals("statistics_minus_comparison", CheckType.STATISTICS_MINUS_COMPARISON.getDescription()); + Assertions.assertEquals("statistics_comparison_percentage", + CheckType.STATISTICS_COMPARISON_PERCENTAGE.getDescription()); + Assertions.assertEquals("statistics_comparison_difference_comparison_percentage", + CheckType.STATISTICS_COMPARISON_DIFFERENCE_COMPARISON_PERCENTAGE.getDescription()); } @Test public void testOf() { - assertEquals(CheckType.COMPARISON_MINUS_STATISTICS, CheckType.of(0)); + Assertions.assertEquals(CheckType.COMPARISON_MINUS_STATISTICS, CheckType.of(0)); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ConnectorTypeTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ConnectorTypeTest.java index 534c3eba3a..67b540db36 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ConnectorTypeTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ConnectorTypeTest.java @@ -17,26 +17,25 @@ package org.apache.dolphinscheduler.plugin.task.api.enums.dp; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ConnectorTypeTest { @Test public void testGetCode() { - assertEquals(0, ConnectorType.JDBC.getCode()); - assertEquals(1, ConnectorType.HIVE.getCode()); + Assertions.assertEquals(0, ConnectorType.JDBC.getCode()); + Assertions.assertEquals(1, ConnectorType.HIVE.getCode()); } @Test public void testGetDescription() { - assertEquals("JDBC", ConnectorType.JDBC.getDescription()); - assertEquals("HIVE", ConnectorType.HIVE.getDescription()); + Assertions.assertEquals("JDBC", ConnectorType.JDBC.getDescription()); + Assertions.assertEquals("HIVE", ConnectorType.HIVE.getDescription()); } @Test public void testOf() { - assertEquals(ConnectorType.JDBC, ConnectorType.of(0)); + Assertions.assertEquals(ConnectorType.JDBC, ConnectorType.of(0)); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/DqFailureStrategyTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/DqFailureStrategyTest.java index f5f478c82e..74ba47493d 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/DqFailureStrategyTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/DqFailureStrategyTest.java @@ -17,27 +17,26 @@ package org.apache.dolphinscheduler.plugin.task.api.enums.dp; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class DqFailureStrategyTest { @Test public void testGetCode() { - assertEquals(0, DqFailureStrategy.ALERT.getCode()); - assertEquals(1, DqFailureStrategy.BLOCK.getCode()); + Assertions.assertEquals(0, DqFailureStrategy.ALERT.getCode()); + Assertions.assertEquals(1, DqFailureStrategy.BLOCK.getCode()); } @Test public void testGetDescription() { - assertEquals("alert", DqFailureStrategy.ALERT.getDescription()); - assertEquals("block", DqFailureStrategy.BLOCK.getDescription()); + Assertions.assertEquals("alert", DqFailureStrategy.ALERT.getDescription()); + Assertions.assertEquals("block", DqFailureStrategy.BLOCK.getDescription()); } @Test public void testOf() { - assertEquals(DqFailureStrategy.ALERT, DqFailureStrategy.of(0)); - assertEquals(DqFailureStrategy.BLOCK, DqFailureStrategy.of(1)); + Assertions.assertEquals(DqFailureStrategy.ALERT, DqFailureStrategy.of(0)); + Assertions.assertEquals(DqFailureStrategy.BLOCK, DqFailureStrategy.of(1)); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/DqTaskStateTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/DqTaskStateTest.java index ed3a306819..2e8aaa3cb1 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/DqTaskStateTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/DqTaskStateTest.java @@ -17,30 +17,29 @@ package org.apache.dolphinscheduler.plugin.task.api.enums.dp; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class DqTaskStateTest { @Test public void testGetCode() { - assertEquals(0, DqTaskState.DEFAULT.getCode()); - assertEquals(1, DqTaskState.SUCCESS.getCode()); - assertEquals(2, DqTaskState.FAILURE.getCode()); + Assertions.assertEquals(0, DqTaskState.DEFAULT.getCode()); + Assertions.assertEquals(1, DqTaskState.SUCCESS.getCode()); + Assertions.assertEquals(2, DqTaskState.FAILURE.getCode()); } @Test public void testGetDescription() { - assertEquals("default", DqTaskState.DEFAULT.getDescription()); - assertEquals("success", DqTaskState.SUCCESS.getDescription()); - assertEquals("failure", DqTaskState.FAILURE.getDescription()); + Assertions.assertEquals("default", DqTaskState.DEFAULT.getDescription()); + Assertions.assertEquals("success", DqTaskState.SUCCESS.getDescription()); + Assertions.assertEquals("failure", DqTaskState.FAILURE.getDescription()); } @Test public void testOf() { - assertEquals(DqTaskState.DEFAULT, DqTaskState.of(0)); - assertEquals(DqTaskState.SUCCESS, DqTaskState.of(1)); - assertEquals(DqTaskState.FAILURE, DqTaskState.of(2)); + Assertions.assertEquals(DqTaskState.DEFAULT, DqTaskState.of(0)); + Assertions.assertEquals(DqTaskState.SUCCESS, DqTaskState.of(1)); + Assertions.assertEquals(DqTaskState.FAILURE, DqTaskState.of(2)); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ExecuteSqlTypeTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ExecuteSqlTypeTest.java index 5262eff30d..48c15abfba 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ExecuteSqlTypeTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ExecuteSqlTypeTest.java @@ -17,30 +17,29 @@ package org.apache.dolphinscheduler.plugin.task.api.enums.dp; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ExecuteSqlTypeTest { @Test public void testGetCode() { - assertEquals(0, ExecuteSqlType.MIDDLE.getCode()); - assertEquals(1, ExecuteSqlType.STATISTICS.getCode()); - assertEquals(2, ExecuteSqlType.COMPARISON.getCode()); + Assertions.assertEquals(0, ExecuteSqlType.MIDDLE.getCode()); + Assertions.assertEquals(1, ExecuteSqlType.STATISTICS.getCode()); + Assertions.assertEquals(2, ExecuteSqlType.COMPARISON.getCode()); } @Test public void testGetDescription() { - assertEquals("middle", ExecuteSqlType.MIDDLE.getDescription()); - assertEquals("statistics", ExecuteSqlType.STATISTICS.getDescription()); - assertEquals("comparison", ExecuteSqlType.COMPARISON.getDescription()); + Assertions.assertEquals("middle", ExecuteSqlType.MIDDLE.getDescription()); + Assertions.assertEquals("statistics", ExecuteSqlType.STATISTICS.getDescription()); + Assertions.assertEquals("comparison", ExecuteSqlType.COMPARISON.getDescription()); } @Test public void testOf() { - assertEquals(ExecuteSqlType.MIDDLE, ExecuteSqlType.of(0)); - assertEquals(ExecuteSqlType.STATISTICS, ExecuteSqlType.of(1)); - assertEquals(ExecuteSqlType.COMPARISON, ExecuteSqlType.of(2)); + Assertions.assertEquals(ExecuteSqlType.MIDDLE, ExecuteSqlType.of(0)); + Assertions.assertEquals(ExecuteSqlType.STATISTICS, ExecuteSqlType.of(1)); + Assertions.assertEquals(ExecuteSqlType.COMPARISON, ExecuteSqlType.of(2)); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/InputTypeTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/InputTypeTest.java index d4515cd720..6bc835ce0a 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/InputTypeTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/InputTypeTest.java @@ -17,33 +17,32 @@ package org.apache.dolphinscheduler.plugin.task.api.enums.dp; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class InputTypeTest { @Test public void testGetCode() { - assertEquals(0, InputType.DEFAULT.getCode()); - assertEquals(1, InputType.STATISTICS.getCode()); - assertEquals(2, InputType.COMPARISON.getCode()); - assertEquals(3, InputType.CHECK.getCode()); + Assertions.assertEquals(0, InputType.DEFAULT.getCode()); + Assertions.assertEquals(1, InputType.STATISTICS.getCode()); + Assertions.assertEquals(2, InputType.COMPARISON.getCode()); + Assertions.assertEquals(3, InputType.CHECK.getCode()); } @Test public void testGetDescription() { - assertEquals("default", InputType.DEFAULT.getDescription()); - assertEquals("statistics", InputType.STATISTICS.getDescription()); - assertEquals("comparison", InputType.COMPARISON.getDescription()); - assertEquals("check", InputType.CHECK.getDescription()); + Assertions.assertEquals("default", InputType.DEFAULT.getDescription()); + Assertions.assertEquals("statistics", InputType.STATISTICS.getDescription()); + Assertions.assertEquals("comparison", InputType.COMPARISON.getDescription()); + Assertions.assertEquals("check", InputType.CHECK.getDescription()); } @Test public void testOf() { - assertEquals(InputType.DEFAULT, InputType.of(0)); - assertEquals(InputType.STATISTICS, InputType.of(1)); - assertEquals(InputType.COMPARISON, InputType.of(2)); - assertEquals(InputType.CHECK, InputType.of(3)); + Assertions.assertEquals(InputType.DEFAULT, InputType.of(0)); + Assertions.assertEquals(InputType.STATISTICS, InputType.of(1)); + Assertions.assertEquals(InputType.COMPARISON, InputType.of(2)); + Assertions.assertEquals(InputType.CHECK, InputType.of(3)); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/OperatorTypeTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/OperatorTypeTest.java index 0e8f2914b1..ee071a4451 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/OperatorTypeTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/OperatorTypeTest.java @@ -17,39 +17,38 @@ package org.apache.dolphinscheduler.plugin.task.api.enums.dp; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class OperatorTypeTest { @Test public void testGetCode() { - assertEquals(0, OperatorType.EQ.getCode()); - assertEquals(1, OperatorType.LT.getCode()); - assertEquals(2, OperatorType.LE.getCode()); - assertEquals(3, OperatorType.GT.getCode()); - assertEquals(4, OperatorType.GE.getCode()); - assertEquals(5, OperatorType.NE.getCode()); + Assertions.assertEquals(0, OperatorType.EQ.getCode()); + Assertions.assertEquals(1, OperatorType.LT.getCode()); + Assertions.assertEquals(2, OperatorType.LE.getCode()); + Assertions.assertEquals(3, OperatorType.GT.getCode()); + Assertions.assertEquals(4, OperatorType.GE.getCode()); + Assertions.assertEquals(5, OperatorType.NE.getCode()); } @Test public void testGetDescription() { - assertEquals("equal", OperatorType.EQ.getDescription()); - assertEquals("little than", OperatorType.LT.getDescription()); - assertEquals("little and equal", OperatorType.LE.getDescription()); - assertEquals("great than", OperatorType.GT.getDescription()); - assertEquals("great and equal", OperatorType.GE.getDescription()); - assertEquals("not equal", OperatorType.NE.getDescription()); + Assertions.assertEquals("equal", OperatorType.EQ.getDescription()); + Assertions.assertEquals("little than", OperatorType.LT.getDescription()); + Assertions.assertEquals("little and equal", OperatorType.LE.getDescription()); + Assertions.assertEquals("great than", OperatorType.GT.getDescription()); + Assertions.assertEquals("great and equal", OperatorType.GE.getDescription()); + Assertions.assertEquals("not equal", OperatorType.NE.getDescription()); } @Test public void testOf() { - assertEquals(OperatorType.EQ, OperatorType.of(0)); - assertEquals(OperatorType.LT, OperatorType.of(1)); - assertEquals(OperatorType.LE, OperatorType.of(2)); - assertEquals(OperatorType.GT, OperatorType.of(3)); - assertEquals(OperatorType.GE, OperatorType.of(4)); - assertEquals(OperatorType.NE, OperatorType.of(5)); + Assertions.assertEquals(OperatorType.EQ, OperatorType.of(0)); + Assertions.assertEquals(OperatorType.LT, OperatorType.of(1)); + Assertions.assertEquals(OperatorType.LE, OperatorType.of(2)); + Assertions.assertEquals(OperatorType.GT, OperatorType.of(3)); + Assertions.assertEquals(OperatorType.GE, OperatorType.of(4)); + Assertions.assertEquals(OperatorType.NE, OperatorType.of(5)); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/OptionSourceTypeTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/OptionSourceTypeTest.java index 7813a5b2b1..42fa81417f 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/OptionSourceTypeTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/OptionSourceTypeTest.java @@ -17,33 +17,32 @@ package org.apache.dolphinscheduler.plugin.task.api.enums.dp; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class OptionSourceTypeTest { @Test public void testGetCode() { - assertEquals(0, OptionSourceType.DEFAULT.getCode()); - assertEquals(1, OptionSourceType.DATASOURCE_ID.getCode()); - assertEquals(2, OptionSourceType.DATASOURCE_TYPE.getCode()); - assertEquals(3, OptionSourceType.COMPARISON_TYPE.getCode()); + Assertions.assertEquals(0, OptionSourceType.DEFAULT.getCode()); + Assertions.assertEquals(1, OptionSourceType.DATASOURCE_ID.getCode()); + Assertions.assertEquals(2, OptionSourceType.DATASOURCE_TYPE.getCode()); + Assertions.assertEquals(3, OptionSourceType.COMPARISON_TYPE.getCode()); } @Test public void testGetDescription() { - assertEquals("default", OptionSourceType.DEFAULT.getDescription()); - assertEquals("datasource_id", OptionSourceType.DATASOURCE_ID.getDescription()); - assertEquals("datasource_type", OptionSourceType.DATASOURCE_TYPE.getDescription()); - assertEquals("comparison_type", OptionSourceType.COMPARISON_TYPE.getDescription()); + Assertions.assertEquals("default", OptionSourceType.DEFAULT.getDescription()); + Assertions.assertEquals("datasource_id", OptionSourceType.DATASOURCE_ID.getDescription()); + Assertions.assertEquals("datasource_type", OptionSourceType.DATASOURCE_TYPE.getDescription()); + Assertions.assertEquals("comparison_type", OptionSourceType.COMPARISON_TYPE.getDescription()); } @Test public void testOf() { - assertEquals(OptionSourceType.DEFAULT, OptionSourceType.of(0)); - assertEquals(OptionSourceType.DATASOURCE_ID, OptionSourceType.of(1)); - assertEquals(OptionSourceType.DATASOURCE_TYPE, OptionSourceType.of(2)); - assertEquals(OptionSourceType.COMPARISON_TYPE, OptionSourceType.of(3)); + Assertions.assertEquals(OptionSourceType.DEFAULT, OptionSourceType.of(0)); + Assertions.assertEquals(OptionSourceType.DATASOURCE_ID, OptionSourceType.of(1)); + Assertions.assertEquals(OptionSourceType.DATASOURCE_TYPE, OptionSourceType.of(2)); + Assertions.assertEquals(OptionSourceType.COMPARISON_TYPE, OptionSourceType.of(3)); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/RuleTypeTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/RuleTypeTest.java index f8e93f8073..3c05e3ac66 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/RuleTypeTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/RuleTypeTest.java @@ -17,33 +17,32 @@ package org.apache.dolphinscheduler.plugin.task.api.enums.dp; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class RuleTypeTest { @Test public void testGetCode() { - assertEquals(0, RuleType.SINGLE_TABLE.getCode()); - assertEquals(1, RuleType.SINGLE_TABLE_CUSTOM_SQL.getCode()); - assertEquals(2, RuleType.MULTI_TABLE_ACCURACY.getCode()); - assertEquals(3, RuleType.MULTI_TABLE_COMPARISON.getCode()); + Assertions.assertEquals(0, RuleType.SINGLE_TABLE.getCode()); + Assertions.assertEquals(1, RuleType.SINGLE_TABLE_CUSTOM_SQL.getCode()); + Assertions.assertEquals(2, RuleType.MULTI_TABLE_ACCURACY.getCode()); + Assertions.assertEquals(3, RuleType.MULTI_TABLE_COMPARISON.getCode()); } - + @Test public void testGetDescription() { - assertEquals("single_table", RuleType.SINGLE_TABLE.getDescription()); - assertEquals("single_table_custom_sql", RuleType.SINGLE_TABLE_CUSTOM_SQL.getDescription()); - assertEquals("multi_table_accuracy", RuleType.MULTI_TABLE_ACCURACY.getDescription()); - assertEquals("multi_table_comparison", RuleType.MULTI_TABLE_COMPARISON.getDescription()); + Assertions.assertEquals("single_table", RuleType.SINGLE_TABLE.getDescription()); + Assertions.assertEquals("single_table_custom_sql", RuleType.SINGLE_TABLE_CUSTOM_SQL.getDescription()); + Assertions.assertEquals("multi_table_accuracy", RuleType.MULTI_TABLE_ACCURACY.getDescription()); + Assertions.assertEquals("multi_table_comparison", RuleType.MULTI_TABLE_COMPARISON.getDescription()); } @Test public void testOf() { - assertEquals(RuleType.SINGLE_TABLE, RuleType.of(0)); - assertEquals(RuleType.SINGLE_TABLE_CUSTOM_SQL, RuleType.of(1)); - assertEquals(RuleType.MULTI_TABLE_ACCURACY, RuleType.of(2)); - assertEquals(RuleType.MULTI_TABLE_COMPARISON, RuleType.of(3)); + Assertions.assertEquals(RuleType.SINGLE_TABLE, RuleType.of(0)); + Assertions.assertEquals(RuleType.SINGLE_TABLE_CUSTOM_SQL, RuleType.of(1)); + Assertions.assertEquals(RuleType.MULTI_TABLE_ACCURACY, RuleType.of(2)); + Assertions.assertEquals(RuleType.MULTI_TABLE_COMPARISON, RuleType.of(3)); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ValueTypeTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ValueTypeTest.java index c45c8b9b5b..9cf622b723 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ValueTypeTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ValueTypeTest.java @@ -17,11 +17,11 @@ package org.apache.dolphinscheduler.plugin.task.api.enums.dp; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ValueTypeTest { + /** * 0-string * 1-list @@ -30,25 +30,25 @@ public class ValueTypeTest { */ @Test public void testGetCode() { - assertEquals(0, ValueType.STRING.getCode()); - assertEquals(1, ValueType.LIST.getCode()); - assertEquals(2, ValueType.NUMBER.getCode()); - assertEquals(3, ValueType.LIKE_SQL.getCode()); + Assertions.assertEquals(0, ValueType.STRING.getCode()); + Assertions.assertEquals(1, ValueType.LIST.getCode()); + Assertions.assertEquals(2, ValueType.NUMBER.getCode()); + Assertions.assertEquals(3, ValueType.LIKE_SQL.getCode()); } - + @Test public void testGetDescription() { - assertEquals("string", ValueType.STRING.getDescription()); - assertEquals("list", ValueType.LIST.getDescription()); - assertEquals("number", ValueType.NUMBER.getDescription()); - assertEquals("sql", ValueType.LIKE_SQL.getDescription()); + Assertions.assertEquals("string", ValueType.STRING.getDescription()); + Assertions.assertEquals("list", ValueType.LIST.getDescription()); + Assertions.assertEquals("number", ValueType.NUMBER.getDescription()); + Assertions.assertEquals("sql", ValueType.LIKE_SQL.getDescription()); } @Test public void testOf() { - assertEquals(ValueType.STRING, ValueType.of(0)); - assertEquals(ValueType.LIST, ValueType.of(1)); - assertEquals(ValueType.NUMBER, ValueType.of(2)); - assertEquals(ValueType.LIKE_SQL, ValueType.of(3)); + Assertions.assertEquals(ValueType.STRING, ValueType.of(0)); + Assertions.assertEquals(ValueType.LIST, ValueType.of(1)); + Assertions.assertEquals(ValueType.NUMBER, ValueType.of(2)); + Assertions.assertEquals(ValueType.LIKE_SQL, ValueType.of(3)); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/k8s/K8sTaskExecutorTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/k8s/K8sTaskExecutorTest.java index 19b37ca413..075500ff6e 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/k8s/K8sTaskExecutorTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/k8s/K8sTaskExecutorTest.java @@ -20,7 +20,6 @@ package org.apache.dolphinscheduler.plugin.task.api.k8s; import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.CLUSTER; import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_CODE_KILL; import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.NAMESPACE_NAME; -import static org.hamcrest.Matchers.is; import org.apache.dolphinscheduler.plugin.task.api.TaskException; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; @@ -30,9 +29,9 @@ import org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.Map; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import io.fabric8.kubernetes.api.model.batch.v1.Job; import io.fabric8.kubernetes.api.model.batch.v1.JobStatus; @@ -48,7 +47,7 @@ public class K8sTaskExecutorTest { private final int taskInstanceId = 1000; private final String taskName = "k8s_task_test"; private Job job; - @Before + @BeforeEach public void before() { TaskExecutionContext taskRequest = new TaskExecutionContext(); taskRequest.setTaskInstanceId(taskInstanceId); @@ -70,7 +69,7 @@ public class K8sTaskExecutorTest { JobStatus jobStatus = new JobStatus(); jobStatus.setSucceeded(1); job.setStatus(jobStatus); - Assert.assertEquals(0, Integer.compare(0, k8sTaskExecutor.getK8sJobStatus(job))); + Assertions.assertEquals(0, Integer.compare(0, k8sTaskExecutor.getK8sJobStatus(job))); } @Test public void testSetTaskStatusNormal() { @@ -79,14 +78,14 @@ public class K8sTaskExecutorTest { K8sTaskMainParameters k8STaskMainParameters = new K8sTaskMainParameters(); k8sTaskExecutor.setJob(job); k8sTaskExecutor.setTaskStatus(jobStatus, String.valueOf(taskInstanceId), taskResponse, k8STaskMainParameters); - Assert.assertEquals(0, Integer.compare(EXIT_CODE_KILL, taskResponse.getExitStatusCode())); + Assertions.assertEquals(0, Integer.compare(EXIT_CODE_KILL, taskResponse.getExitStatusCode())); } @Test public void testWaitTimeoutNormal() { try { k8sTaskExecutor.waitTimeout(true); } catch (TaskException e) { - Assert.assertThat(e.getMessage(), is("K8sTask is timeout")); + Assertions.assertEquals(e.getMessage(), "K8sTask is timeout"); } } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/parser/HttpTaskDefinitionParserTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/parser/HttpTaskDefinitionParserTest.java index 71707bfd45..3bcb80585d 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/parser/HttpTaskDefinitionParserTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/parser/HttpTaskDefinitionParserTest.java @@ -21,22 +21,22 @@ import org.apache.dolphinscheduler.plugin.task.api.loop.template.LoopTaskYamlDef import java.io.IOException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class HttpTaskDefinitionParserTest { private static final String yamlFile = HttpTaskDefinitionParserTest.class.getResource("/mock_loop_task.yaml") - .getFile(); + .getFile(); @Test public void parseYamlConfigFile() throws IOException { LoopTaskYamlDefinition loopTaskYamlDefinition = new HttpTaskDefinitionParser().parseYamlConfigFile(yamlFile); - Assert.assertNotNull(loopTaskYamlDefinition); - Assert.assertNotNull(loopTaskYamlDefinition.getService()); + Assertions.assertNotNull(loopTaskYamlDefinition); + Assertions.assertNotNull(loopTaskYamlDefinition.getService()); LoopTaskYamlDefinition.LoopTaskServiceYamlDefinition service = loopTaskYamlDefinition.getService(); - Assert.assertEquals("MockService", service.getName()); - Assert.assertNotNull(service.getApi()); + Assertions.assertEquals("MockService", service.getName()); + Assertions.assertNotNull(service.getApi()); } @Test @@ -45,7 +45,7 @@ public class HttpTaskDefinitionParserTest { LoopTaskYamlDefinition loopTaskYamlDefinition = httpTaskDefinitionParser.parseYamlConfigFile(yamlFile); httpTaskDefinitionParser.validateYamlDefinition(loopTaskYamlDefinition); // if no exception assert true - Assert.assertTrue(true); + Assertions.assertTrue(true); } -} \ No newline at end of file +} diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParametersTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParametersTest.java index 44f73c242b..435b5f60c2 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParametersTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParametersTest.java @@ -25,14 +25,15 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class AbstractParametersTest { @Test public void testGetInputLocalParametersMap() { AbstractParameters parameters = new AbstractParameters() { + @Override public boolean checkParameters() { return false; @@ -47,8 +48,8 @@ public class AbstractParametersTest { // should return property key1 and key2 (direct null and IN) Map inputLocalParametersMap = parameters.getInputLocalParametersMap(); - Assert.assertEquals(2, inputLocalParametersMap.size()); - Assert.assertTrue(inputLocalParametersMap.containsKey("key1")); - Assert.assertTrue(inputLocalParametersMap.containsKey("key2")); + Assertions.assertEquals(2, inputLocalParametersMap.size()); + Assertions.assertTrue(inputLocalParametersMap.containsKey("key1")); + Assertions.assertTrue(inputLocalParametersMap.containsKey("key2")); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParametersTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParametersTest.java index 6fa1148795..83fe739f47 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParametersTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParametersTest.java @@ -17,8 +17,6 @@ package org.apache.dolphinscheduler.plugin.task.api.parameters; -import static org.junit.Assert.assertNotNull; - import org.apache.dolphinscheduler.plugin.task.api.enums.DataType; import org.apache.dolphinscheduler.plugin.task.api.enums.Direct; import org.apache.dolphinscheduler.plugin.task.api.model.Property; @@ -28,8 +26,8 @@ import org.apache.commons.collections4.CollectionUtils; import java.util.ArrayList; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class SqlParametersTest { @@ -55,7 +53,7 @@ public class SqlParametersTest { properties.add(property); SqlParameters sqlParameters = new SqlParameters(); - Assert.assertTrue(CollectionUtils.isEmpty(sqlParameters.getResourceFilesList())); + Assertions.assertTrue(CollectionUtils.isEmpty(sqlParameters.getResourceFilesList())); sqlParameters.setType(type); sqlParameters.setSql(sql); @@ -68,29 +66,29 @@ public class SqlParametersTest { sqlParameters.setTitle(title); sqlParameters.setGroupId(groupId); - Assert.assertEquals(type, sqlParameters.getType()); - Assert.assertEquals(sql, sqlParameters.getSql()); - Assert.assertEquals(udfs, sqlParameters.getUdfs()); - Assert.assertEquals(datasource, sqlParameters.getDatasource()); - Assert.assertEquals(sqlType, sqlParameters.getSqlType()); - Assert.assertEquals(sendEmail, sqlParameters.getSendEmail()); - Assert.assertEquals(displayRows, sqlParameters.getDisplayRows()); - Assert.assertEquals(showType, sqlParameters.getShowType()); - Assert.assertEquals(title, sqlParameters.getTitle()); - Assert.assertEquals(groupId, sqlParameters.getGroupId()); + Assertions.assertEquals(type, sqlParameters.getType()); + Assertions.assertEquals(sql, sqlParameters.getSql()); + Assertions.assertEquals(udfs, sqlParameters.getUdfs()); + Assertions.assertEquals(datasource, sqlParameters.getDatasource()); + Assertions.assertEquals(sqlType, sqlParameters.getSqlType()); + Assertions.assertEquals(sendEmail, sqlParameters.getSendEmail()); + Assertions.assertEquals(displayRows, sqlParameters.getDisplayRows()); + Assertions.assertEquals(showType, sqlParameters.getShowType()); + Assertions.assertEquals(title, sqlParameters.getTitle()); + Assertions.assertEquals(groupId, sqlParameters.getGroupId()); String sqlResult = "[{\"id\":6,\"test1\":\"6\"},{\"id\":70002,\"test1\":\"+1\"}]"; String sqlResult1 = "[{\"id\":6,\"test1\":\"6\"}]"; sqlParameters.setLocalParams(properties); sqlParameters.varPool = new ArrayList<>(); sqlParameters.dealOutParam(sqlResult1); - assertNotNull(sqlParameters.getVarPool().get(0)); + Assertions.assertNotNull(sqlParameters.getVarPool().get(0)); property.setType(DataType.LIST); properties.clear(); properties.add(property); sqlParameters.setLocalParams(properties); sqlParameters.dealOutParam(sqlResult); - assertNotNull(sqlParameters.getVarPool().get(0)); + Assertions.assertNotNull(sqlParameters.getVarPool().get(0)); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/resource/AbstractResourceParametersTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/resource/AbstractResourceParametersTest.java index 9f96294038..5059e0a635 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/resource/AbstractResourceParametersTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/resource/AbstractResourceParametersTest.java @@ -22,17 +22,19 @@ import org.apache.dolphinscheduler.plugin.task.api.parameters.SqlParameters; import org.apache.dolphinscheduler.spi.enums.DbType; import org.apache.dolphinscheduler.spi.utils.JSONUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class AbstractResourceParametersTest { @Test public void testDataSource() { TaskExecutionContext taskExecutionContext = new TaskExecutionContext(); - String taskParam = "{\"localParams\":[],\"resourceList\":[],\"type\":\"MYSQL\",\"datasource\":\"1\",\"sql\":\"select now();\",\"sqlType\":\"0\",\"preStatements\":[],\"postStatements\":[],\"conditionResult\":\"null\",\"dependence\":\"null\",\"switchResult\":\"null\",\"waitStartTimeout\":null}"; + String taskParam = + "{\"localParams\":[],\"resourceList\":[],\"type\":\"MYSQL\",\"datasource\":\"1\",\"sql\":\"select now();\",\"sqlType\":\"0\",\"preStatements\":[],\"postStatements\":[],\"conditionResult\":\"null\",\"dependence\":\"null\",\"switchResult\":\"null\",\"waitStartTimeout\":null}"; - ResourceParametersHelper resourceParametersHelper = JSONUtils.parseObject(taskParam, SqlParameters.class).getResources(); + ResourceParametersHelper resourceParametersHelper = + JSONUtils.parseObject(taskParam, SqlParameters.class).getResources(); resourceParametersHelper.getResourceMap().forEach((type, map) -> { map.forEach((code, parameters) -> { @@ -49,8 +51,6 @@ public class AbstractResourceParametersTest { taskExecutionContext = JSONUtils.parseObject(json, TaskExecutionContext.class); - Assert.assertNotNull(taskExecutionContext); + Assertions.assertNotNull(taskExecutionContext); } } - - diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/ParameterUtilsTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/ParameterUtilsTest.java index ddee405935..206f473016 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/ParameterUtilsTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/ParameterUtilsTest.java @@ -24,8 +24,8 @@ import org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.HashMap; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import com.google.common.collect.Lists; @@ -34,19 +34,22 @@ public class ParameterUtilsTest { @Test public void expandListParameter() { Map params = new HashMap<>(); - params.put(1, new Property(null, null, DataType.LIST, JSONUtils.toJsonString(Lists.newArrayList("c1", "c2", "c3")))); + params.put(1, + new Property(null, null, DataType.LIST, JSONUtils.toJsonString(Lists.newArrayList("c1", "c2", "c3")))); params.put(2, new Property(null, null, DataType.DATE, "2020-06-30")); - params.put(3, new Property(null, null, DataType.LIST, JSONUtils.toJsonString(Lists.newArrayList(3.1415, 2.44, 3.44)))); - String sql = ParameterUtils.expandListParameter(params, "select * from test where col1 in (?) and date=? and col2 in (?)"); - Assert.assertEquals("select * from test where col1 in (?,?,?) and date=? and col2 in (?,?,?)", sql); - Assert.assertEquals(7, params.size()); + params.put(3, new Property(null, null, DataType.LIST, + JSONUtils.toJsonString(Lists.newArrayList(3.1415, 2.44, 3.44)))); + String sql = ParameterUtils.expandListParameter(params, + "select * from test where col1 in (?) and date=? and col2 in (?)"); + Assertions.assertEquals("select * from test where col1 in (?,?,?) and date=? and col2 in (?,?,?)", sql); + Assertions.assertEquals(7, params.size()); Map params2 = new HashMap<>(); params2.put(1, new Property(null, null, DataType.LIST, JSONUtils.toJsonString(Lists.newArrayList("c1")))); params2.put(2, new Property(null, null, DataType.DATE, "2020-06-30")); String sql2 = ParameterUtils.expandListParameter(params2, "select * from test where col1 in (?) and date=?"); - Assert.assertEquals("select * from test where col1 in (?) and date=?", sql2); - Assert.assertEquals(2, params2.size()); + Assertions.assertEquals("select * from test where col1 in (?) and date=?", sql2); + Assertions.assertEquals(2, params2.size()); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtilsTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtilsTest.java index f16192adec..50aed45177 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtilsTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtilsTest.java @@ -23,11 +23,11 @@ import org.apache.dolphinscheduler.spi.utils.DateUtils; import java.util.Date; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; - +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TimePlaceholderUtilsTest { + Date date = DateUtils.parse("2022-08-26 00:00:00", "yyyy-MM-dd HH:mm:ss"); Map timeParams = BusinessTimeUtils.getBusinessTime(CommandType.COMPLEMENT_DATA, date); @@ -38,10 +38,10 @@ public class TimePlaceholderUtilsTest { String thisDate = "$[this_day(yyyyMMdd)]"; String thisDayTime = ParameterUtils.convertParameterPlaceholders(thisDay, timeParams); - Assert.assertEquals(thisDayTime, "2022-08-26"); + Assertions.assertEquals(thisDayTime, "2022-08-26"); String thisDateTime = ParameterUtils.convertParameterPlaceholders(thisDate, timeParams); - Assert.assertEquals(thisDateTime, "20220826"); + Assertions.assertEquals(thisDateTime, "20220826"); } @Test @@ -49,10 +49,10 @@ public class TimePlaceholderUtilsTest { String lastDay = "$[last_day(yyyy-MM-dd)]"; String lastDate = "$[last_day(yyyyMMdd)]"; String lastDayTime = ParameterUtils.convertParameterPlaceholders(lastDay, timeParams); - Assert.assertEquals(lastDayTime, "2022-08-25"); + Assertions.assertEquals(lastDayTime, "2022-08-25"); String lastDateTime = ParameterUtils.convertParameterPlaceholders(lastDate, timeParams); - Assert.assertEquals(lastDateTime, "20220825"); + Assertions.assertEquals(lastDateTime, "20220825"); } @Test @@ -62,20 +62,20 @@ public class TimePlaceholderUtilsTest { String yearWeekDay = "$[year_week(yyyyMMdd)]"; String yearWeekDateTime = ParameterUtils.convertParameterPlaceholders(yearWeekDate, timeParams); - Assert.assertEquals(yearWeekDateTime, "2022-34"); + Assertions.assertEquals(yearWeekDateTime, "2022-34"); String yearWeekDayTime = ParameterUtils.convertParameterPlaceholders(yearWeekDay, timeParams); - Assert.assertEquals(yearWeekDayTime, "202234"); + Assertions.assertEquals(yearWeekDayTime, "202234"); // Start the week on Friday String yearWeekDateAny = "$[year_week(yyyy-MM-dd,5)]"; String yearWeekDayAny = "$[year_week(yyyyMMdd,5)]"; String yearWeekDateAnyTime = ParameterUtils.convertParameterPlaceholders(yearWeekDateAny, timeParams); - Assert.assertEquals(yearWeekDateAnyTime, "2022-35"); + Assertions.assertEquals(yearWeekDateAnyTime, "2022-35"); String yearWeekDayAnyTime = ParameterUtils.convertParameterPlaceholders(yearWeekDayAny, timeParams); - Assert.assertEquals(yearWeekDayAnyTime, "202235"); + Assertions.assertEquals(yearWeekDayAnyTime, "202235"); } @Test @@ -84,10 +84,10 @@ public class TimePlaceholderUtilsTest { String monthFirstDay = "$[month_first_day(yyyyMMdd,-1)]"; String monthFirstDateTime = ParameterUtils.convertParameterPlaceholders(monthFirstDate, timeParams); - Assert.assertEquals(monthFirstDateTime, "2022-07-01"); + Assertions.assertEquals(monthFirstDateTime, "2022-07-01"); String monthFirstDayTime = ParameterUtils.convertParameterPlaceholders(monthFirstDay, timeParams); - Assert.assertEquals(monthFirstDayTime, "20220701"); + Assertions.assertEquals(monthFirstDayTime, "20220701"); } @Test @@ -96,10 +96,10 @@ public class TimePlaceholderUtilsTest { String monthLastDay = "$[month_last_day(yyyyMMdd,-1)]"; String monthLastDateTime = ParameterUtils.convertParameterPlaceholders(monthLastDate, timeParams); - Assert.assertEquals(monthLastDateTime, "2022-07-31"); + Assertions.assertEquals(monthLastDateTime, "2022-07-31"); String monthLastDayTime = ParameterUtils.convertParameterPlaceholders(monthLastDay, timeParams); - Assert.assertEquals(monthLastDayTime, "20220731"); + Assertions.assertEquals(monthLastDayTime, "20220731"); } @Test @@ -108,10 +108,10 @@ public class TimePlaceholderUtilsTest { String weekFirstDay = "$[week_first_day(yyyyMMdd,0)]"; String weekFirstDateTime = ParameterUtils.convertParameterPlaceholders(weekFirstDate, timeParams); - Assert.assertEquals(weekFirstDateTime, "2022-08-22"); + Assertions.assertEquals(weekFirstDateTime, "2022-08-22"); String weekFirstDayTime = ParameterUtils.convertParameterPlaceholders(weekFirstDay, timeParams); - Assert.assertEquals(weekFirstDayTime, "20220822"); + Assertions.assertEquals(weekFirstDayTime, "20220822"); } @Test @@ -120,9 +120,9 @@ public class TimePlaceholderUtilsTest { String weekLastDay = "$[week_last_day(yyyyMMdd,0)]"; String weekLastDateTime = ParameterUtils.convertParameterPlaceholders(weekLastDate, timeParams); - Assert.assertEquals(weekLastDateTime,"2022-08-28"); + Assertions.assertEquals(weekLastDateTime, "2022-08-28"); String weekLastDayTime = ParameterUtils.convertParameterPlaceholders(weekLastDay, timeParams); - Assert.assertEquals(weekLastDayTime,"20220828"); + Assertions.assertEquals(weekLastDayTime, "20220828"); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/DependentUtilsTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/DependentUtilsTest.java index 1f21989a6a..a5e2114c31 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/DependentUtilsTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/DependentUtilsTest.java @@ -26,85 +26,86 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.collect.Lists; public class DependentUtilsTest { + private static final Logger logger = LoggerFactory.getLogger(DependentUtilsTest.class); @Test public void getDependResultForRelation() { - //failed + // failed DependentRelation dependentRelation = DependentRelation.AND; List dependResultList = new ArrayList<>(); dependResultList.add(DependResult.FAILED); dependResultList.add(DependResult.SUCCESS); DependResult result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); - Assert.assertEquals(result, DependResult.FAILED); + Assertions.assertEquals(result, DependResult.FAILED); - //waiting + // waiting dependResultList = new ArrayList<>(); dependResultList.add(DependResult.WAITING); dependResultList.add(DependResult.SUCCESS); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); - Assert.assertEquals(result, DependResult.WAITING); + Assertions.assertEquals(result, DependResult.WAITING); - //success + // success dependResultList = new ArrayList<>(); dependResultList.add(DependResult.SUCCESS); dependResultList.add(DependResult.SUCCESS); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); - Assert.assertEquals(result, DependResult.SUCCESS); + Assertions.assertEquals(result, DependResult.SUCCESS); - //one success + // one success dependResultList = new ArrayList<>(); dependResultList.add(DependResult.SUCCESS); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); - Assert.assertEquals(result, DependResult.SUCCESS); + Assertions.assertEquals(result, DependResult.SUCCESS); - //one failed + // one failed dependResultList = new ArrayList<>(); dependResultList.add(DependResult.FAILED); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); - Assert.assertEquals(result, DependResult.FAILED); + Assertions.assertEquals(result, DependResult.FAILED); - //or success + // or success dependentRelation = DependentRelation.OR; dependResultList = new ArrayList<>(); dependResultList.add(DependResult.FAILED); dependResultList.add(DependResult.SUCCESS); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); - Assert.assertEquals(result, DependResult.SUCCESS); + Assertions.assertEquals(result, DependResult.SUCCESS); - //waiting + // waiting dependResultList = new ArrayList<>(); dependResultList.add(DependResult.WAITING); dependResultList.add(DependResult.FAILED); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); - Assert.assertEquals(result, DependResult.WAITING); + Assertions.assertEquals(result, DependResult.WAITING); - //success + // success dependResultList = new ArrayList<>(); dependResultList.add(DependResult.SUCCESS); dependResultList.add(DependResult.SUCCESS); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); - Assert.assertEquals(result, DependResult.SUCCESS); + Assertions.assertEquals(result, DependResult.SUCCESS); - //one success + // one success dependResultList = new ArrayList<>(); dependResultList.add(DependResult.SUCCESS); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); - Assert.assertEquals(result, DependResult.SUCCESS); + Assertions.assertEquals(result, DependResult.SUCCESS); - //one failed + // one failed dependResultList = new ArrayList<>(); dependResultList.add(DependResult.FAILED); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); - Assert.assertEquals(result, DependResult.FAILED); + Assertions.assertEquals(result, DependResult.FAILED); } @Test @@ -123,7 +124,7 @@ public class DependentUtilsTest { DateUtils.getEndOfDay(day2)); String dateValue = "last1Days"; List dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue); - Assert.assertEquals(dateIntervals.get(0), di1); + Assertions.assertEquals(dateIntervals.get(0), di1); dateValue = "last2Days"; dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue); @@ -131,142 +132,144 @@ public class DependentUtilsTest { logger.info(dateInterval.getStartTime().toString() + " == " + dateInterval.getEndTime().toString()); } - Assert.assertEquals(dateIntervals.get(1), di1); - Assert.assertEquals(dateIntervals.get(0), di2); + Assertions.assertEquals(dateIntervals.get(1), di1); + Assertions.assertEquals(dateIntervals.get(0), di2); dateValue = "today"; dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue); - Assert.assertEquals(dateIntervals.get(0), diCur); + Assertions.assertEquals(dateIntervals.get(0), diCur); dateValue = "thisWeek"; Date firstWeekDay = DateUtils.getMonday(curDay); dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue); - DateInterval weekHead = new DateInterval(DateUtils.getStartOfDay(firstWeekDay), DateUtils.getEndOfDay(firstWeekDay)); + DateInterval weekHead = + new DateInterval(DateUtils.getStartOfDay(firstWeekDay), DateUtils.getEndOfDay(firstWeekDay)); DateInterval weekThis = new DateInterval(DateUtils.getStartOfDay(curDay), DateUtils.getEndOfDay(curDay)); - Assert.assertEquals(dateIntervals.get(0), weekHead); - Assert.assertEquals(dateIntervals.get(dateIntervals.size() - 1), weekThis); + Assertions.assertEquals(dateIntervals.get(0), weekHead); + Assertions.assertEquals(dateIntervals.get(dateIntervals.size() - 1), weekThis); dateValue = "thisMonth"; Date firstMonthDay = DateUtils.getFirstDayOfMonth(curDay); dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue); - DateInterval monthHead = new DateInterval(DateUtils.getStartOfDay(firstMonthDay), DateUtils.getEndOfDay(firstMonthDay)); + DateInterval monthHead = + new DateInterval(DateUtils.getStartOfDay(firstMonthDay), DateUtils.getEndOfDay(firstMonthDay)); DateInterval monthThis = new DateInterval(DateUtils.getStartOfDay(curDay), DateUtils.getEndOfDay(curDay)); - Assert.assertEquals(dateIntervals.get(0), monthHead); - Assert.assertEquals(dateIntervals.get(dateIntervals.size() - 1), monthThis); + Assertions.assertEquals(dateIntervals.get(0), monthHead); + Assertions.assertEquals(dateIntervals.get(dateIntervals.size() - 1), monthThis); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-04 10:00:00"), "last1Hour"); DateInterval expect = new DateInterval(DateUtils.stringToDate("2019-02-04 09:00:00"), DateUtils.getEndOfHour(DateUtils.stringToDate("2019-02-04 09:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(expect, dateIntervals.get(0)); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-04 10:00:00"), "last2Hours"); expect = new DateInterval(DateUtils.stringToDate("2019-02-04 08:00:00"), DateUtils.getEndOfHour(DateUtils.stringToDate("2019-02-04 08:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(expect, dateIntervals.get(0)); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-04 10:00:00"), "last3Hours"); expect = new DateInterval(DateUtils.stringToDate("2019-02-04 07:00:00"), DateUtils.getEndOfHour(DateUtils.stringToDate("2019-02-04 07:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(expect, dateIntervals.get(0)); dateValue = "last3Days"; dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); expect = new DateInterval(DateUtils.stringToDate("2019-02-07 00:00:00"), DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-07 00:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(expect, dateIntervals.get(0)); dateValue = "last7Days"; dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); expect = new DateInterval(DateUtils.stringToDate("2019-02-03 00:00:00"), DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-03 00:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(expect, dateIntervals.get(0)); dateValue = "lastWeek"; dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); expect = new DateInterval(DateUtils.stringToDate("2019-01-28 00:00:00"), DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-28 00:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(expect, dateIntervals.get(0)); expect = new DateInterval(DateUtils.stringToDate("2019-02-03 00:00:00"), DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-03 00:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(6)); - Assert.assertEquals(7, dateIntervals.size()); + Assertions.assertEquals(expect, dateIntervals.get(6)); + Assertions.assertEquals(7, dateIntervals.size()); dateValue = "lastMonday"; dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); expect = new DateInterval(DateUtils.stringToDate("2019-01-28 00:00:00"), DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-28 00:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); - Assert.assertEquals(1, dateIntervals.size()); + Assertions.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(1, dateIntervals.size()); dateValue = "lastTuesday"; dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); expect = new DateInterval(DateUtils.stringToDate("2019-01-29 00:00:00"), DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-29 00:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); - Assert.assertEquals(1, dateIntervals.size()); + Assertions.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(1, dateIntervals.size()); dateValue = "lastWednesday"; dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); expect = new DateInterval(DateUtils.stringToDate("2019-01-30 00:00:00"), DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-30 00:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); - Assert.assertEquals(1, dateIntervals.size()); + Assertions.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(1, dateIntervals.size()); dateValue = "lastThursday"; dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); expect = new DateInterval(DateUtils.stringToDate("2019-01-31 00:00:00"), DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-31 00:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); - Assert.assertEquals(1, dateIntervals.size()); + Assertions.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(1, dateIntervals.size()); dateValue = "lastFriday"; dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); expect = new DateInterval(DateUtils.stringToDate("2019-02-01 00:00:00"), DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-01 00:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); - Assert.assertEquals(1, dateIntervals.size()); + Assertions.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(1, dateIntervals.size()); dateValue = "lastSaturday"; dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); expect = new DateInterval(DateUtils.stringToDate("2019-02-02 00:00:00"), DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-02 00:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); - Assert.assertEquals(1, dateIntervals.size()); + Assertions.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(1, dateIntervals.size()); dateValue = "lastSunday"; dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); expect = new DateInterval(DateUtils.stringToDate("2019-02-03 00:00:00"), DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-03 00:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); - Assert.assertEquals(1, dateIntervals.size()); + Assertions.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(1, dateIntervals.size()); dateValue = "lastMonth"; dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); expect = new DateInterval(DateUtils.stringToDate("2019-01-01 00:00:00"), DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-01 00:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(expect, dateIntervals.get(0)); expect = new DateInterval(DateUtils.stringToDate("2019-01-31 00:00:00"), DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-31 00:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(30)); - Assert.assertEquals(31, dateIntervals.size()); + Assertions.assertEquals(expect, dateIntervals.get(30)); + Assertions.assertEquals(31, dateIntervals.size()); dateValue = "lastMonthBegin"; dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); expect = new DateInterval(DateUtils.stringToDate("2019-01-01 00:00:00"), DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-01 00:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); - Assert.assertEquals(1, dateIntervals.size()); + Assertions.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(1, dateIntervals.size()); dateValue = "lastMonthEnd"; dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); expect = new DateInterval(DateUtils.stringToDate("2019-01-31 00:00:00"), DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-31 00:00:00"))); - Assert.assertEquals(expect, dateIntervals.get(0)); - Assert.assertEquals(1, dateIntervals.size()); + Assertions.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(1, dateIntervals.size()); } @Test @@ -295,27 +298,27 @@ public class DependentUtilsTest { Date day7 = DateUtils.stringToDate("2019-02-03 00:00:00"); DateInterval di7 = new DateInterval(DateUtils.getStartOfDay(day7), DateUtils.getEndOfDay(day7)); - List dateIntervals = DependentDateUtils.getLastWeekInterval(curDay); - Assert.assertEquals(dateIntervals.size(), 7); - Assert.assertEquals(dateIntervals.get(0), di1); - Assert.assertEquals(dateIntervals.get(1), di2); - Assert.assertEquals(dateIntervals.get(2), di3); - Assert.assertEquals(dateIntervals.get(3), di4); + List dateIntervals = DependentDateUtils.getLastWeekInterval(curDay); + Assertions.assertEquals(dateIntervals.size(), 7); + Assertions.assertEquals(dateIntervals.get(0), di1); + Assertions.assertEquals(dateIntervals.get(1), di2); + Assertions.assertEquals(dateIntervals.get(2), di3); + Assertions.assertEquals(dateIntervals.get(3), di4); List monday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 1); - Assert.assertEquals(monday.get(0), di1); + Assertions.assertEquals(monday.get(0), di1); List tuesday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 2); - Assert.assertEquals(tuesday.get(0), di2); + Assertions.assertEquals(tuesday.get(0), di2); List wednesday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 3); - Assert.assertEquals(wednesday.get(0), di3); + Assertions.assertEquals(wednesday.get(0), di3); List thursday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 4); - Assert.assertEquals(thursday.get(0), di4); + Assertions.assertEquals(thursday.get(0), di4); List friday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 5); - Assert.assertEquals(friday.get(0), di5); + Assertions.assertEquals(friday.get(0), di5); List saturday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 6); - Assert.assertEquals(saturday.get(0), di6); + Assertions.assertEquals(saturday.get(0), di6); List sunday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 7); - Assert.assertEquals(sunday.get(0), di7); + Assertions.assertEquals(sunday.get(0), di7); } @Test @@ -333,14 +336,14 @@ public class DependentUtilsTest { DateUtils.getEndOfHour(day3)); List dateIntervals = DependentDateUtils.getLastHoursInterval(curDay, 1); - Assert.assertEquals(dateIntervals.get(0), di1); + Assertions.assertEquals(dateIntervals.get(0), di1); dateIntervals = DependentDateUtils.getLastHoursInterval(curDay, 2); - Assert.assertEquals(dateIntervals.get(1), di1); - Assert.assertEquals(dateIntervals.get(0), di2); + Assertions.assertEquals(dateIntervals.get(1), di1); + Assertions.assertEquals(dateIntervals.get(0), di2); dateIntervals = DependentDateUtils.getLastHoursInterval(curDay, 3); - Assert.assertEquals(dateIntervals.get(2), di1); - Assert.assertEquals(dateIntervals.get(1), di2); - Assert.assertEquals(dateIntervals.get(0), di3); + Assertions.assertEquals(dateIntervals.get(2), di1); + Assertions.assertEquals(dateIntervals.get(1), di2); + Assertions.assertEquals(dateIntervals.get(0), di3); } @@ -350,12 +353,13 @@ public class DependentUtilsTest { Date curDay = DateUtils.stringToDate("2020-05-15 12:10:00"); - List dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue); + List dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue); - DateInterval expect = new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-15 12:00:00")), DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-15 12:59:59"))); + DateInterval expect = new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-15 12:00:00")), + DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-15 12:59:59"))); - Assert.assertEquals(expect, dateIntervals.get(0)); - Assert.assertEquals(1, dateIntervals.size()); + Assertions.assertEquals(expect, dateIntervals.get(0)); + Assertions.assertEquals(1, dateIntervals.size()); } @Test @@ -371,17 +375,20 @@ public class DependentUtilsTest { if (a < 10) { i = "0" + i; } - DateInterval dateInterval = new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-14 " + i + ":00:00")), - DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-14 " + i + ":59:59"))); + DateInterval dateInterval = + new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-14 " + i + ":00:00")), + DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-14 " + i + ":59:59"))); expect.add(dateInterval); } - DateInterval dateInterval = new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-15 00:00:00")), DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-15 00:59:59"))); + DateInterval dateInterval = + new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-15 00:00:00")), + DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-15 00:59:59"))); expect.add(dateInterval); - Assert.assertEquals(24, dateIntervals.size()); + Assertions.assertEquals(24, dateIntervals.size()); for (int i = 0; i < expect.size(); i++) { - Assert.assertEquals(expect.get(i), dateIntervals.get(i)); + Assertions.assertEquals(expect.get(i), dateIntervals.get(i)); } } @@ -398,9 +405,9 @@ public class DependentUtilsTest { List dateIntervals = DependentDateUtils.getLastMonthInterval(curDay); - Assert.assertEquals(dateIntervals.size(), 31); - Assert.assertEquals(dateIntervals.get(0), di1); - Assert.assertEquals(dateIntervals.get(30), di2); + Assertions.assertEquals(dateIntervals.size(), 31); + Assertions.assertEquals(dateIntervals.get(0), di1); + Assertions.assertEquals(dateIntervals.get(30), di2); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/JdbcUrlParserTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/JdbcUrlParserTest.java index 63c3c321fe..9cef208187 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/JdbcUrlParserTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/JdbcUrlParserTest.java @@ -19,8 +19,8 @@ package org.apache.dolphinscheduler.plugin.task.api.utils; import org.apache.dolphinscheduler.plugin.task.api.model.JdbcInfo; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * JdbcUrlParserTest @@ -38,7 +38,7 @@ public class JdbcUrlParserTest { + "driverName='mysql', database='dolphinscheduler', " + "params='useUnicode=true&characterEncoding=UTF-8', " + "address='jdbc:mysql://localhost:3306'}"; - Assert.assertEquals(expected,jdbcInfoStr); + Assertions.assertEquals(expected, jdbcInfoStr); } } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/JsonPathUtilsTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/JsonPathUtilsTest.java index f878beb349..c959121a9a 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/JsonPathUtilsTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/JsonPathUtilsTest.java @@ -19,8 +19,8 @@ package org.apache.dolphinscheduler.plugin.task.api.utils; import java.util.Optional; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class JsonPathUtilsTest { @@ -28,13 +28,13 @@ public class JsonPathUtilsTest { public void read() { String json = "{\"taskInstanceId\":\"123\",\"taskInstanceFinished\":true}"; Optional optionalBoolean = JsonPathUtils.read(json, "$.taskInstanceFinished"); - Assert.assertTrue(optionalBoolean.get()); + Assertions.assertTrue(optionalBoolean.get()); } @Test public void exist() { String json = "{\"taskInstanceId\":\"123\",\"taskInstanceFinished\":true}"; - Assert.assertTrue(JsonPathUtils.exist(json, "$.[?(@.taskInstanceFinished == true)]")); - Assert.assertFalse(JsonPathUtils.exist(json, "$.[?(@.taskInstanceFinished == false)]")); + Assertions.assertTrue(JsonPathUtils.exist(json, "$.[?(@.taskInstanceFinished == true)]")); + Assertions.assertFalse(JsonPathUtils.exist(json, "$.[?(@.taskInstanceFinished == false)]")); } -} \ No newline at end of file +} diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/LogUtilsTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/LogUtilsTest.java index d72a9737bf..df74305daf 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/LogUtilsTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/LogUtilsTest.java @@ -19,8 +19,8 @@ package org.apache.dolphinscheduler.plugin.task.api.utils; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import com.google.common.collect.Lists; @@ -32,6 +32,6 @@ public class LogUtilsTest { @Test public void getAppIdsFromLogFile() { List appIds = LogUtils.getAppIdsFromLogFile(APP_ID_FILE); - Assert.assertEquals(Lists.newArrayList("application_1548381669007_1234"), appIds); + Assertions.assertEquals(Lists.newArrayList("application_1548381669007_1234"), appIds); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/RetryUtilsTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/RetryUtilsTest.java index a3d6d0f9b8..9f402c81c0 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/RetryUtilsTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/RetryUtilsTest.java @@ -19,21 +19,24 @@ package org.apache.dolphinscheduler.plugin.task.api.utils; import java.util.function.Supplier; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class RetryUtilsTest { - @Test(expected = RuntimeException.class) + @Test public void retryFunction() { Boolean retrySuccess = RetryUtils.retryFunction(() -> true); - Assert.assertTrue(retrySuccess); + Assertions.assertTrue(retrySuccess); - RetryUtils.retryFunction((Supplier) () -> { - throw new RuntimeException("Test failed function"); + Assertions.assertThrows(RuntimeException.class, () -> { + RetryUtils.retryFunction((Supplier) () -> { + throw new RuntimeException("Test failed function"); + }); + // make sure RuntimeException thrown + Assertions.fail(); }); - // should throw runtime exception - Assert.fail(); + } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-chunjun/src/test/java/org/apache/dolphinscheduler/plugin/task/chunjun/ChunJunConstantsTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-chunjun/src/test/java/org/apache/dolphinscheduler/plugin/task/chunjun/ChunJunConstantsTest.java index bfdfc60f71..51125a2f75 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-chunjun/src/test/java/org/apache/dolphinscheduler/plugin/task/chunjun/ChunJunConstantsTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-chunjun/src/test/java/org/apache/dolphinscheduler/plugin/task/chunjun/ChunJunConstantsTest.java @@ -17,9 +17,9 @@ package org.apache.dolphinscheduler.plugin.task.chunjun; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ChunJunConstantsTest { @@ -29,7 +29,7 @@ public class ChunJunConstantsTest { private String hadoopConfDir; - @Before + @BeforeEach public void setUp() { flinkConfDir = "${FLINK_HOME}/conf"; flinkLibDir = "${FLINK_HOME}/lib"; @@ -38,9 +38,9 @@ public class ChunJunConstantsTest { @Test public void testEqualsString() { - Assert.assertEquals(ChunJunConstants.FLINK_CONF_DIR, flinkConfDir); - Assert.assertEquals(ChunJunConstants.FLINK_LIB_DIR, flinkLibDir); - Assert.assertEquals(ChunJunConstants.HADOOP_CONF_DIR, hadoopConfDir); + Assertions.assertEquals(ChunJunConstants.FLINK_CONF_DIR, flinkConfDir); + Assertions.assertEquals(ChunJunConstants.FLINK_LIB_DIR, flinkLibDir); + Assertions.assertEquals(ChunJunConstants.HADOOP_CONF_DIR, hadoopConfDir); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-chunjun/src/test/java/org/apache/dolphinscheduler/plugin/task/chunjun/ChunJunParametersTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-chunjun/src/test/java/org/apache/dolphinscheduler/plugin/task/chunjun/ChunJunParametersTest.java index a309e74171..faba030661 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-chunjun/src/test/java/org/apache/dolphinscheduler/plugin/task/chunjun/ChunJunParametersTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-chunjun/src/test/java/org/apache/dolphinscheduler/plugin/task/chunjun/ChunJunParametersTest.java @@ -17,15 +17,15 @@ package org.apache.dolphinscheduler.plugin.task.chunjun; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ChunJunParametersTest { private ChunJunParameters chunJunParameters = new ChunJunParameters(); - @Before + @BeforeEach public void setUp() { chunJunParameters.setCustomConfig(0); chunJunParameters.setDataSource(1); @@ -41,38 +41,38 @@ public class ChunJunParametersTest { public void testToString() { String expected = "ChunJunParameters" - + "{" - + "customConfig=0, " - + "json='json', " - + "dsType='MYSQL', " - + "dataSource=1, " - + "dtType='MYSQL', " - + "dataTarget=1, " - + "sql='null', " - + "targetTable='null', " - + "preStatements=null, " - + "postStatements=null, " - + "jobSpeedByte=1, " - + "jobSpeedRecord=1, " - + "others=xx, " - + "deployMode=local" - + "}"; + + "{" + + "customConfig=0, " + + "json='json', " + + "dsType='MYSQL', " + + "dataSource=1, " + + "dtType='MYSQL', " + + "dataTarget=1, " + + "sql='null', " + + "targetTable='null', " + + "preStatements=null, " + + "postStatements=null, " + + "jobSpeedByte=1, " + + "jobSpeedRecord=1, " + + "others=xx, " + + "deployMode=local" + + "}"; - Assert.assertNotEquals(expected, chunJunParameters.toString()); + Assertions.assertNotEquals(expected, chunJunParameters.toString()); } @Test public void testCheckParameters() { - Assert.assertFalse(chunJunParameters.checkParameters()); + Assertions.assertFalse(chunJunParameters.checkParameters()); } @Test public void testGetResourceFilesList() { - Assert.assertNotNull(chunJunParameters.getResourceFilesList()); + Assertions.assertNotNull(chunJunParameters.getResourceFilesList()); } @Test public void testGetResources() { - Assert.assertNotNull(chunJunParameters.getResources()); + Assertions.assertNotNull(chunJunParameters.getResources()); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/DataQualityParameterTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/DataQualityParameterTest.java index 859f11c4ce..13032160be 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/DataQualityParameterTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/DataQualityParameterTest.java @@ -33,9 +33,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; @@ -48,7 +48,7 @@ public class DataQualityParameterTest { private DataQualityParameters dataQualityParameters = null; - @Before + @BeforeEach public void before() { dataQualityParameters = new DataQualityParameters(); dataQualityParameters.setRuleId(1); @@ -58,24 +58,24 @@ public class DataQualityParameterTest { @Test public void testCheckParameterNormal() { - Map inputParameterValue = new HashMap<>(); - inputParameterValue.put("src_connector_type","JDBC"); - inputParameterValue.put("src_datasource_id","1"); - inputParameterValue.put("src_table","test1"); - inputParameterValue.put("src_filter","date=2012-10-05"); - inputParameterValue.put("src_field","id"); - - inputParameterValue.put("rule_type","1"); - inputParameterValue.put("process_definition_id","1"); - inputParameterValue.put("task_instance_id","1"); - inputParameterValue.put("check_type","1"); - inputParameterValue.put("threshold","1000"); - inputParameterValue.put("create_time","2012-10-05"); - inputParameterValue.put("update_time","2012-10-05"); + Map inputParameterValue = new HashMap<>(); + inputParameterValue.put("src_connector_type", "JDBC"); + inputParameterValue.put("src_datasource_id", "1"); + inputParameterValue.put("src_table", "test1"); + inputParameterValue.put("src_filter", "date=2012-10-05"); + inputParameterValue.put("src_field", "id"); + + inputParameterValue.put("rule_type", "1"); + inputParameterValue.put("process_definition_id", "1"); + inputParameterValue.put("task_instance_id", "1"); + inputParameterValue.put("check_type", "1"); + inputParameterValue.put("threshold", "1000"); + inputParameterValue.put("create_time", "2012-10-05"); + inputParameterValue.put("update_time", "2012-10-05"); dataQualityParameters.setRuleInputParameter(inputParameterValue); - Assert.assertTrue(dataQualityParameters.checkParameters()); + Assertions.assertTrue(dataQualityParameters.checkParameters()); } @Test @@ -96,10 +96,10 @@ public class DataQualityParameterTest { selectParamProps.setDisabled(false); selectParamProps.setSize("small"); - SelectParam srcConnectorType = SelectParam.newBuilder("src_connector_type","源数据类型") + SelectParam srcConnectorType = SelectParam.newBuilder("src_connector_type", "源数据类型") .setProps(selectParamProps) - .addOptions(new ParamsOptions("HIVE","HIVE",false)) - .addOptions(new ParamsOptions("JDBC","JDBC",false)) + .addOptions(new ParamsOptions("HIVE", "HIVE", false)) + .addOptions(new ParamsOptions("JDBC", "JDBC", false)) .setValue("JDBC") .build(); @@ -109,9 +109,10 @@ public class DataQualityParameterTest { inputParamProps.setSize("small"); inputParamProps.setRows(0); - InputParam srcTable = InputParam.newBuilder("src_table","源数据表") + InputParam srcTable = InputParam.newBuilder("src_table", "源数据表") .setProps(inputParamProps) - .addValidate(Validate.newBuilder().setType("string").setRequired(true).setTrigger(TriggerType.BLUR.getTriggerType()).build()) + .addValidate(Validate.newBuilder().setType("string").setRequired(true) + .setTrigger(TriggerType.BLUR.getTriggerType()).build()) .build(); pluginParamsList.add(srcConnectorType); @@ -124,9 +125,9 @@ public class DataQualityParameterTest { try { result = mapper.writeValueAsString(pluginParamsList); } catch (JsonProcessingException e) { - Assert.fail(); + Assertions.fail(); } - Assert.assertEquals(formCreateJson,result); + Assertions.assertEquals(formCreateJson, result); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/DataQualityTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/DataQualityTaskTest.java index 8f483b247a..432bc61916 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/DataQualityTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/DataQualityTaskTest.java @@ -38,8 +38,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * DataQualityTaskTest @@ -96,7 +96,7 @@ public class DataQualityTaskTest { + "as unique_code,'table_count.total'AS statistics_name," + "table_count.total AS statistics_value,'2021-08-12 10:15:48' as data_time,'2021-08-12 10:15:48' as create_time," + "'2021-08-12 10:15:48' as update_time from table_count\"}}]}"; - Assert.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter())); + Assertions.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter())); } private DataQualityTaskExecutionContext getSingleTableContext() { @@ -540,7 +540,7 @@ public class DataQualityTaskTest { + "'2021-08-30 00:00:00' as data_time,'2021-08-30 00:00:00' as create_time,'2021-08-30 00:00:00' " + "as update_time from test_person\"}}]}"; - Assert.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter())); + Assertions.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter())); } @Test @@ -819,7 +819,7 @@ public class DataQualityTaskTest { + "where c1>20 ) tmp2\"}}]}"; RuleManager ruleManager = new RuleManager(inputParameterValue, dataQualityTaskExecutionContext); - Assert.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter())); + Assertions.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter())); } @Test @@ -1171,6 +1171,6 @@ public class DataQualityTaskTest { + "\"config\":{\"path\":\"hdfs://localhost:8022/user/ods/data_quality_error_data/1_1_test\",\"input_table\":\"miss_items\"}}]}"; RuleManager ruleManager = new RuleManager(inputParameterValue, dataQualityTaskExecutionContext); - Assert.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter())); + Assertions.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter())); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/utils/Md5UtilsTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/utils/Md5UtilsTest.java index cf71a05f60..140a080947 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/utils/Md5UtilsTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/utils/Md5UtilsTest.java @@ -17,14 +17,13 @@ package org.apache.dolphinscheduler.plugin.task.dq.utils; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class Md5UtilsTest { @Test public void testGetMd5() { - assertEquals("jZae727K08KaOmKSgOaGzww/XVqGr/PKEgIMkjrcbJI=", Md5Utils.getMd5("123456", false)); + Assertions.assertEquals("jZae727K08KaOmKSgOaGzww/XVqGr/PKEgIMkjrcbJI=", Md5Utils.getMd5("123456", false)); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-datasync/src/test/java/org/apache/dolphinscheduler/plugin/task/datasync/DatasyncTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-datasync/src/test/java/org/apache/dolphinscheduler/plugin/task/datasync/DatasyncTaskTest.java index 0a7ca878a1..06745705e6 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-datasync/src/test/java/org/apache/dolphinscheduler/plugin/task/datasync/DatasyncTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-datasync/src/test/java/org/apache/dolphinscheduler/plugin/task/datasync/DatasyncTaskTest.java @@ -38,16 +38,16 @@ import software.amazon.awssdk.services.datasync.model.StartTaskExecutionResponse import software.amazon.awssdk.services.datasync.model.TaskExecutionStatus; import software.amazon.awssdk.services.datasync.model.TaskStatus; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class DatasyncTaskTest { private static final String mockExeArn = @@ -63,7 +63,7 @@ public class DatasyncTaskTest { @Mock DataSyncClient client; MockedStatic datasyncHookMockedStatic; - @Before + @BeforeEach public void before() throws IllegalAccessException { client = mock(DataSyncClient.class); datasyncHookMockedStatic = mockStatic(DatasyncHook.class); @@ -129,22 +129,22 @@ public class DatasyncTaskTest { DatasyncTask DatasyncTask = initTask(DatasyncParameters); DatasyncParameters datasyncParameters = DatasyncTask.getParameters(); - Assert.assertEquals("arn:aws:logs:ap-northeast-3:523202806641:log-group:/aws/datasync:*", + Assertions.assertEquals("arn:aws:logs:ap-northeast-3:523202806641:log-group:/aws/datasync:*", datasyncParameters.getCloudWatchLogGroupArn()); - Assert.assertEquals("task001", datasyncParameters.getName()); - Assert.assertEquals("arn:aws:datasync:ap-northeast-3:523202806641:location/loc-04ceafb4aaf7a1a0d", + Assertions.assertEquals("task001", datasyncParameters.getName()); + Assertions.assertEquals("arn:aws:datasync:ap-northeast-3:523202806641:location/loc-04ceafb4aaf7a1a0d", datasyncParameters.getSourceLocationArn()); - Assert.assertEquals("arn:aws:datasync:ap-northeast-3:523202806641:location/loc-01cf61e102e58e365", + Assertions.assertEquals("arn:aws:datasync:ap-northeast-3:523202806641:location/loc-01cf61e102e58e365", datasyncParameters.getDestinationLocationArn()); - Assert.assertEquals("inType1", datasyncParameters.getIncludes().get(0).getFilterType()); - Assert.assertEquals("inValue1", datasyncParameters.getIncludes().get(0).getValue()); - Assert.assertEquals("exType1", datasyncParameters.getExcludes().get(0).getFilterType()); - Assert.assertEquals("exValue1", datasyncParameters.getExcludes().get(0).getValue()); - Assert.assertEquals("tagKey1", datasyncParameters.getTags().get(0).getKey()); - Assert.assertEquals("tagValue1", datasyncParameters.getTags().get(0).getValue()); - Assert.assertEquals("* * * * * ?", datasyncParameters.getSchedule().getScheduleExpression()); - Assert.assertEquals("aTime", datasyncParameters.getOptions().getAtime()); - Assert.assertEquals(Long.valueOf(10), datasyncParameters.getOptions().getBytesPerSecond()); + Assertions.assertEquals("inType1", datasyncParameters.getIncludes().get(0).getFilterType()); + Assertions.assertEquals("inValue1", datasyncParameters.getIncludes().get(0).getValue()); + Assertions.assertEquals("exType1", datasyncParameters.getExcludes().get(0).getFilterType()); + Assertions.assertEquals("exValue1", datasyncParameters.getExcludes().get(0).getValue()); + Assertions.assertEquals("tagKey1", datasyncParameters.getTags().get(0).getKey()); + Assertions.assertEquals("tagValue1", datasyncParameters.getTags().get(0).getValue()); + Assertions.assertEquals("* * * * * ?", datasyncParameters.getSchedule().getScheduleExpression()); + Assertions.assertEquals("aTime", datasyncParameters.getOptions().getAtime()); + Assertions.assertEquals(Long.valueOf(10), datasyncParameters.getOptions().getBytesPerSecond()); datasyncHookMockedStatic.close(); } @@ -160,7 +160,7 @@ public class DatasyncTaskTest { doReturn(true).when(hook).doubleCheckTaskStatus(any(), any()); hook.createDatasyncTask(datasyncTask.getParameters()); - Assert.assertEquals(mockTaskArn, hook.getTaskArn()); + Assertions.assertEquals(mockTaskArn, hook.getTaskArn()); datasyncHookMockedStatic.close(); } @@ -175,7 +175,7 @@ public class DatasyncTaskTest { when(response.taskExecutionArn()).thenReturn(mockExeArn); doReturn(true).when(hook).doubleCheckExecStatus(any(), any()); hook.startDatasyncTask(); - Assert.assertEquals(mockExeArn, hook.getTaskExecArn()); + Assertions.assertEquals(mockExeArn, hook.getTaskExecArn()); datasyncHookMockedStatic.close(); } @@ -187,7 +187,7 @@ public class DatasyncTaskTest { SdkHttpResponse sdkMock = mock(SdkHttpResponse.class); when(response.sdkHttpResponse()).thenReturn(sdkMock); when(sdkMock.isSuccessful()).thenReturn(true); - Assert.assertEquals(true, hook.cancelDatasyncTask()); + Assertions.assertEquals(true, hook.cancelDatasyncTask()); datasyncHookMockedStatic.close(); } @@ -195,10 +195,10 @@ public class DatasyncTaskTest { public void testDescribeTask() { DatasyncHook hook = spy(new DatasyncHook()); doReturn(null).when(hook).queryDatasyncTaskStatus(); - Assert.assertEquals(false, hook.doubleCheckTaskStatus(TaskStatus.AVAILABLE, DatasyncHook.taskFinishFlags)); + Assertions.assertEquals(false, hook.doubleCheckTaskStatus(TaskStatus.AVAILABLE, DatasyncHook.taskFinishFlags)); doReturn(TaskStatus.AVAILABLE).when(hook).queryDatasyncTaskStatus(); - Assert.assertEquals(true, hook.doubleCheckTaskStatus(TaskStatus.AVAILABLE, DatasyncHook.taskFinishFlags)); + Assertions.assertEquals(true, hook.doubleCheckTaskStatus(TaskStatus.AVAILABLE, DatasyncHook.taskFinishFlags)); datasyncHookMockedStatic.close(); } @@ -206,10 +206,11 @@ public class DatasyncTaskTest { public void testDescribeTaskExec() { DatasyncHook hook = spy(new DatasyncHook()); doReturn(null).when(hook).queryDatasyncTaskExecStatus(); - Assert.assertEquals(false, hook.doubleCheckExecStatus(TaskExecutionStatus.SUCCESS, DatasyncHook.doneStatus)); + Assertions.assertEquals(false, + hook.doubleCheckExecStatus(TaskExecutionStatus.SUCCESS, DatasyncHook.doneStatus)); doReturn(TaskExecutionStatus.SUCCESS).when(hook).queryDatasyncTaskExecStatus(); - Assert.assertEquals(true, hook.doubleCheckExecStatus(TaskExecutionStatus.SUCCESS, DatasyncHook.doneStatus)); + Assertions.assertEquals(true, hook.doubleCheckExecStatus(TaskExecutionStatus.SUCCESS, DatasyncHook.doneStatus)); datasyncHookMockedStatic.close(); } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/test/java/org/apache/dolphinscheduler/plugin/task/datax/DataxParametersTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/test/java/org/apache/dolphinscheduler/plugin/task/datax/DataxParametersTest.java index c7d317005e..79792f491c 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/test/java/org/apache/dolphinscheduler/plugin/task/datax/DataxParametersTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/test/java/org/apache/dolphinscheduler/plugin/task/datax/DataxParametersTest.java @@ -18,12 +18,13 @@ package org.apache.dolphinscheduler.plugin.task.datax; import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo; -import org.junit.Assert; -import org.junit.Test; import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + public class DataxParametersTest { /** @@ -32,27 +33,27 @@ public class DataxParametersTest { public static final String JVM_PARAM = " --jvm=\"-Xms%sG -Xmx%sG\" "; @Test - public void testLoadJvmEnv() { + public void testLoadJvmEnv() { DataxParameters dataxParameters = new DataxParameters(); dataxParameters.setXms(0); dataxParameters.setXmx(-100); - String actual = loadJvmEnvTest(dataxParameters); + String actual = loadJvmEnvTest(dataxParameters); String except = " --jvm=\"-Xms1G -Xmx1G\" "; - Assert.assertEquals(except,actual); + Assertions.assertEquals(except, actual); dataxParameters.setXms(13); dataxParameters.setXmx(14); - actual = loadJvmEnvTest(dataxParameters); + actual = loadJvmEnvTest(dataxParameters); except = " --jvm=\"-Xms13G -Xmx14G\" "; - Assert.assertEquals(except,actual); + Assertions.assertEquals(except, actual); } @Test - public void testToString() { + public void testToString() { DataxParameters dataxParameters = new DataxParameters(); List resourceInfoList = new ArrayList<>(); @@ -92,7 +93,7 @@ public class DataxParametersTest { + "resourceList=[{\"id\":2,\"resourceName\":\"/hdfs.keytab\",\"res\":null}]" + "}"; - Assert.assertEquals(expected,dataxParameters.toString()); + Assertions.assertEquals(expected, dataxParameters.toString()); } public String loadJvmEnvTest(DataxParameters dataXParameters) { diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-dms/src/test/java/org/apache/dolphinscheduler/plugin/task/dms/DmsHookTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-dms/src/test/java/org/apache/dolphinscheduler/plugin/task/dms/DmsHookTest.java index ec81dbd157..a2f2ed3efe 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-dms/src/test/java/org/apache/dolphinscheduler/plugin/task/dms/DmsHookTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-dms/src/test/java/org/apache/dolphinscheduler/plugin/task/dms/DmsHookTest.java @@ -23,15 +23,16 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; +import java.time.Duration; import java.util.Arrays; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.MockedStatic; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import com.amazonaws.services.databasemigrationservice.AWSDatabaseMigrationService; import com.amazonaws.services.databasemigrationservice.model.CreateReplicationTaskResult; @@ -40,92 +41,99 @@ import com.amazonaws.services.databasemigrationservice.model.ReplicationTask; import com.amazonaws.services.databasemigrationservice.model.ReplicationTaskStats; import com.amazonaws.services.databasemigrationservice.model.StartReplicationTaskResult; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class DmsHookTest { final String replicationTaskArn = "arn:aws:dms:ap-southeast-1:123456789012:task:task"; AWSDatabaseMigrationService client; - @Before + @BeforeEach public void before() { client = mock(AWSDatabaseMigrationService.class); } - @Test(timeout = 60000) + @Test public void testCreateReplicationTask() throws Exception { try (MockedStatic mockHook = Mockito.mockStatic(DmsHook.class)) { - mockHook.when(DmsHook::createClient).thenReturn(client); - - DmsHook dmsHook = spy(new DmsHook()); - CreateReplicationTaskResult createReplicationTaskResult = mock(CreateReplicationTaskResult.class); - when(client.createReplicationTask(any())).thenReturn(createReplicationTaskResult); - - ReplicationTask replicationTask = mock(ReplicationTask.class); - final String taskIdentifier = "task"; - when(replicationTask.getReplicationTaskArn()).thenReturn(replicationTaskArn); - when(replicationTask.getReplicationTaskIdentifier()).thenReturn(taskIdentifier); - when(replicationTask.getStatus()).thenReturn(DmsHook.STATUS.READY); - when(createReplicationTaskResult.getReplicationTask()).thenReturn(replicationTask); - - doReturn(replicationTask).when(dmsHook).describeReplicationTasks(); - Assert.assertTrue(dmsHook.createReplicationTask()); - Assert.assertEquals(replicationTaskArn, dmsHook.getReplicationTaskArn()); - Assert.assertEquals(taskIdentifier, dmsHook.getReplicationTaskIdentifier()); + Assertions.assertTimeout(Duration.ofMillis(60000), () -> { + mockHook.when(DmsHook::createClient).thenReturn(client); + + DmsHook dmsHook = spy(new DmsHook()); + CreateReplicationTaskResult createReplicationTaskResult = mock(CreateReplicationTaskResult.class); + when(client.createReplicationTask(any())).thenReturn(createReplicationTaskResult); + + ReplicationTask replicationTask = mock(ReplicationTask.class); + final String taskIdentifier = "task"; + when(replicationTask.getReplicationTaskArn()).thenReturn(replicationTaskArn); + when(replicationTask.getReplicationTaskIdentifier()).thenReturn(taskIdentifier); + when(replicationTask.getStatus()).thenReturn(DmsHook.STATUS.READY); + when(createReplicationTaskResult.getReplicationTask()).thenReturn(replicationTask); + + doReturn(replicationTask).when(dmsHook).describeReplicationTasks(); + Assertions.assertTrue(dmsHook.createReplicationTask()); + Assertions.assertEquals(replicationTaskArn, dmsHook.getReplicationTaskArn()); + Assertions.assertEquals(taskIdentifier, dmsHook.getReplicationTaskIdentifier()); + }); } } - @Test(timeout = 60000) + @Test public void testStartReplicationTask() { - try (MockedStatic mockHook = Mockito.mockStatic(DmsHook.class)) { - mockHook.when(DmsHook::createClient).thenReturn(client); - - DmsHook dmsHook = spy(new DmsHook()); - StartReplicationTaskResult startReplicationTaskResult = mock(StartReplicationTaskResult.class); - when(client.startReplicationTask(any())).thenReturn(startReplicationTaskResult); - - ReplicationTask replicationTask = mock(ReplicationTask.class); - when(replicationTask.getReplicationTaskArn()).thenReturn(replicationTaskArn); - when(replicationTask.getStatus()).thenReturn(DmsHook.STATUS.RUNNING); - when(startReplicationTaskResult.getReplicationTask()).thenReturn(replicationTask); - - doReturn(replicationTask).when(dmsHook).describeReplicationTasks(); - Assert.assertTrue(dmsHook.startReplicationTask()); - Assert.assertEquals(replicationTaskArn, dmsHook.getReplicationTaskArn()); - } + Assertions.assertTimeout(Duration.ofMillis(60000), () -> { + try (MockedStatic mockHook = Mockito.mockStatic(DmsHook.class)) { + mockHook.when(DmsHook::createClient).thenReturn(client); + + DmsHook dmsHook = spy(new DmsHook()); + StartReplicationTaskResult startReplicationTaskResult = mock(StartReplicationTaskResult.class); + when(client.startReplicationTask(any())).thenReturn(startReplicationTaskResult); + + ReplicationTask replicationTask = mock(ReplicationTask.class); + when(replicationTask.getReplicationTaskArn()).thenReturn(replicationTaskArn); + when(replicationTask.getStatus()).thenReturn(DmsHook.STATUS.RUNNING); + when(startReplicationTaskResult.getReplicationTask()).thenReturn(replicationTask); + + doReturn(replicationTask).when(dmsHook).describeReplicationTasks(); + Assertions.assertTrue(dmsHook.startReplicationTask()); + Assertions.assertEquals(replicationTaskArn, dmsHook.getReplicationTaskArn()); + } + }); } - @Test(timeout = 60000) + @Test public void testCheckFinishedReplicationTask() { - try (MockedStatic mockHook = Mockito.mockStatic(DmsHook.class)) { - mockHook.when(DmsHook::createClient).thenReturn(client); - DmsHook dmsHook = spy(new DmsHook()); + Assertions.assertTimeout(Duration.ofMillis(60000), () -> { + try (MockedStatic mockHook = Mockito.mockStatic(DmsHook.class)) { + mockHook.when(DmsHook::createClient).thenReturn(client); + DmsHook dmsHook = spy(new DmsHook()); - ReplicationTask replicationTask = mock(ReplicationTask.class); - when(replicationTask.getStatus()).thenReturn(DmsHook.STATUS.STOPPED); + ReplicationTask replicationTask = mock(ReplicationTask.class); + when(replicationTask.getStatus()).thenReturn(DmsHook.STATUS.STOPPED); - doReturn(replicationTask).when(dmsHook).describeReplicationTasks(); + doReturn(replicationTask).when(dmsHook).describeReplicationTasks(); - when(replicationTask.getStopReason()).thenReturn("*_FINISHED"); - Assert.assertTrue(dmsHook.checkFinishedReplicationTask()); + when(replicationTask.getStopReason()).thenReturn("*_FINISHED"); + Assertions.assertTrue(dmsHook.checkFinishedReplicationTask()); - when(replicationTask.getStopReason()).thenReturn("*_ERROR"); - Assert.assertFalse(dmsHook.checkFinishedReplicationTask()); - } + when(replicationTask.getStopReason()).thenReturn("*_ERROR"); + Assertions.assertFalse(dmsHook.checkFinishedReplicationTask()); + } + }); } - @Test(timeout = 60000) + @Test public void testDeleteReplicationTask() { - try (MockedStatic mockHook = Mockito.mockStatic(DmsHook.class)) { - mockHook.when(DmsHook::createClient).thenReturn(client); - - DmsHook dmsHook = spy(new DmsHook()); - - ReplicationTask replicationTask = mock(ReplicationTask.class); - when(replicationTask.getStatus()).thenReturn(DmsHook.STATUS.DELETE); - doReturn(replicationTask).when(dmsHook).describeReplicationTasks(); - Assert.assertTrue(dmsHook.deleteReplicationTask()); - } - + Assertions.assertTimeout(Duration.ofMillis(60000), () -> { + try (MockedStatic mockHook = Mockito.mockStatic(DmsHook.class)) { + mockHook.when(DmsHook::createClient).thenReturn(client); + + DmsHook dmsHook = spy(new DmsHook()); + + ReplicationTask replicationTask = mock(ReplicationTask.class); + when(replicationTask.getStatus()).thenReturn(DmsHook.STATUS.DELETE); + doReturn(replicationTask).when(dmsHook).describeReplicationTasks(); + Assertions.assertTrue(dmsHook.deleteReplicationTask()); + } + }); } @Test @@ -145,29 +153,27 @@ public class DmsHookTest { doReturn(false).when(dmsHook).testConnection(replicationInstanceArn, falseSourceEndpointArn); doReturn(false).when(dmsHook).testConnection(replicationInstanceArn, falseTargetEndpointArn); - dmsHook.setReplicationInstanceArn(replicationInstanceArn); dmsHook.setSourceEndpointArn(trueSourceEndpointArn); dmsHook.setTargetEndpointArn(trueTargetEndpointArn); - Assert.assertTrue(dmsHook.testConnectionEndpoint()); + Assertions.assertTrue(dmsHook.testConnectionEndpoint()); dmsHook.setSourceEndpointArn(falseSourceEndpointArn); dmsHook.setTargetEndpointArn(falseTargetEndpointArn); - Assert.assertFalse(dmsHook.testConnectionEndpoint()); + Assertions.assertFalse(dmsHook.testConnectionEndpoint()); dmsHook.setSourceEndpointArn(trueSourceEndpointArn); dmsHook.setTargetEndpointArn(falseTargetEndpointArn); - Assert.assertFalse(dmsHook.testConnectionEndpoint()); + Assertions.assertFalse(dmsHook.testConnectionEndpoint()); dmsHook.setSourceEndpointArn(falseSourceEndpointArn); dmsHook.setTargetEndpointArn(trueTargetEndpointArn); - Assert.assertFalse(dmsHook.testConnectionEndpoint()); + Assertions.assertFalse(dmsHook.testConnectionEndpoint()); } } - @Test public void testDescribeReplicationTasks() { try (MockedStatic mockHook = Mockito.mockStatic(DmsHook.class)) { @@ -180,7 +186,8 @@ public class DmsHookTest { when(client.describeReplicationTasks(any())).thenReturn(describeReplicationTasksResult); ReplicationTask replicationTask = mock(ReplicationTask.class); - when(replicationTask.getReplicationTaskArn()).thenReturn("arn:aws:dms:ap-southeast-1:123456789012:task:task"); + when(replicationTask.getReplicationTaskArn()) + .thenReturn("arn:aws:dms:ap-southeast-1:123456789012:task:task"); when(replicationTask.getReplicationTaskIdentifier()).thenReturn("task"); final String sourceArn = "arn:aws:dms:ap-southeast-1:123456789012:endpoint:source"; @@ -192,46 +199,43 @@ public class DmsHookTest { when(describeReplicationTasksResult.getReplicationTasks()).thenReturn(Arrays.asList(replicationTask)); ReplicationTask replicationTaskOut = dmsHook.describeReplicationTasks(); - Assert.assertNotEquals(dmsHook.getReplicationInstanceArn(), replicationTaskOut.getReplicationTaskArn()); - Assert.assertEquals("task", replicationTaskOut.getReplicationTaskIdentifier()); - Assert.assertEquals(sourceArn, replicationTaskOut.getSourceEndpointArn()); - Assert.assertEquals(targetArn, replicationTaskOut.getTargetEndpointArn()); + Assertions.assertNotEquals(dmsHook.getReplicationInstanceArn(), replicationTaskOut.getReplicationTaskArn()); + Assertions.assertEquals("task", replicationTaskOut.getReplicationTaskIdentifier()); + Assertions.assertEquals(sourceArn, replicationTaskOut.getSourceEndpointArn()); + Assertions.assertEquals(targetArn, replicationTaskOut.getTargetEndpointArn()); } } - - @Test(timeout = 60000) + @Test public void testAwaitReplicationTaskStatus() { - try (MockedStatic mockHook = Mockito.mockStatic(DmsHook.class)) { - mockHook.when(DmsHook::createClient).thenReturn(client); - DmsHook dmsHook = spy(new DmsHook()); - - ReplicationTask replicationTask = mock(ReplicationTask.class); - doReturn(replicationTask).when(dmsHook).describeReplicationTasks(); - - ReplicationTaskStats taskStats = mock(ReplicationTaskStats.class); - when(replicationTask.getReplicationTaskStats()).thenReturn(taskStats); - when(taskStats.getFullLoadProgressPercent()).thenReturn(100); - - when(replicationTask.getStatus()).thenReturn( - DmsHook.STATUS.STOPPED - ); - Assert.assertTrue(dmsHook.awaitReplicationTaskStatus(DmsHook.STATUS.STOPPED)); - - when(replicationTask.getStatus()).thenReturn( - DmsHook.STATUS.RUNNING, - DmsHook.STATUS.STOPPED - ); - Assert.assertTrue(dmsHook.awaitReplicationTaskStatus(DmsHook.STATUS.STOPPED)); - - when(replicationTask.getStatus()).thenReturn( - DmsHook.STATUS.RUNNING, - DmsHook.STATUS.STOPPED - ); - Assert.assertFalse(dmsHook.awaitReplicationTaskStatus(DmsHook.STATUS.STOPPED, DmsHook.STATUS.RUNNING)); - } + Assertions.assertTimeout(Duration.ofMillis(60000), () -> { + try (MockedStatic mockHook = Mockito.mockStatic(DmsHook.class)) { + mockHook.when(DmsHook::createClient).thenReturn(client); + DmsHook dmsHook = spy(new DmsHook()); + + ReplicationTask replicationTask = mock(ReplicationTask.class); + doReturn(replicationTask).when(dmsHook).describeReplicationTasks(); + + ReplicationTaskStats taskStats = mock(ReplicationTaskStats.class); + when(replicationTask.getReplicationTaskStats()).thenReturn(taskStats); + when(taskStats.getFullLoadProgressPercent()).thenReturn(100); + + when(replicationTask.getStatus()).thenReturn( + DmsHook.STATUS.STOPPED); + Assertions.assertTrue(dmsHook.awaitReplicationTaskStatus(DmsHook.STATUS.STOPPED)); + + when(replicationTask.getStatus()).thenReturn( + DmsHook.STATUS.RUNNING, + DmsHook.STATUS.STOPPED); + Assertions.assertTrue(dmsHook.awaitReplicationTaskStatus(DmsHook.STATUS.STOPPED)); + + when(replicationTask.getStatus()).thenReturn( + DmsHook.STATUS.RUNNING, + DmsHook.STATUS.STOPPED); + Assertions.assertFalse( + dmsHook.awaitReplicationTaskStatus(DmsHook.STATUS.STOPPED, DmsHook.STATUS.RUNNING)); + } + }); } } - - diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-dms/src/test/java/org/apache/dolphinscheduler/plugin/task/dms/DmsTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-dms/src/test/java/org/apache/dolphinscheduler/plugin/task/dms/DmsTaskTest.java index 1c74f8ae2f..031f03c53c 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-dms/src/test/java/org/apache/dolphinscheduler/plugin/task/dms/DmsTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-dms/src/test/java/org/apache/dolphinscheduler/plugin/task/dms/DmsTaskTest.java @@ -26,18 +26,18 @@ import org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.lang.reflect.Field; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import com.amazonaws.services.databasemigrationservice.model.InvalidResourceStateException; import com.amazonaws.services.databasemigrationservice.model.ReplicationTask; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class DmsTaskTest { @Mock @@ -45,7 +45,7 @@ public class DmsTaskTest { DmsTask dmsTask; - @Before + @BeforeEach public void before() throws Exception { DmsParameters dmsParameters = new DmsParameters(); dmsTask = initTask(dmsParameters); @@ -56,20 +56,21 @@ public class DmsTaskTest { @Test public void testCreateTaskJson() { String jsonData = "{\n" + - " \"ReplicationTaskIdentifier\":\"task6\",\n" + - " \"SourceEndpointArn\":\"arn:aws:dms:ap-southeast-1:511640773671:endpoint:Z7SUEAL273SCT7OCPYNF5YNDHJDDFRATGNQISOQ\",\n" + - " \"TargetEndpointArn\":\"arn:aws:dms:ap-southeast-1:511640773671:endpoint:aws-mysql57-target\",\n" + - " \"ReplicationInstanceArn\":\"arn:aws:dms:ap-southeast-1:511640773671:rep:dms2c2g\",\n" + - " \"MigrationType\":\"full-load\",\n" + - " \"TableMappings\":\"file://table-mapping.json\",\n" + - " \"ReplicationTaskSettings\":\"file://ReplicationTaskSettings.json\",\n" + - " \"Tags\":[\n" + - " {\n" + - " \"Key\":\"key1\",\n" + - " \"Value\":\"value1\"\n" + - " }\n" + - " ]\n" + - "}"; + " \"ReplicationTaskIdentifier\":\"task6\",\n" + + " \"SourceEndpointArn\":\"arn:aws:dms:ap-southeast-1:511640773671:endpoint:Z7SUEAL273SCT7OCPYNF5YNDHJDDFRATGNQISOQ\",\n" + + + " \"TargetEndpointArn\":\"arn:aws:dms:ap-southeast-1:511640773671:endpoint:aws-mysql57-target\",\n" + + " \"ReplicationInstanceArn\":\"arn:aws:dms:ap-southeast-1:511640773671:rep:dms2c2g\",\n" + + " \"MigrationType\":\"full-load\",\n" + + " \"TableMappings\":\"file://table-mapping.json\",\n" + + " \"ReplicationTaskSettings\":\"file://ReplicationTaskSettings.json\",\n" + + " \"Tags\":[\n" + + " {\n" + + " \"Key\":\"key1\",\n" + + " \"Value\":\"value1\"\n" + + " }\n" + + " ]\n" + + "}"; DmsParameters dmsParameters = new DmsParameters(); dmsParameters.setIsJsonFormat(true); @@ -78,42 +79,45 @@ public class DmsTaskTest { DmsTask dmsTask = initTask(dmsParameters); dmsTask.convertJsonParameters(); DmsParameters dmsParametersNew = dmsTask.getParameters(); - Assert.assertEquals("task6", dmsParametersNew.getReplicationTaskIdentifier()); - Assert.assertEquals("arn:aws:dms:ap-southeast-1:511640773671:endpoint:Z7SUEAL273SCT7OCPYNF5YNDHJDDFRATGNQISOQ", dmsParametersNew.getSourceEndpointArn()); - Assert.assertEquals("arn:aws:dms:ap-southeast-1:511640773671:endpoint:aws-mysql57-target", dmsParametersNew.getTargetEndpointArn()); - Assert.assertEquals("arn:aws:dms:ap-southeast-1:511640773671:rep:dms2c2g", dmsParametersNew.getReplicationInstanceArn()); - Assert.assertEquals("full-load", dmsParametersNew.getMigrationType()); - Assert.assertEquals("file://table-mapping.json", dmsParametersNew.getTableMappings()); - Assert.assertEquals("file://ReplicationTaskSettings.json", dmsParametersNew.getReplicationTaskSettings()); - Assert.assertEquals("key1", dmsParametersNew.getTags().get(0).getKey()); - Assert.assertEquals("value1", dmsParametersNew.getTags().get(0).getValue()); + Assertions.assertEquals("task6", dmsParametersNew.getReplicationTaskIdentifier()); + Assertions.assertEquals( + "arn:aws:dms:ap-southeast-1:511640773671:endpoint:Z7SUEAL273SCT7OCPYNF5YNDHJDDFRATGNQISOQ", + dmsParametersNew.getSourceEndpointArn()); + Assertions.assertEquals("arn:aws:dms:ap-southeast-1:511640773671:endpoint:aws-mysql57-target", + dmsParametersNew.getTargetEndpointArn()); + Assertions.assertEquals("arn:aws:dms:ap-southeast-1:511640773671:rep:dms2c2g", + dmsParametersNew.getReplicationInstanceArn()); + Assertions.assertEquals("full-load", dmsParametersNew.getMigrationType()); + Assertions.assertEquals("file://table-mapping.json", dmsParametersNew.getTableMappings()); + Assertions.assertEquals("file://ReplicationTaskSettings.json", dmsParametersNew.getReplicationTaskSettings()); + Assertions.assertEquals("key1", dmsParametersNew.getTags().get(0).getKey()); + Assertions.assertEquals("value1", dmsParametersNew.getTags().get(0).getValue()); } @Test public void testCheckCreateReplicationTask() throws Exception { - DmsParameters dmsParameters = dmsTask.getParameters(); dmsParameters.setIsRestartTask(true); - Assert.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.checkCreateReplicationTask()); + Assertions.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.checkCreateReplicationTask()); dmsParameters.setIsRestartTask(false); when(dmsHook.createReplicationTask()).thenReturn(true); - Assert.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.checkCreateReplicationTask()); + Assertions.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.checkCreateReplicationTask()); when(dmsHook.createReplicationTask()).thenReturn(false); dmsTask.checkCreateReplicationTask(); - Assert.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.checkCreateReplicationTask()); + Assertions.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.checkCreateReplicationTask()); } @Test public void testStartReplicationTask() { when(dmsHook.startReplicationTask()).thenReturn(true); - Assert.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.startReplicationTask()); + Assertions.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.startReplicationTask()); when(dmsHook.startReplicationTask()).thenReturn(false); - Assert.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.startReplicationTask()); + Assertions.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.startReplicationTask()); } @Test @@ -123,25 +127,23 @@ public class DmsTaskTest { parameters.setIsRestartTask(false); when(dmsHook.testConnectionEndpoint()).thenReturn(true); when(dmsHook.startReplicationTask()) - .thenThrow(new InvalidResourceStateException("Test connection")) - .thenReturn(true); - Assert.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.startReplicationTask()); - + .thenThrow(new InvalidResourceStateException("Test connection")) + .thenReturn(true); + Assertions.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.startReplicationTask()); when(dmsHook.startReplicationTask()) - .thenThrow(new InvalidResourceStateException("Test connection")) - .thenReturn(false); - Assert.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.startReplicationTask()); + .thenThrow(new InvalidResourceStateException("Test connection")) + .thenReturn(false); + Assertions.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.startReplicationTask()); } - @Test public void testStartReplicationTaskRestartOtherException() { DmsParameters parameters = dmsTask.getParameters(); parameters.setIsRestartTask(false); when(dmsHook.startReplicationTask()).thenThrow(new InvalidResourceStateException("other error")); - Assert.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.startReplicationTask()); + Assertions.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.startReplicationTask()); } @Test @@ -154,22 +156,21 @@ public class DmsTaskTest { when(replicationTask.getMigrationType()).thenReturn("cdc"); parameters.setCdcStopPosition("now"); - Assert.assertFalse(dmsTask.isStopTaskWhenCdc()); + Assertions.assertFalse(dmsTask.isStopTaskWhenCdc()); when(replicationTask.getMigrationType()).thenReturn("full-load-and-cdc"); parameters.setCdcStopPosition("now"); - Assert.assertFalse(dmsTask.isStopTaskWhenCdc()); + Assertions.assertFalse(dmsTask.isStopTaskWhenCdc()); when(replicationTask.getMigrationType()).thenReturn("full-load-and-cdc"); parameters.setCdcStopPosition(null); - Assert.assertTrue(dmsTask.isStopTaskWhenCdc()); + Assertions.assertTrue(dmsTask.isStopTaskWhenCdc()); when(replicationTask.getMigrationType()).thenReturn("full-load"); parameters.setCdcStopPosition(null); - Assert.assertFalse(dmsTask.isStopTaskWhenCdc()); + Assertions.assertFalse(dmsTask.isStopTaskWhenCdc()); } - private DmsTask initTask(DmsParameters dmsParameters) { TaskExecutionContext taskExecutionContext = createContext(dmsParameters); DmsTask dmsTask = new DmsTask(taskExecutionContext); @@ -184,5 +185,3 @@ public class DmsTaskTest { return taskExecutionContext; } } - - diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-dvc/src/test/java/org/apache/dolphinscheduler/plugin/task/dvc/DvcTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-dvc/src/test/java/org/apache/dolphinscheduler/plugin/task/dvc/DvcTaskTest.java index fd6b026648..415fe49254 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-dvc/src/test/java/org/apache/dolphinscheduler/plugin/task/dvc/DvcTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-dvc/src/test/java/org/apache/dolphinscheduler/plugin/task/dvc/DvcTaskTest.java @@ -21,14 +21,13 @@ import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContextCacheManager; import org.apache.dolphinscheduler.spi.utils.JSONUtils; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; - -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class DvcTaskTest { public TaskExecutionContext createContext(DvcParameters dvcParameters) { @@ -52,42 +51,45 @@ public class DvcTaskTest { @Test public void testDvcUpload() throws Exception { DvcTask dvcTask = initTask(createUploadParameters()); - Assert.assertEquals(dvcTask.buildCommand(), - "which dvc || { echo \"dvc does not exist\"; exit 1; }; DVC_REPO=git@github.com:/dvc-data-repository-example\n" + - "DVC_DATA_PATH=/home//test\n" + - "DVC_DATA_LOCATION=test\n" + - "DVC_VERSION=iris_v2.3.1\n" + - "DVC_MESSAGE=\"add test iris data\"\n" + - "git clone $DVC_REPO dvc-repository; cd dvc-repository; pwd\n" + - "dvc config core.autostage true --local || exit 1\n" + - "dvc add $DVC_DATA_PATH -v -o $DVC_DATA_LOCATION --to-remote || exit 1\n" + - "git commit -am \"$DVC_MESSAGE\"\n" + - "git tag \"$DVC_VERSION\" -m \"$DVC_MESSAGE\"\n" + - "git push --all\n" + - "git push --tags"); + Assertions.assertEquals(dvcTask.buildCommand(), + "which dvc || { echo \"dvc does not exist\"; exit 1; }; DVC_REPO=git@github.com:/dvc-data-repository-example\n" + + + "DVC_DATA_PATH=/home//test\n" + + "DVC_DATA_LOCATION=test\n" + + "DVC_VERSION=iris_v2.3.1\n" + + "DVC_MESSAGE=\"add test iris data\"\n" + + "git clone $DVC_REPO dvc-repository; cd dvc-repository; pwd\n" + + "dvc config core.autostage true --local || exit 1\n" + + "dvc add $DVC_DATA_PATH -v -o $DVC_DATA_LOCATION --to-remote || exit 1\n" + + "git commit -am \"$DVC_MESSAGE\"\n" + + "git tag \"$DVC_VERSION\" -m \"$DVC_MESSAGE\"\n" + + "git push --all\n" + + "git push --tags"); } @Test public void testDvcDownload() throws Exception { DvcTask dvcTask = initTask(createDownloadParameters()); - Assert.assertEquals(dvcTask.buildCommand(), - "which dvc || { echo \"dvc does not exist\"; exit 1; }; DVC_REPO=git@github.com:/dvc-data-repository-example\n" + - "DVC_DATA_PATH=data\n" + - "DVC_DATA_LOCATION=iris\n" + - "DVC_VERSION=iris_v2.3.1\n" + - "dvc get $DVC_REPO $DVC_DATA_LOCATION -o $DVC_DATA_PATH -v --rev $DVC_VERSION"); + Assertions.assertEquals(dvcTask.buildCommand(), + "which dvc || { echo \"dvc does not exist\"; exit 1; }; DVC_REPO=git@github.com:/dvc-data-repository-example\n" + + + "DVC_DATA_PATH=data\n" + + "DVC_DATA_LOCATION=iris\n" + + "DVC_VERSION=iris_v2.3.1\n" + + "dvc get $DVC_REPO $DVC_DATA_LOCATION -o $DVC_DATA_PATH -v --rev $DVC_VERSION"); } @Test public void testInitDvc() throws Exception { DvcTask dvcTask = initTask(createInitDvcParameters()); - Assert.assertEquals(dvcTask.buildCommand(), - "which dvc || { echo \"dvc does not exist\"; exit 1; }; DVC_REPO=git@github.com:/dvc-data-repository-example\n" + - "git clone $DVC_REPO dvc-repository; cd dvc-repository; pwd\n" + - "dvc init || exit 1\n" + - "dvc remote add origin ~/.dvc_test -d\n" + - "git commit -am \"init dvc project and add remote\"; git push"); + Assertions.assertEquals(dvcTask.buildCommand(), + "which dvc || { echo \"dvc does not exist\"; exit 1; }; DVC_REPO=git@github.com:/dvc-data-repository-example\n" + + + "git clone $DVC_REPO dvc-repository; cd dvc-repository; pwd\n" + + "dvc init || exit 1\n" + + "dvc remote add origin ~/.dvc_test -d\n" + + "git commit -am \"init dvc project and add remote\"; git push"); } private DvcParameters createUploadParameters() { @@ -118,4 +120,4 @@ public class DvcTaskTest { parameters.setDvcStoreUrl("~/.dvc_test"); return parameters; } -} \ No newline at end of file +} diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrAddStepsTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrAddStepsTaskTest.java index c4bf29459e..8a7bddee65 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrAddStepsTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrAddStepsTaskTest.java @@ -33,12 +33,12 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Collections; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduce; import com.amazonaws.services.elasticmapreduce.model.AddJobFlowStepsResult; @@ -53,23 +53,23 @@ import com.amazonaws.services.elasticmapreduce.model.StepStatus; * * @since v3.1.0 */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class EmrAddStepsTaskTest { private final StepStatus pendingState = - new StepStatus().withState(StepState.PENDING); + new StepStatus().withState(StepState.PENDING); private final StepStatus runningState = - new StepStatus().withState(StepState.RUNNING); + new StepStatus().withState(StepState.RUNNING); private final StepStatus completedState = - new StepStatus().withState(StepState.COMPLETED); + new StepStatus().withState(StepState.COMPLETED); private final StepStatus cancelledState = - new StepStatus().withState(StepState.CANCELLED); + new StepStatus().withState(StepState.CANCELLED); private final StepStatus failedState = - new StepStatus().withState(StepState.FAILED); + new StepStatus().withState(StepState.FAILED); private EmrAddStepsTask emrAddStepsTask; private AmazonElasticMapReduce emrClient; @@ -78,7 +78,7 @@ public class EmrAddStepsTaskTest { }; - @Before + @BeforeEach public void before() throws Exception { // mock EmrParameters and EmrAddStepsTask EmrParameters emrParameters = buildEmrTaskParameters(); @@ -91,27 +91,30 @@ public class EmrAddStepsTaskTest { emrClient = Mockito.mock(AmazonElasticMapReduce.class); AddJobFlowStepsResult addJobFlowStepsResult = Mockito.mock(AddJobFlowStepsResult.class); - Mockito.when(emrClient.addJobFlowSteps(any())).thenReturn(addJobFlowStepsResult); - Mockito.when(addJobFlowStepsResult.getStepIds()).thenReturn(Collections.singletonList("step-xx")); + Mockito.lenient().when(emrClient.addJobFlowSteps(any())).thenReturn(addJobFlowStepsResult); + Mockito.lenient().when(addJobFlowStepsResult.getStepIds()).thenReturn(Collections.singletonList("step-xx")); Mockito.doReturn(emrClient).when(emrAddStepsTask).createEmrClient(); DescribeStepResult describeStepResult = Mockito.mock(DescribeStepResult.class); - Mockito.when(emrClient.describeStep(any())).thenReturn(describeStepResult); + Mockito.lenient().when(emrClient.describeStep(any())).thenReturn(describeStepResult); // mock step step = Mockito.mock(Step.class); - Mockito.when(describeStepResult.getStep()).thenReturn(step); + Mockito.lenient().when(describeStepResult.getStep()).thenReturn(step); emrAddStepsTask.init(); } - @Test(expected = TaskException.class) + @Test public void testCanNotParseJson() throws Exception { - Mockito.when(emrAddStepsTask.createAddJobFlowStepsRequest()).thenThrow(new EmrTaskException("can not parse AddJobFlowStepsRequest from json", new Exception("error"))); - emrAddStepsTask.handle(taskCallBack); + Mockito.when(emrAddStepsTask.createAddJobFlowStepsRequest()).thenThrow( + new EmrTaskException("can not parse AddJobFlowStepsRequest from json", new Exception("error"))); + Assertions.assertThrows(TaskException.class, () -> { + emrAddStepsTask.handle(taskCallBack); + }); } - @Test(expected = TaskException.class) + @Test public void testDefineJsonStepNotOne() throws Exception { // mock EmrParameters and EmrAddStepsTask EmrParameters emrParameters = buildErrorEmrTaskParameters(); @@ -120,8 +123,11 @@ public class EmrAddStepsTaskTest { Mockito.when(taskExecutionContext.getTaskParams()).thenReturn(emrParametersString); emrAddStepsTask = Mockito.spy(new EmrAddStepsTask(taskExecutionContext)); Mockito.doReturn(emrClient).when(emrAddStepsTask).createEmrClient(); - emrAddStepsTask.init(); - emrAddStepsTask.handle(taskCallBack); + Assertions.assertThrows(TaskException.class, () -> { + emrAddStepsTask.init(); + emrAddStepsTask.handle(taskCallBack); + }); + } @Test @@ -129,7 +135,7 @@ public class EmrAddStepsTaskTest { Mockito.when(step.getStatus()).thenReturn(pendingState, runningState, completedState); emrAddStepsTask.handle(taskCallBack); - Assert.assertEquals(EXIT_CODE_SUCCESS, emrAddStepsTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, emrAddStepsTask.getExitStatusCode()); } @Test @@ -137,17 +143,20 @@ public class EmrAddStepsTaskTest { Mockito.when(step.getStatus()).thenReturn(pendingState, runningState, cancelledState); emrAddStepsTask.handle(taskCallBack); - Assert.assertEquals(EXIT_CODE_KILL, emrAddStepsTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_KILL, emrAddStepsTask.getExitStatusCode()); } - @Test(expected = TaskException.class) + @Test public void testHandleError() throws Exception { Mockito.when(step.getStatus()).thenReturn(pendingState, runningState, failedState); emrAddStepsTask.handle(taskCallBack); - Assert.assertEquals(EXIT_CODE_FAILURE, emrAddStepsTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_FAILURE, emrAddStepsTask.getExitStatusCode()); - Mockito.when(emrClient.addJobFlowSteps(any())).thenThrow(new AmazonElasticMapReduceException("error"), new EmrTaskException()); - emrAddStepsTask.handle(taskCallBack); + Mockito.when(emrClient.addJobFlowSteps(any())).thenThrow(new AmazonElasticMapReduceException("error"), + new EmrTaskException()); + Assertions.assertThrows(TaskException.class, () -> { + emrAddStepsTask.handle(taskCallBack); + }); } private EmrParameters buildEmrTaskParameters() { @@ -179,4 +188,4 @@ public class EmrAddStepsTaskTest { return emrParameters; } -} \ No newline at end of file +} diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrJobFlowTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrJobFlowTaskTest.java index 1830217f75..518dff8228 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrJobFlowTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrJobFlowTaskTest.java @@ -32,12 +32,12 @@ import org.apache.commons.io.IOUtils; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduce; import com.amazonaws.services.elasticmapreduce.model.AmazonElasticMapReduceException; @@ -49,56 +49,49 @@ import com.amazonaws.services.elasticmapreduce.model.ClusterStatus; import com.amazonaws.services.elasticmapreduce.model.DescribeClusterResult; import com.amazonaws.services.elasticmapreduce.model.RunJobFlowResult; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class EmrJobFlowTaskTest { private final ClusterStatus startingStatus = - new ClusterStatus().withState(ClusterState.STARTING) - .withStateChangeReason(new ClusterStateChangeReason()); + new ClusterStatus().withState(ClusterState.STARTING) + .withStateChangeReason(new ClusterStateChangeReason()); private final ClusterStatus softwareConfigStatus = - new ClusterStatus().withState(ClusterState.STARTING) - .withStateChangeReason( - new ClusterStateChangeReason() - .withMessage("Configuring cluster software") - ); + new ClusterStatus().withState(ClusterState.STARTING) + .withStateChangeReason( + new ClusterStateChangeReason() + .withMessage("Configuring cluster software")); private final ClusterStatus runningStatus = - new ClusterStatus().withState(ClusterState.RUNNING) - .withStateChangeReason( - new ClusterStateChangeReason().withMessage("Running step") - ); + new ClusterStatus().withState(ClusterState.RUNNING) + .withStateChangeReason( + new ClusterStateChangeReason().withMessage("Running step")); private final ClusterStatus terminatingStatus = - new ClusterStatus().withState(ClusterState.TERMINATING.toString()) - .withStateChangeReason( - new ClusterStateChangeReason() - .withCode(ClusterStateChangeReasonCode.ALL_STEPS_COMPLETED) - .withMessage("Steps completed") - ); + new ClusterStatus().withState(ClusterState.TERMINATING.toString()) + .withStateChangeReason( + new ClusterStateChangeReason() + .withCode(ClusterStateChangeReasonCode.ALL_STEPS_COMPLETED) + .withMessage("Steps completed")); private final ClusterStatus waitingStatus = - new ClusterStatus().withState(ClusterState.WAITING) - .withStateChangeReason( - new ClusterStateChangeReason() - .withMessage("Cluster ready after last step completed.") - ); + new ClusterStatus().withState(ClusterState.WAITING) + .withStateChangeReason( + new ClusterStateChangeReason() + .withMessage("Cluster ready after last step completed.")); private final ClusterStatus userRequestTerminateStatus = - new ClusterStatus().withState(ClusterState.TERMINATING) - .withStateChangeReason( - new ClusterStateChangeReason() - .withCode(ClusterStateChangeReasonCode.USER_REQUEST) - .withMessage("Terminated by user request") - ); - + new ClusterStatus().withState(ClusterState.TERMINATING) + .withStateChangeReason( + new ClusterStateChangeReason() + .withCode(ClusterStateChangeReasonCode.USER_REQUEST) + .withMessage("Terminated by user request")); private final ClusterStatus terminatedWithErrorsStatus = - new ClusterStatus().withState(ClusterState.TERMINATED_WITH_ERRORS) - .withStateChangeReason( - new ClusterStateChangeReason() - .withCode(ClusterStateChangeReasonCode.STEP_FAILURE) - ); + new ClusterStatus().withState(ClusterState.TERMINATED_WITH_ERRORS) + .withStateChangeReason( + new ClusterStateChangeReason() + .withCode(ClusterStateChangeReasonCode.STEP_FAILURE)); private EmrJobFlowTask emrJobFlowTask; private AmazonElasticMapReduce emrClient; @@ -107,7 +100,7 @@ public class EmrJobFlowTaskTest { }; - @Before + @BeforeEach public void before() throws Exception { String emrParameters = buildEmrTaskParameters(); TaskExecutionContext taskExecutionContext = Mockito.mock(TaskExecutionContext.class); @@ -117,15 +110,15 @@ public class EmrJobFlowTaskTest { // mock emrClient and behavior emrClient = Mockito.mock(AmazonElasticMapReduce.class); RunJobFlowResult runJobFlowResult = Mockito.mock(RunJobFlowResult.class); - Mockito.when(emrClient.runJobFlow(any())).thenReturn(runJobFlowResult); - Mockito.when(runJobFlowResult.getJobFlowId()).thenReturn("xx"); + Mockito.lenient().when(emrClient.runJobFlow(any())).thenReturn(runJobFlowResult); + Mockito.lenient().when(runJobFlowResult.getJobFlowId()).thenReturn("xx"); Mockito.doReturn(emrClient).when(emrJobFlowTask).createEmrClient(); DescribeClusterResult describeClusterResult = Mockito.mock(DescribeClusterResult.class); - Mockito.when(emrClient.describeCluster(any())).thenReturn(describeClusterResult); + Mockito.lenient().when(emrClient.describeCluster(any())).thenReturn(describeClusterResult); // mock cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(describeClusterResult.getCluster()).thenReturn(cluster); + Mockito.lenient().when(describeClusterResult.getCluster()).thenReturn(cluster); emrJobFlowTask.init(); } @@ -133,19 +126,21 @@ public class EmrJobFlowTaskTest { @Test public void testHandle() throws Exception { - Mockito.when(cluster.getStatus()).thenReturn(startingStatus, softwareConfigStatus, runningStatus, terminatingStatus); + Mockito.when(cluster.getStatus()).thenReturn(startingStatus, softwareConfigStatus, runningStatus, + terminatingStatus); emrJobFlowTask.handle(taskCallBack); - Assert.assertEquals(EXIT_CODE_SUCCESS, emrJobFlowTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, emrJobFlowTask.getExitStatusCode()); } @Test public void testHandleAliveWhenNoSteps() throws Exception { - Mockito.when(cluster.getStatus()).thenReturn(startingStatus, softwareConfigStatus, runningStatus, waitingStatus); + Mockito.when(cluster.getStatus()).thenReturn(startingStatus, softwareConfigStatus, runningStatus, + waitingStatus); emrJobFlowTask.handle(taskCallBack); - Assert.assertEquals(EXIT_CODE_SUCCESS, emrJobFlowTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, emrJobFlowTask.getExitStatusCode()); } @Test @@ -153,34 +148,42 @@ public class EmrJobFlowTaskTest { Mockito.when(cluster.getStatus()).thenReturn(startingStatus, userRequestTerminateStatus); emrJobFlowTask.handle(taskCallBack); - Assert.assertEquals(EXIT_CODE_KILL, emrJobFlowTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_KILL, emrJobFlowTask.getExitStatusCode()); } @Test public void testHandleTerminatedWithError() throws Exception { - Mockito.when(cluster.getStatus()).thenReturn(startingStatus, softwareConfigStatus, runningStatus, terminatedWithErrorsStatus); + Mockito.when(cluster.getStatus()).thenReturn(startingStatus, softwareConfigStatus, runningStatus, + terminatedWithErrorsStatus); emrJobFlowTask.handle(taskCallBack); - Assert.assertEquals(EXIT_CODE_FAILURE, emrJobFlowTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_FAILURE, emrJobFlowTask.getExitStatusCode()); } - @Test(expected = TaskException.class) + @Test public void testCanNotParseJson() throws Exception { - Mockito.when(emrJobFlowTask.createRunJobFlowRequest()).thenThrow(new EmrTaskException("can not parse RunJobFlowRequest from json", new Exception("error"))); - emrJobFlowTask.handle(taskCallBack); + Mockito.when(emrJobFlowTask.createRunJobFlowRequest()) + .thenThrow(new EmrTaskException("can not parse RunJobFlowRequest from json", new Exception("error"))); + Assertions.assertThrows(TaskException.class, () -> { + emrJobFlowTask.handle(taskCallBack); + }); } - @Test(expected = TaskException.class) + @Test public void testClusterStatusNull() throws Exception { - Mockito.when(emrClient.describeCluster(any())).thenReturn(null); - emrJobFlowTask.handle(taskCallBack); + Assertions.assertThrows(TaskException.class, () -> { + emrJobFlowTask.handle(taskCallBack); + }); } - @Test(expected = TaskException.class) + @Test public void testRunJobFlowError() throws Exception { - Mockito.when(emrClient.runJobFlow(any())).thenThrow(new AmazonElasticMapReduceException("error"), new EmrTaskException()); - emrJobFlowTask.handle(taskCallBack); + Mockito.when(emrClient.runJobFlow(any())).thenThrow(new AmazonElasticMapReduceException("error"), + new EmrTaskException()); + Assertions.assertThrows(TaskException.class, () -> { + emrJobFlowTask.handle(taskCallBack); + }); } private String buildEmrTaskParameters() { @@ -197,4 +200,4 @@ public class EmrJobFlowTaskTest { return JSONUtils.toJsonString(emrParameters); } -} \ No newline at end of file +} diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkArgsUtilsTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkArgsUtilsTest.java index cbd9852e2e..8d3f83b622 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkArgsUtilsTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkArgsUtilsTest.java @@ -19,11 +19,12 @@ package org.apache.dolphinscheduler.plugin.task.flink; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo; -import org.junit.Assert; -import org.junit.Test; import java.util.List; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + public class FlinkArgsUtilsTest { private String joinStringListWithSpace(List stringList) { @@ -60,7 +61,7 @@ public class FlinkArgsUtilsTest { FlinkStreamParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.APPLICATION); List commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); - Assert.assertEquals( + Assertions.assertEquals( "flink run-application -t yarn-application -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", joinStringListWithSpace(commandLine)); } @@ -69,23 +70,26 @@ public class FlinkArgsUtilsTest { public void testRunJarInClusterMode() throws Exception { FlinkStreamParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.CLUSTER); flinkParameters.setFlinkVersion("1.11"); - List commandLine1 = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); + List commandLine1 = + FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); - Assert.assertEquals( + Assertions.assertEquals( "flink run -m yarn-cluster -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", joinStringListWithSpace(commandLine1)); flinkParameters.setFlinkVersion("<1.10"); - List commandLine2 = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); + List commandLine2 = + FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); - Assert.assertEquals( + Assertions.assertEquals( "flink run -m yarn-cluster -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", joinStringListWithSpace(commandLine2)); flinkParameters.setFlinkVersion(">=1.12"); - List commandLine3 = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); + List commandLine3 = + FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); - Assert.assertEquals( + Assertions.assertEquals( "flink run -t yarn-per-job -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", joinStringListWithSpace(commandLine3)); } @@ -95,7 +99,7 @@ public class FlinkArgsUtilsTest { FlinkStreamParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.LOCAL); List commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); - Assert.assertEquals( + Assertions.assertEquals( "flink run -p 4 -sae -c org.example.Main /opt/job.jar", joinStringListWithSpace(commandLine)); } @@ -106,27 +110,29 @@ public class FlinkArgsUtilsTest { flinkParameters.setProgramType(ProgramType.SQL); List commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); - Assert.assertEquals("sql-client.sh -i /tmp/execution/app-id_init.sql -f /tmp/execution/app-id_node.sql", + Assertions.assertEquals("sql-client.sh -i /tmp/execution/app-id_init.sql -f /tmp/execution/app-id_node.sql", joinStringListWithSpace(commandLine)); } @Test public void testInitOptionsInClusterMode() throws Exception { - List initOptions = FlinkArgsUtils.buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.CLUSTER)); - Assert.assertEquals(2, initOptions.size()); - Assert.assertTrue(initOptions.contains("set execution.target=local")); - Assert.assertTrue(initOptions.contains("set parallelism.default=4")); + List initOptions = + FlinkArgsUtils.buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.CLUSTER)); + Assertions.assertEquals(2, initOptions.size()); + Assertions.assertTrue(initOptions.contains("set execution.target=local")); + Assertions.assertTrue(initOptions.contains("set parallelism.default=4")); } @Test public void testInitOptionsInApplicationMode() throws Exception { - List initOptions = FlinkArgsUtils.buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.APPLICATION)); - Assert.assertEquals(6, initOptions.size()); - Assert.assertTrue(initOptions.contains("set execution.target=yarn-per-job")); - Assert.assertTrue(initOptions.contains("set taskmanager.numberOfTaskSlots=4")); - Assert.assertTrue(initOptions.contains("set yarn.application.name=demo-app-name")); - Assert.assertTrue(initOptions.contains("set jobmanager.memory.process.size=1024m")); - Assert.assertTrue(initOptions.contains("set taskmanager.memory.process.size=1024m")); - Assert.assertTrue(initOptions.contains("set parallelism.default=4")); + List initOptions = FlinkArgsUtils + .buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.APPLICATION)); + Assertions.assertEquals(6, initOptions.size()); + Assertions.assertTrue(initOptions.contains("set execution.target=yarn-per-job")); + Assertions.assertTrue(initOptions.contains("set taskmanager.numberOfTaskSlots=4")); + Assertions.assertTrue(initOptions.contains("set yarn.application.name=demo-app-name")); + Assertions.assertTrue(initOptions.contains("set jobmanager.memory.process.size=1024m")); + Assertions.assertTrue(initOptions.contains("set taskmanager.memory.process.size=1024m")); + Assertions.assertTrue(initOptions.contains("set parallelism.default=4")); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkParametersTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkParametersTest.java index e998540316..cb39748fcc 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkParametersTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkParametersTest.java @@ -22,14 +22,15 @@ import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo; import java.util.LinkedList; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class FlinkParametersTest { + @Test public void getResourceFilesList() { FlinkStreamParameters flinkParameters = new FlinkStreamParameters(); - Assert.assertTrue(flinkParameters.getResourceFilesList().isEmpty()); + Assertions.assertTrue(flinkParameters.getResourceFilesList().isEmpty()); ResourceInfo mainResource = new ResourceInfo(); mainResource.setRes("testFlinkMain-1.0.0-SNAPSHOT.jar"); @@ -42,8 +43,8 @@ public class FlinkParametersTest { flinkParameters.setResourceList(resourceInfos); List resourceFilesList = flinkParameters.getResourceFilesList(); - Assert.assertNotNull(resourceFilesList); - Assert.assertEquals(2, resourceFilesList.size()); + Assertions.assertNotNull(resourceFilesList); + Assertions.assertEquals(2, resourceFilesList.size()); ResourceInfo resourceInfo2 = new ResourceInfo(); resourceInfo2.setRes("testFlinkParameters2.jar"); @@ -51,7 +52,7 @@ public class FlinkParametersTest { flinkParameters.setResourceList(resourceInfos); resourceFilesList = flinkParameters.getResourceFilesList(); - Assert.assertNotNull(resourceFilesList); - Assert.assertEquals(3, resourceFilesList.size()); + Assertions.assertNotNull(resourceFilesList); + Assertions.assertEquals(3, resourceFilesList.size()); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkArgsUtilsTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkArgsUtilsTest.java index f71afb4d0e..62148521aa 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkArgsUtilsTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkArgsUtilsTest.java @@ -19,11 +19,12 @@ package org.apache.dolphinscheduler.plugin.task.flink; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo; -import org.junit.Assert; -import org.junit.Test; import java.util.List; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + public class FlinkArgsUtilsTest { private String joinStringListWithSpace(List stringList) { @@ -60,7 +61,7 @@ public class FlinkArgsUtilsTest { FlinkParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.APPLICATION); List commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); - Assert.assertEquals( + Assertions.assertEquals( "flink run-application -t yarn-application -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", joinStringListWithSpace(commandLine)); } @@ -69,23 +70,26 @@ public class FlinkArgsUtilsTest { public void testRunJarInClusterMode() throws Exception { FlinkParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.CLUSTER); flinkParameters.setFlinkVersion("1.11"); - List commandLine1 = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); + List commandLine1 = + FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); - Assert.assertEquals( + Assertions.assertEquals( "flink run -m yarn-cluster -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", joinStringListWithSpace(commandLine1)); flinkParameters.setFlinkVersion("<1.10"); - List commandLine2 = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); + List commandLine2 = + FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); - Assert.assertEquals( + Assertions.assertEquals( "flink run -m yarn-cluster -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", joinStringListWithSpace(commandLine2)); flinkParameters.setFlinkVersion(">=1.12"); - List commandLine3 = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); + List commandLine3 = + FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); - Assert.assertEquals( + Assertions.assertEquals( "flink run -t yarn-per-job -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", joinStringListWithSpace(commandLine3)); } @@ -95,7 +99,7 @@ public class FlinkArgsUtilsTest { FlinkParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.LOCAL); List commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); - Assert.assertEquals( + Assertions.assertEquals( "flink run -p 4 -sae -c org.example.Main /opt/job.jar", joinStringListWithSpace(commandLine)); } @@ -106,27 +110,29 @@ public class FlinkArgsUtilsTest { flinkParameters.setProgramType(ProgramType.SQL); List commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); - Assert.assertEquals("sql-client.sh -i /tmp/execution/app-id_init.sql -f /tmp/execution/app-id_node.sql", + Assertions.assertEquals("sql-client.sh -i /tmp/execution/app-id_init.sql -f /tmp/execution/app-id_node.sql", joinStringListWithSpace(commandLine)); } @Test public void testInitOptionsInClusterMode() throws Exception { - List initOptions = FlinkArgsUtils.buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.CLUSTER)); - Assert.assertEquals(2, initOptions.size()); - Assert.assertTrue(initOptions.contains("set execution.target=local")); - Assert.assertTrue(initOptions.contains("set parallelism.default=4")); + List initOptions = + FlinkArgsUtils.buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.CLUSTER)); + Assertions.assertEquals(2, initOptions.size()); + Assertions.assertTrue(initOptions.contains("set execution.target=local")); + Assertions.assertTrue(initOptions.contains("set parallelism.default=4")); } @Test public void testInitOptionsInApplicationMode() throws Exception { - List initOptions = FlinkArgsUtils.buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.APPLICATION)); - Assert.assertEquals(6, initOptions.size()); - Assert.assertTrue(initOptions.contains("set execution.target=yarn-per-job")); - Assert.assertTrue(initOptions.contains("set taskmanager.numberOfTaskSlots=4")); - Assert.assertTrue(initOptions.contains("set yarn.application.name=demo-app-name")); - Assert.assertTrue(initOptions.contains("set jobmanager.memory.process.size=1024m")); - Assert.assertTrue(initOptions.contains("set taskmanager.memory.process.size=1024m")); - Assert.assertTrue(initOptions.contains("set parallelism.default=4")); + List initOptions = FlinkArgsUtils + .buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.APPLICATION)); + Assertions.assertEquals(6, initOptions.size()); + Assertions.assertTrue(initOptions.contains("set execution.target=yarn-per-job")); + Assertions.assertTrue(initOptions.contains("set taskmanager.numberOfTaskSlots=4")); + Assertions.assertTrue(initOptions.contains("set yarn.application.name=demo-app-name")); + Assertions.assertTrue(initOptions.contains("set jobmanager.memory.process.size=1024m")); + Assertions.assertTrue(initOptions.contains("set taskmanager.memory.process.size=1024m")); + Assertions.assertTrue(initOptions.contains("set parallelism.default=4")); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkParametersTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkParametersTest.java index 52aa7dbc5d..3e4a614acb 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkParametersTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkParametersTest.java @@ -1,57 +1,58 @@ -/* - * 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.plugin.task.flink; - -import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo; - -import java.util.LinkedList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; - -public class FlinkParametersTest { - @Test - public void getResourceFilesList() { - FlinkParameters flinkParameters = new FlinkParameters(); - Assert.assertTrue(flinkParameters.getResourceFilesList().isEmpty()); - - ResourceInfo mainResource = new ResourceInfo(); - mainResource.setRes("testFlinkMain-1.0.0-SNAPSHOT.jar"); - flinkParameters.setMainJar(mainResource); - - List resourceInfos = new LinkedList<>(); - ResourceInfo resourceInfo1 = new ResourceInfo(); - resourceInfo1.setRes("testFlinkParameters1.jar"); - resourceInfos.add(resourceInfo1); - - flinkParameters.setResourceList(resourceInfos); - List resourceFilesList = flinkParameters.getResourceFilesList(); - Assert.assertNotNull(resourceFilesList); - Assert.assertEquals(2, resourceFilesList.size()); - - ResourceInfo resourceInfo2 = new ResourceInfo(); - resourceInfo2.setRes("testFlinkParameters2.jar"); - resourceInfos.add(resourceInfo2); - - flinkParameters.setResourceList(resourceInfos); - resourceFilesList = flinkParameters.getResourceFilesList(); - Assert.assertNotNull(resourceFilesList); - Assert.assertEquals(3, resourceFilesList.size()); - } -} +/* + * 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.plugin.task.flink; + +import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo; + +import java.util.LinkedList; +import java.util.List; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class FlinkParametersTest { + + @Test + public void getResourceFilesList() { + FlinkParameters flinkParameters = new FlinkParameters(); + Assertions.assertTrue(flinkParameters.getResourceFilesList().isEmpty()); + + ResourceInfo mainResource = new ResourceInfo(); + mainResource.setRes("testFlinkMain-1.0.0-SNAPSHOT.jar"); + flinkParameters.setMainJar(mainResource); + + List resourceInfos = new LinkedList<>(); + ResourceInfo resourceInfo1 = new ResourceInfo(); + resourceInfo1.setRes("testFlinkParameters1.jar"); + resourceInfos.add(resourceInfo1); + + flinkParameters.setResourceList(resourceInfos); + List resourceFilesList = flinkParameters.getResourceFilesList(); + Assertions.assertNotNull(resourceFilesList); + Assertions.assertEquals(2, resourceFilesList.size()); + + ResourceInfo resourceInfo2 = new ResourceInfo(); + resourceInfo2.setRes("testFlinkParameters2.jar"); + resourceInfos.add(resourceInfo2); + + flinkParameters.setResourceList(resourceInfos); + resourceFilesList = flinkParameters.getResourceFilesList(); + Assertions.assertNotNull(resourceFilesList); + Assertions.assertEquals(3, resourceFilesList.size()); + } +} diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-hivecli/src/test/java/org/apache/dolphinscheduler/plugin/task/hivecli/HiveCliTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-hivecli/src/test/java/org/apache/dolphinscheduler/plugin/task/hivecli/HiveCliTaskTest.java index 62655dfb86..6369dea0dd 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-hivecli/src/test/java/org/apache/dolphinscheduler/plugin/task/hivecli/HiveCliTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-hivecli/src/test/java/org/apache/dolphinscheduler/plugin/task/hivecli/HiveCliTaskTest.java @@ -27,13 +27,13 @@ import org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.ArrayList; import java.util.List; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class HiveCliTaskTest { public static final String EXPECTED_HIVE_CLI_TASK_EXECUTE_FROM_SCRIPT_COMMAND = @@ -50,7 +50,7 @@ public class HiveCliTaskTest { String hiveCliTaskParameters = buildHiveCliTaskExecuteSqlFromScriptParameters(); HiveCliTask hiveCliTask = prepareHiveCliTaskForTest(hiveCliTaskParameters); hiveCliTask.init(); - Assert.assertEquals(hiveCliTask.buildCommand(), EXPECTED_HIVE_CLI_TASK_EXECUTE_FROM_SCRIPT_COMMAND); + Assertions.assertEquals(hiveCliTask.buildCommand(), EXPECTED_HIVE_CLI_TASK_EXECUTE_FROM_SCRIPT_COMMAND); } @Test @@ -58,7 +58,7 @@ public class HiveCliTaskTest { String hiveCliTaskParameters = buildHiveCliTaskExecuteSqlFromFileParameters(); HiveCliTask hiveCliTask = prepareHiveCliTaskForTest(hiveCliTaskParameters); hiveCliTask.init(); - Assert.assertEquals(hiveCliTask.buildCommand(), EXPECTED_HIVE_CLI_TASK_EXECUTE_FROM_FILE_COMMAND); + Assertions.assertEquals(hiveCliTask.buildCommand(), EXPECTED_HIVE_CLI_TASK_EXECUTE_FROM_FILE_COMMAND); } @Test @@ -66,7 +66,7 @@ public class HiveCliTaskTest { String hiveCliTaskParameters = buildHiveCliTaskExecuteWithOptionsParameters(); HiveCliTask hiveCliTask = prepareHiveCliTaskForTest(hiveCliTaskParameters); hiveCliTask.init(); - Assert.assertEquals(hiveCliTask.buildCommand(), EXPECTED_HIVE_CLI_TASK_EXECUTE_WITH_OPTIONS); + Assertions.assertEquals(hiveCliTask.buildCommand(), EXPECTED_HIVE_CLI_TASK_EXECUTE_WITH_OPTIONS); } private HiveCliTask prepareHiveCliTaskForTest(final String hiveCliTaskParameters) { diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpParametersTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpParametersTest.java index aede1781cb..1ad25daf90 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpParametersTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpParametersTest.java @@ -19,13 +19,13 @@ package org.apache.dolphinscheduler.plugin.task.http; import org.apache.dolphinscheduler.spi.utils.JSONUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * http parameter */ -public class HttpParametersTest { +public class HttpParametersTest { @Test public void testGenerator() { @@ -33,12 +33,12 @@ public class HttpParametersTest { + "\"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()); + Assertions.assertEquals(10000, httpParameters.getConnectTimeout()); + Assertions.assertEquals(10000, httpParameters.getSocketTimeout()); + Assertions.assertEquals("https://www.baidu.com/", httpParameters.getUrl()); + Assertions.assertEquals(HttpMethod.GET, httpParameters.getHttpMethod()); + Assertions.assertEquals(HttpCheckCondition.STATUS_CODE_DEFAULT, httpParameters.getHttpCheckCondition()); + Assertions.assertEquals("", httpParameters.getCondition()); } @@ -48,13 +48,13 @@ public class HttpParametersTest { + "\"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()); + Assertions.assertTrue(httpParameters.checkParameters()); + Assertions.assertEquals(10000, httpParameters.getConnectTimeout()); + Assertions.assertEquals(10000, httpParameters.getSocketTimeout()); + Assertions.assertEquals("https://www.baidu.com/", httpParameters.getUrl()); + Assertions.assertEquals(HttpMethod.GET, httpParameters.getHttpMethod()); + Assertions.assertEquals(HttpCheckCondition.STATUS_CODE_DEFAULT, httpParameters.getHttpCheckCondition()); + Assertions.assertEquals("", httpParameters.getCondition()); } @@ -64,15 +64,15 @@ public class HttpParametersTest { + "\"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()); + Assertions.assertTrue(httpParameters.checkParameters()); + Assertions.assertEquals(10000, httpParameters.getConnectTimeout()); + Assertions.assertEquals(10000, httpParameters.getSocketTimeout()); + Assertions.assertEquals("https://www.baidu.com/", httpParameters.getUrl()); + Assertions.assertEquals(HttpMethod.GET, httpParameters.getHttpMethod()); + Assertions.assertEquals(HttpCheckCondition.STATUS_CODE_DEFAULT, httpParameters.getHttpCheckCondition()); + Assertions.assertEquals("", httpParameters.getCondition()); + Assertions.assertEquals(0, httpParameters.getLocalParametersMap().size()); + Assertions.assertEquals(0, httpParameters.getResourceFilesList().size()); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpTaskTest.java index f42976d5ee..5873feb019 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpTaskTest.java @@ -39,12 +39,12 @@ import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; -import org.junit.After; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -52,7 +52,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; /** * Test HttpTask */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class HttpTaskTest { private static final String CONTENT_TYPE = "Content-Type"; @@ -65,7 +65,7 @@ public class HttpTaskTest { private final List mockWebServers = new ArrayList<>(); - @After + @AfterEach public void after() { mockWebServers.forEach(IOUtils::closeQuietly); mockWebServers.clear(); @@ -83,18 +83,18 @@ public class HttpTaskTest { headHttpTask.handle(null); putHttpTask.handle(null); deleteHttpTask.handle(null); - Assert.assertEquals(EXIT_CODE_SUCCESS, getHttpTask.getExitStatusCode()); - Assert.assertEquals(EXIT_CODE_SUCCESS, postHttpTask.getExitStatusCode()); - Assert.assertEquals(EXIT_CODE_SUCCESS, headHttpTask.getExitStatusCode()); - Assert.assertEquals(EXIT_CODE_SUCCESS, putHttpTask.getExitStatusCode()); - Assert.assertEquals(EXIT_CODE_SUCCESS, deleteHttpTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, getHttpTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, postHttpTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, headHttpTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, putHttpTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, deleteHttpTask.getExitStatusCode()); } @Test public void testHandleCheckCodeDefaultError() throws Exception { HttpTask getHttpTask = generateHttpTask(HttpMethod.GET, HttpStatus.SC_BAD_REQUEST); getHttpTask.handle(null); - Assert.assertEquals(EXIT_CODE_FAILURE, getHttpTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_FAILURE, getHttpTask.getExitStatusCode()); } @Test @@ -106,8 +106,8 @@ public class HttpTaskTest { condition, HttpStatus.SC_OK, ""); httpTask.handle(null); httpErrorTask.handle(null); - Assert.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); - Assert.assertEquals(EXIT_CODE_FAILURE, httpErrorTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_FAILURE, httpErrorTask.getExitStatusCode()); } @Test @@ -118,8 +118,8 @@ public class HttpTaskTest { "success", HttpStatus.SC_OK, "{\"status\": \"failed\"}"); httpTask.handle(null); httpErrorTask.handle(null); - Assert.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); - Assert.assertEquals(EXIT_CODE_FAILURE, httpErrorTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_FAILURE, httpErrorTask.getExitStatusCode()); } @Test @@ -130,8 +130,8 @@ public class HttpTaskTest { "failed", HttpStatus.SC_OK, "{\"status\": \"failed\"}"); httpTask.handle(null); httpErrorTask.handle(null); - Assert.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); - Assert.assertEquals(EXIT_CODE_FAILURE, httpErrorTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_FAILURE, httpErrorTask.getExitStatusCode()); } @Test @@ -151,7 +151,7 @@ public class HttpTaskTest { httpParams, prepareParamsMap, HttpCheckCondition.BODY_CONTAINS, "20220812", HttpStatus.SC_OK, ""); httpTask.handle(null); - Assert.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); } @Test @@ -171,7 +171,7 @@ public class HttpTaskTest { httpParams, prepareParamsMap, HttpCheckCondition.BODY_CONTAINS, "20220812", HttpStatus.SC_OK, ""); httpTask.handle(null); - Assert.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); } private String withMockWebServer(String path, int actualResponseCode, diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/main/test/org/apache/dolphinscheduler/plugin/task/java/JavaTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/test/java/org/apache/dolphinscheduler/plugin/task/java/JavaTaskTest.java similarity index 76% rename from dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/main/test/org/apache/dolphinscheduler/plugin/task/java/JavaTaskTest.java rename to dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/test/java/org/apache/dolphinscheduler/plugin/task/java/JavaTaskTest.java index 89cc4f89e5..c242e44359 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/main/test/org/apache/dolphinscheduler/plugin/task/java/JavaTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/test/java/org/apache/dolphinscheduler/plugin/task/java/JavaTaskTest.java @@ -22,6 +22,7 @@ import static org.apache.dolphinscheduler.plugin.task.api.enums.Direct.IN; import static org.apache.dolphinscheduler.plugin.task.java.JavaConstants.RUN_TYPE_JAR; import static org.apache.dolphinscheduler.plugin.task.java.JavaConstants.RUN_TYPE_JAVA; +import org.apache.dolphinscheduler.plugin.task.api.TaskCallBack; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.model.Property; import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo; @@ -38,15 +39,19 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class JavaTaskTest { + private TaskCallBack taskCallBack = (taskInstanceId, appIds) -> { + + }; + @Test - public void testGetPubllicClassName(){ + public void testGetPubllicClassName() { JavaTask javaTask = runJavaType(); - Assert.assertEquals(javaTask.getPublicClassName("import java.io.IOException;\n" + + Assertions.assertEquals(javaTask.getPublicClassName("import java.io.IOException;\n" + "public class JavaTaskTest {\n" + " public static void main(String[] args) throws IOException {\n" + " StringBuilder builder = new StringBuilder(\"Hello: \");\n" + @@ -67,7 +72,7 @@ public class JavaTaskTest { public void buildJarCommand() { String homeBinPath = JavaConstants.JAVA_HOME_VAR + File.separator + "bin" + File.separator; JavaTask javaTask = runJarType(); - Assert.assertEquals(javaTask.buildJarCommand(), homeBinPath + Assertions.assertEquals(javaTask.buildJarCommand(), homeBinPath + "java --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar -jar /tmp/dolphinscheduler/test/executepath/opt/share/jar/main.jar -host 127.0.0.1 -port 8080 -xms:50m"); } @@ -81,7 +86,7 @@ public class JavaTaskTest { JavaTask javaTask = runJavaType(); String sourceCode = javaTask.buildJavaSourceContent(); String publicClassName = javaTask.getPublicClassName(sourceCode); - Assert.assertEquals("JavaTaskTest", publicClassName); + Assertions.assertEquals("JavaTaskTest", publicClassName); String fileName = javaTask.buildJavaSourceCodeFileFullName(publicClassName); try { String homeBinPath = JavaConstants.JAVA_HOME_VAR + File.separator + "bin" + File.separator; @@ -89,8 +94,8 @@ public class JavaTaskTest { if (Files.exists(path)) { Files.delete(path); } - Assert.assertEquals(homeBinPath - + "javac --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java", + Assertions.assertEquals(homeBinPath + + "javac --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java", javaTask.buildJavaCompileCommand(sourceCode)); } finally { Path path = Paths.get(fileName); @@ -108,17 +113,18 @@ public class JavaTaskTest { **/ @Test public void buildJavaCommand() throws Exception { - String wantJavaCommand = "${JAVA_HOME}/bin/javac --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java;${JAVA_HOME}/bin/java --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar JavaTaskTest -host 127.0.0.1 -port 8080 -xms:50m"; + String wantJavaCommand = + "${JAVA_HOME}/bin/javac --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java;${JAVA_HOME}/bin/java --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar JavaTaskTest -host 127.0.0.1 -port 8080 -xms:50m"; JavaTask javaTask = runJavaType(); String sourceCode = javaTask.buildJavaSourceContent(); String publicClassName = javaTask.getPublicClassName(sourceCode); - Assert.assertEquals("JavaTaskTest", publicClassName); + Assertions.assertEquals("JavaTaskTest", publicClassName); String fileName = javaTask.buildJavaSourceCodeFileFullName(publicClassName); Path path = Paths.get(fileName); if (Files.exists(path)) { Files.delete(path); } - Assert.assertEquals(wantJavaCommand, javaTask.buildJavaCommand()); + Assertions.assertEquals(wantJavaCommand, javaTask.buildJavaCommand()); } /** @@ -126,25 +132,28 @@ public class JavaTaskTest { * @return void * @throws IOException **/ - @Test(expected = JavaSourceFileExistException.class) - public void coverJavaSourceFileExistException() throws IOException { + @Test + public void coverJavaSourceFileExistException() throws IOException { JavaTask javaTask = runJavaType(); String sourceCode = javaTask.buildJavaSourceContent(); String publicClassName = javaTask.getPublicClassName(sourceCode); - Assert.assertEquals("JavaTaskTest", publicClassName); + Assertions.assertEquals("JavaTaskTest", publicClassName); String fileName = javaTask.buildJavaSourceCodeFileFullName(publicClassName); - try { - Path path = Paths.get(fileName); - if (!Files.exists(path)) { - Files.createDirectories(path); - } - javaTask.createJavaSourceFileIfNotExists(sourceCode,fileName); - } finally { - Path path = Paths.get(fileName); - if (Files.exists(path)) { - Files.delete(path); + + Assertions.assertThrows(JavaSourceFileExistException.class, () -> { + try { + Path path = Paths.get(fileName); + if (!Files.exists(path)) { + Files.createDirectories(path); + } + javaTask.createJavaSourceFileIfNotExists(sourceCode, fileName); + } finally { + Path path = Paths.get(fileName); + if (Files.exists(path)) { + Files.delete(path); + } } - } + }); } /** @@ -152,10 +161,12 @@ public class JavaTaskTest { * * @return void **/ - @Test(expected = PublicClassNotFoundException.class) - public void coverPublicClassNotFoundException() { - JavaTask javaTask = runJavaType(); - javaTask.getPublicClassName(""); + @Test + public void coverPublicClassNotFoundException() { + Assertions.assertThrows(PublicClassNotFoundException.class, () -> { + JavaTask javaTask = runJavaType(); + javaTask.getPublicClassName(""); + }); } /** @@ -164,14 +175,17 @@ public class JavaTaskTest { * @return void * @throws Exception **/ - @Test(expected = RunTypeNotFoundException.class) - public void coverRunTypeNotFoundException() throws Exception { + @Test + public void coverRunTypeNotFoundException() throws Exception { JavaTask javaTask = runJavaType(); Field javaParameters = JavaTask.class.getDeclaredField("javaParameters"); javaParameters.setAccessible(true); - ((JavaParameters)(javaParameters.get(javaTask))).setRunType(""); - javaTask.handle(); - javaTask.getPublicClassName(""); + ((JavaParameters) (javaParameters.get(javaTask))).setRunType(""); + + Assertions.assertThrows(RunTypeNotFoundException.class, () -> { + javaTask.handle(taskCallBack); + javaTask.getPublicClassName(""); + }); } /** @@ -194,7 +208,7 @@ public class JavaTaskTest { resourceInfoArrayList.add(resourceJar); javaParameters.setResourceList(resourceInfoArrayList); javaParameters.setRawScript( - "import java.io.IOException;\n" + + "import java.io.IOException;\n" + "public class JavaTaskTest {\n" + " public static void main(String[] args) throws IOException {\n" + " StringBuilder builder = new StringBuilder(\"Hello: \");\n" + diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-jupyter/src/test/java/org/apache/dolphinscheduler/plugin/task/jupyter/JupyterTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-jupyter/src/test/java/org/apache/dolphinscheduler/plugin/task/jupyter/JupyterTaskTest.java index 1fe03b9640..bcd27f569e 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-jupyter/src/test/java/org/apache/dolphinscheduler/plugin/task/jupyter/JupyterTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-jupyter/src/test/java/org/apache/dolphinscheduler/plugin/task/jupyter/JupyterTaskTest.java @@ -25,13 +25,13 @@ import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.spi.utils.DateUtils; import org.apache.dolphinscheduler.spi.utils.JSONUtils; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class JupyterTaskTest { private static final String EXPECTED_JUPYTER_TASK_COMMAND_USE_LOCAL_CONDA_ENV = @@ -93,7 +93,7 @@ public class JupyterTaskTest { String jupyterTaskParameters = buildJupyterTaskUseLocalCondaEnvCommand(); JupyterTask jupyterTask = prepareJupyterTaskForTest(jupyterTaskParameters); jupyterTask.init(); - Assert.assertEquals(jupyterTask.buildCommand(), EXPECTED_JUPYTER_TASK_COMMAND_USE_LOCAL_CONDA_ENV); + Assertions.assertEquals(jupyterTask.buildCommand(), EXPECTED_JUPYTER_TASK_COMMAND_USE_LOCAL_CONDA_ENV); } @Test @@ -101,7 +101,7 @@ public class JupyterTaskTest { String jupyterTaskParameters = buildJupyterTaskUsePackedCondaEnvCommand(); JupyterTask jupyterTask = prepareJupyterTaskForTest(jupyterTaskParameters); jupyterTask.init(); - Assert.assertEquals(jupyterTask.buildCommand(), EXPECTED_JUPYTER_TASK_COMMAND_USE_PACKED_CONDA_ENV); + Assertions.assertEquals(jupyterTask.buildCommand(), EXPECTED_JUPYTER_TASK_COMMAND_USE_PACKED_CONDA_ENV); } @Test @@ -111,7 +111,7 @@ public class JupyterTaskTest { Mockito.mockStatic(DateUtils.class); when(DateUtils.getTimestampString()).thenReturn("123456789"); jupyterTask.init(); - Assert.assertEquals(jupyterTask.buildCommand(), EXPECTED_JUPYTER_TASK_COMMAND_USE_PIP_REQUIREMENTS); + Assertions.assertEquals(jupyterTask.buildCommand(), EXPECTED_JUPYTER_TASK_COMMAND_USE_PIP_REQUIREMENTS); } private JupyterTask prepareJupyterTaskForTest(final String jupyterTaskParameters) { diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sParametersTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sParametersTest.java index 218b58ed70..4328752351 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sParametersTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sParametersTest.java @@ -16,20 +16,22 @@ */ package org.apache.dolphinscheduler.plugin.task.k8s; + import org.apache.dolphinscheduler.plugin.task.api.parameters.K8sTaskParameters; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class K8sParametersTest { + private K8sTaskParameters k8sTaskParameters = null; private final String image = "ds-dev"; private final String namespace = "{\"name\":\"default\",\"cluster\":\"lab\"}"; private final double minCpuCores = 2; private final double minMemorySpace = 10; - @Before + @BeforeEach public void before() { k8sTaskParameters = new K8sTaskParameters(); k8sTaskParameters.setImage(image); @@ -40,21 +42,21 @@ public class K8sParametersTest { @Test public void testCheckParameterNormal() { - Assert.assertTrue(k8sTaskParameters.checkParameters()); + Assertions.assertTrue(k8sTaskParameters.checkParameters()); } @Test public void testGetResourceFilesListNormal() { - Assert.assertNotNull(k8sTaskParameters.getResourceFilesList()); - Assert.assertEquals(0, k8sTaskParameters.getResourceFilesList().size()); + Assertions.assertNotNull(k8sTaskParameters.getResourceFilesList()); + Assertions.assertEquals(0, k8sTaskParameters.getResourceFilesList().size()); } @Test public void testK8sParameters() { - Assert.assertEquals(image, k8sTaskParameters.getImage()); - Assert.assertEquals(namespace, k8sTaskParameters.getNamespace()); - Assert.assertEquals(0, Double.compare(minCpuCores, k8sTaskParameters.getMinCpuCores())); - Assert.assertEquals(0,Double.compare(minMemorySpace, k8sTaskParameters.getMinMemorySpace())); + Assertions.assertEquals(image, k8sTaskParameters.getImage()); + Assertions.assertEquals(namespace, k8sTaskParameters.getNamespace()); + Assertions.assertEquals(0, Double.compare(minCpuCores, k8sTaskParameters.getMinCpuCores())); + Assertions.assertEquals(0, Double.compare(minMemorySpace, k8sTaskParameters.getMinMemorySpace())); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sTaskTest.java index f28bc2eec3..d6bbd404fe 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sTaskTest.java @@ -27,11 +27,12 @@ import org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.HashMap; import java.util.Map; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class K8sTaskTest { + private K8sTaskParameters k8sTaskParameters = null; private K8sTask k8sTask = null; @@ -47,7 +48,7 @@ public class K8sTaskTest { private final String DAY = "day"; private final String date = "20220507"; - @Before + @BeforeEach public void before() { k8sTaskParameters = new K8sTaskParameters(); k8sTaskParameters.setImage(image); @@ -64,7 +65,7 @@ public class K8sTaskTest { property.setType(DataType.VARCHAR); property.setValue(date); Map paramsMap = new HashMap<>(); - paramsMap.put(DAY,property); + paramsMap.put(DAY, property); taskRequest.setParamsMap(paramsMap); Map prepareParamsMap = new HashMap<>(); @@ -78,16 +79,18 @@ public class K8sTaskTest { @Test public void testBuildCommandNormal() { - String expectedStr = "{\"image\":\"ds-dev\",\"namespaceName\":\"default\",\"clusterName\":\"lab\",\"minCpuCores\":2.0,\"minMemorySpace\":10.0,\"paramsMap\":{\"day\":\"20220507\"}}"; + String expectedStr = + "{\"image\":\"ds-dev\",\"namespaceName\":\"default\",\"clusterName\":\"lab\",\"minCpuCores\":2.0,\"minMemorySpace\":10.0,\"paramsMap\":{\"day\":\"20220507\"}}"; String commandStr = k8sTask.buildCommand(); - Assert.assertEquals(expectedStr, commandStr); + Assertions.assertEquals(expectedStr, commandStr); } @Test public void testGetParametersNormal() { - String expectedStr = "K8sTaskParameters{image='ds-dev', namespace='{\"name\":\"default\",\"cluster\":\"lab\"}', minCpuCores=2.0, minMemorySpace=10.0}"; + String expectedStr = + "K8sTaskParameters{image='ds-dev', namespace='{\"name\":\"default\",\"cluster\":\"lab\"}', minCpuCores=2.0, minMemorySpace=10.0}"; String result = k8sTask.getParameters().toString(); - Assert.assertEquals(expectedStr, result); + Assertions.assertEquals(expectedStr, result); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-mlflow/src/test/java/org/apache/dolphinler/plugin/task/mlflow/MlflowTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-mlflow/src/test/java/org/apache/dolphinler/plugin/task/mlflow/MlflowTaskTest.java index 69775d363a..c49b189d1a 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-mlflow/src/test/java/org/apache/dolphinler/plugin/task/mlflow/MlflowTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-mlflow/src/test/java/org/apache/dolphinler/plugin/task/mlflow/MlflowTaskTest.java @@ -25,29 +25,31 @@ import org.apache.dolphinscheduler.plugin.task.mlflow.MlflowTask; import org.apache.dolphinscheduler.spi.utils.JSONUtils; import org.apache.dolphinscheduler.spi.utils.PropertyUtils; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.MockedStatic; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class MlflowTaskTest { + private static final Logger logger = LoggerFactory.getLogger(MlflowTask.class); private MockedStatic propertyUtilsMockedStatic; - @Before + @BeforeEach public void init() { propertyUtilsMockedStatic = Mockito.mockStatic(PropertyUtils.class); - propertyUtilsMockedStatic.when(() -> PropertyUtils.getString(MlflowConstants.PRESET_REPOSITORY_VERSION_KEY)).thenReturn("main"); + propertyUtilsMockedStatic.when(() -> PropertyUtils.getString(MlflowConstants.PRESET_REPOSITORY_VERSION_KEY)) + .thenReturn("main"); } - @After + @AfterEach public void clean() { propertyUtilsMockedStatic.close(); } @@ -62,60 +64,66 @@ public class MlflowTaskTest { @Test public void testGetPresetRepositoryData() { - Assert.assertEquals("https://github.com/apache/dolphinscheduler-mlflow", MlflowTask.getPresetRepository()); + Assertions.assertEquals("https://github.com/apache/dolphinscheduler-mlflow", MlflowTask.getPresetRepository()); - Assert.assertEquals("main", MlflowTask.getPresetRepositoryVersion()); + Assertions.assertEquals("main", MlflowTask.getPresetRepositoryVersion()); String definedRepository = "https://github.com//dolphinscheduler-mlflow"; - Mockito.when(PropertyUtils.getString(MlflowConstants.PRESET_REPOSITORY_KEY)).thenAnswer(invocation -> definedRepository); - Assert.assertEquals(definedRepository, MlflowTask.getPresetRepository()); + Mockito.when(PropertyUtils.getString(MlflowConstants.PRESET_REPOSITORY_KEY)) + .thenAnswer(invocation -> definedRepository); + Assertions.assertEquals(definedRepository, MlflowTask.getPresetRepository()); String definedRepositoryVersion = "dev"; - Mockito.when(PropertyUtils.getString(MlflowConstants.PRESET_REPOSITORY_VERSION_KEY)).thenAnswer(invocation -> definedRepositoryVersion); - Assert.assertEquals(definedRepositoryVersion, MlflowTask.getPresetRepositoryVersion()); + Mockito.when(PropertyUtils.getString(MlflowConstants.PRESET_REPOSITORY_VERSION_KEY)) + .thenAnswer(invocation -> definedRepositoryVersion); + Assertions.assertEquals(definedRepositoryVersion, MlflowTask.getPresetRepositoryVersion()); } @Test public void testGetVersionString() { - Assert.assertEquals("--version=main", MlflowTask.getVersionString("main", "https://github.com/apache/dolphinscheduler-mlflow")); - Assert.assertEquals("--version=master", MlflowTask.getVersionString("master", "https://github.com/apache/dolphinscheduler-mlflow")); - Assert.assertEquals("--version=main", MlflowTask.getVersionString("main", "git@github.com:apache/dolphinscheduler-mlflow.git")); - Assert.assertEquals("--version=master", MlflowTask.getVersionString("master", "git@github.com:apache/dolphinscheduler-mlflow.git")); - Assert.assertEquals("", MlflowTask.getVersionString("main", "/tmp/dolphinscheduler-mlflow")); - Assert.assertEquals("", MlflowTask.getVersionString("master", "/tmp/dolphinscheduler-mlflow")); + Assertions.assertEquals("--version=main", + MlflowTask.getVersionString("main", "https://github.com/apache/dolphinscheduler-mlflow")); + Assertions.assertEquals("--version=master", + MlflowTask.getVersionString("master", "https://github.com/apache/dolphinscheduler-mlflow")); + Assertions.assertEquals("--version=main", + MlflowTask.getVersionString("main", "git@github.com:apache/dolphinscheduler-mlflow.git")); + Assertions.assertEquals("--version=master", + MlflowTask.getVersionString("master", "git@github.com:apache/dolphinscheduler-mlflow.git")); + Assertions.assertEquals("", MlflowTask.getVersionString("main", "/tmp/dolphinscheduler-mlflow")); + Assertions.assertEquals("", MlflowTask.getVersionString("master", "/tmp/dolphinscheduler-mlflow")); } @Test public void testInitBasicAlgorithmTask() { MlflowTask mlflowTask = initTask(createBasicAlgorithmParameters()); - Assert.assertEquals(mlflowTask.buildCommand(), - "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" - + "data_path=/data/iris.csv\n" - + "repo=https://github.com/apache/dolphinscheduler-mlflow#Project-BasicAlgorithm\n" - + "mlflow run $repo " - + "-P algorithm=xgboost " - + "-P data_path=$data_path " - + "-P params=\"n_estimators=100\" " - + "-P search_params=\"\" " - + "-P model_name=\"BasicAlgorithm\" " - + "--experiment-name=\"BasicAlgorithm\" " - + "--version=main"); + Assertions.assertEquals(mlflowTask.buildCommand(), + "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" + + "data_path=/data/iris.csv\n" + + "repo=https://github.com/apache/dolphinscheduler-mlflow#Project-BasicAlgorithm\n" + + "mlflow run $repo " + + "-P algorithm=xgboost " + + "-P data_path=$data_path " + + "-P params=\"n_estimators=100\" " + + "-P search_params=\"\" " + + "-P model_name=\"BasicAlgorithm\" " + + "--experiment-name=\"BasicAlgorithm\" " + + "--version=main"); } @Test public void testInitAutoMLTask() { MlflowTask mlflowTask = initTask(createAutoMLParameters()); - Assert.assertEquals(mlflowTask.buildCommand(), - "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" - + "data_path=/data/iris.csv\n" - + "repo=https://github.com/apache/dolphinscheduler-mlflow#Project-AutoML\n" - + "mlflow run $repo " - + "-P tool=autosklearn " - + "-P data_path=$data_path " - + "-P params=\"time_left_for_this_task=30\" " - + "-P model_name=\"AutoML\" " - + "--experiment-name=\"AutoML\" " - + "--version=main"); + Assertions.assertEquals(mlflowTask.buildCommand(), + "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" + + "data_path=/data/iris.csv\n" + + "repo=https://github.com/apache/dolphinscheduler-mlflow#Project-AutoML\n" + + "mlflow run $repo " + + "-P tool=autosklearn " + + "-P data_path=$data_path " + + "-P params=\"time_left_for_this_task=30\" " + + "-P model_name=\"AutoML\" " + + "--experiment-name=\"AutoML\" " + + "--version=main"); } @Test @@ -123,58 +131,58 @@ public class MlflowTaskTest { MlflowTask mlflowTask = initTask(createCustomProjectParameters()); // Version will be set if parameter.mlflowProjectVersion is empty - Assert.assertEquals(mlflowTask.buildCommand(), - "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" - + "repo=https://github.com/mlflow/mlflow#examples/xgboost/xgboost_native\n" - + "mlflow run $repo " - + "-P learning_rate=0.2 " - + "-P colsample_bytree=0.8 " - + "-P subsample=0.9 " - + "--experiment-name=\"custom_project\""); + Assertions.assertEquals(mlflowTask.buildCommand(), + "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" + + "repo=https://github.com/mlflow/mlflow#examples/xgboost/xgboost_native\n" + + "mlflow run $repo " + + "-P learning_rate=0.2 " + + "-P colsample_bytree=0.8 " + + "-P subsample=0.9 " + + "--experiment-name=\"custom_project\""); // Version will be set if repository is remote path mlflowTask.getParameters().setMlflowProjectVersion("dev"); - Assert.assertEquals(mlflowTask.buildCommand(), - "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" - + "repo=https://github.com/mlflow/mlflow#examples/xgboost/xgboost_native\n" - + "mlflow run $repo " - + "-P learning_rate=0.2 " - + "-P colsample_bytree=0.8 " - + "-P subsample=0.9 " - + "--experiment-name=\"custom_project\" " - + "--version=dev"); + Assertions.assertEquals(mlflowTask.buildCommand(), + "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" + + "repo=https://github.com/mlflow/mlflow#examples/xgboost/xgboost_native\n" + + "mlflow run $repo " + + "-P learning_rate=0.2 " + + "-P colsample_bytree=0.8 " + + "-P subsample=0.9 " + + "--experiment-name=\"custom_project\" " + + "--version=dev"); // Version will not be set if repository is local path mlflowTask.getParameters().setMlflowProjectRepository("/tmp/dolphinscheduler-mlflow"); - Assert.assertEquals(mlflowTask.buildCommand(), - "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" - + "repo=/tmp/dolphinscheduler-mlflow\n" - + "mlflow run $repo " - + "-P learning_rate=0.2 " - + "-P colsample_bytree=0.8 " - + "-P subsample=0.9 " - + "--experiment-name=\"custom_project\""); + Assertions.assertEquals(mlflowTask.buildCommand(), + "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" + + "repo=/tmp/dolphinscheduler-mlflow\n" + + "mlflow run $repo " + + "-P learning_rate=0.2 " + + "-P colsample_bytree=0.8 " + + "-P subsample=0.9 " + + "--experiment-name=\"custom_project\""); } @Test public void testModelsDeployMlflow() { MlflowTask mlflowTask = initTask(createModelDeplyMlflowParameters()); - Assert.assertEquals(mlflowTask.buildCommand(), - "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" - + "mlflow models serve -m models:/model/1 --port 7000 -h 0.0.0.0"); + Assertions.assertEquals(mlflowTask.buildCommand(), + "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" + + "mlflow models serve -m models:/model/1 --port 7000 -h 0.0.0.0"); } @Test public void testModelsDeployDocker() { MlflowTask mlflowTask = initTask(createModelDeplyDockerParameters()); - Assert.assertEquals(mlflowTask.buildCommand(), - "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" - + "mlflow models build-docker -m models:/model/1 -n mlflow/model:1 --enable-mlserver\n" - + "docker rm -f ds-mlflow-model-1\n" - + "docker run -d --name=ds-mlflow-model-1 -p=7000:8080 " - + "--health-cmd \"curl --fail http://127.0.0.1:8080/ping || exit 1\" --health-interval 5s --health-retries 20 " - + "mlflow/model:1"); + Assertions.assertEquals(mlflowTask.buildCommand(), + "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" + + "mlflow models build-docker -m models:/model/1 -n mlflow/model:1 --enable-mlserver\n" + + "docker rm -f ds-mlflow-model-1\n" + + "docker run -d --name=ds-mlflow-model-1 -p=7000:8080 " + + "--health-cmd \"curl --fail http://127.0.0.1:8080/ping || exit 1\" --health-interval 5s --health-retries 20 " + + "mlflow/model:1"); } private MlflowTask initTask(MlflowParameters mlflowParameters) { diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-openmldb/src/test/java/org/apache/dolphinscheduler/plugin/task/openmldb/OpenmldbTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-openmldb/src/test/java/org/apache/dolphinscheduler/plugin/task/openmldb/OpenmldbTaskTest.java index f66d60d870..aa40a9661a 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-openmldb/src/test/java/org/apache/dolphinscheduler/plugin/task/openmldb/OpenmldbTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-openmldb/src/test/java/org/apache/dolphinscheduler/plugin/task/openmldb/OpenmldbTaskTest.java @@ -25,12 +25,14 @@ import org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.HashMap; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; public class OpenmldbTaskTest { + static class MockOpenmldbTask extends OpenmldbTask { + /** * constructor * @@ -55,7 +57,7 @@ public class OpenmldbTaskTest { OpenmldbTask openmldbTask = createOpenmldbTask(); String pythonFile = "test.py"; String result1 = openmldbTask.buildPythonExecuteCommand(pythonFile); - Assert.assertEquals("python3 test.py", result1); + Assertions.assertEquals("python3 test.py", result1); } @Test @@ -74,21 +76,20 @@ public class OpenmldbTaskTest { OpenmldbTask openmldbTask = new OpenmldbTask(taskExecutionContext); openmldbTask.init(); OpenmldbParameters internal = (OpenmldbParameters) openmldbTask.getParameters(); - Assert.assertNotNull(internal); - Assert.assertEquals(internal.getExecuteMode(), "offline"); + Assertions.assertNotNull(internal); + Assertions.assertEquals(internal.getExecuteMode(), "offline"); String result1 = openmldbTask.buildPythonScriptContent(); - Assert.assertEquals("import openmldb\n" - + "import sqlalchemy as db\n" - + "engine = db.create_engine('openmldb:///?zk=localhost:2181&zkPath=dolphinscheduler')\n" - + "con = engine.connect()\n" - + "con.execute(\"set @@execute_mode='offline';\")\n" - + "con.execute(\"set @@sync_job=true\")\n" - + "con.execute(\"set @@job_timeout=1800000\")\n" - + "con.execute(\"select * from users\\n-- some comment\\ninner join order on users.order_id = " - + "order.id\")\n" - + "con.execute(\"select * from users\")\n" - , result1); + Assertions.assertEquals("import openmldb\n" + + "import sqlalchemy as db\n" + + "engine = db.create_engine('openmldb:///?zk=localhost:2181&zkPath=dolphinscheduler')\n" + + "con = engine.connect()\n" + + "con.execute(\"set @@execute_mode='offline';\")\n" + + "con.execute(\"set @@sync_job=true\")\n" + + "con.execute(\"set @@job_timeout=1800000\")\n" + + "con.execute(\"select * from users\\n-- some comment\\ninner join order on users.order_id = " + + "order.id\")\n" + + "con.execute(\"select * from users\")\n", result1); } -} \ No newline at end of file +} diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-pigeon/src/test/java/org/apache/dolphinscheduler/plugin/task/pigeon/PigeonTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-pigeon/src/test/java/org/apache/dolphinscheduler/plugin/task/pigeon/PigeonTaskTest.java index 679cca1eb7..cf4fd789fe 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-pigeon/src/test/java/org/apache/dolphinscheduler/plugin/task/pigeon/PigeonTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-pigeon/src/test/java/org/apache/dolphinscheduler/plugin/task/pigeon/PigeonTaskTest.java @@ -22,21 +22,20 @@ import static com.github.dreamhead.moco.MocoJsonRunner.jsonHttpServer; import static com.github.dreamhead.moco.Runner.running; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; +import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; import org.apache.commons.io.IOUtils; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Collections; -import java.util.Date; import java.util.Map; import java.util.Objects; import java.util.UUID; -import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,7 +49,7 @@ public class PigeonTaskTest { private TaskExecutionContext taskExecutionContext; - @Before + @BeforeEach public void before() throws Exception { String taskParams = "{\"targetJobName\":\"mysql_elastic\"}"; @@ -80,22 +79,22 @@ public class PigeonTaskTest { public void testGetTISConfigParams() { PigeonConfig cfg = PigeonConfig.getInstance(); String tisHost = "127.0.0.1:8080"; - Assert.assertEquals("http://127.0.0.1:8080/tjs/coredefine/coredefine.ajax", cfg.getJobTriggerUrl(tisHost)); + Assertions.assertEquals("http://127.0.0.1:8080/tjs/coredefine/coredefine.ajax", cfg.getJobTriggerUrl(tisHost)); String jobName = "mysql_elastic"; int taskId = 123; - Assert.assertEquals( + Assertions.assertEquals( "ws://" + tisHost + "/tjs/download/logfeedback?logtype=full&collection=mysql_elastic&taskid=" + taskId, cfg.getJobLogsFetchUrl(tisHost, jobName, taskId)); - Assert.assertEquals("action=datax_action&emethod=trigger_fullbuild_task", cfg.getJobTriggerPostBody()); + Assertions.assertEquals("action=datax_action&emethod=trigger_fullbuild_task", cfg.getJobTriggerPostBody()); - Assert.assertEquals( + Assertions.assertEquals( "http://127.0.0.1:8080/tjs/config/config.ajax?action=collection_action&emethod=get_task_status", cfg.getJobStatusUrl(tisHost)); - Assert.assertEquals("{\n taskid: " + taskId + "\n, log: false }", cfg.getJobStatusPostBody(taskId)); + Assertions.assertEquals("{\n taskid: " + taskId + "\n, log: false }", cfg.getJobStatusPostBody(taskId)); - Assert.assertEquals("action=core_action&event_submit_do_cancel_task=y&taskid=" + taskId, + Assertions.assertEquals("action=core_action&event_submit_do_cancel_task=y&taskid=" + taskId, cfg.getJobCancelPostBody(taskId)); } @@ -104,7 +103,7 @@ public class PigeonTaskTest { try { pigeonTask.init(); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } } @@ -116,7 +115,7 @@ public class PigeonTaskTest { running(server, () -> { pigeonTask.handle(null); - Assert.assertEquals("PIGEON execute be success", TaskExecutionStatus.SUCCESS, pigeonTask.getExitStatus()); + Assertions.assertEquals(TaskExecutionStatus.SUCCESS, pigeonTask.getExitStatus()); }); } @@ -137,7 +136,7 @@ public class PigeonTaskTest { // try { // tisTask.cancelApplication(true); // } catch (Exception e) { - // Assert.fail(e.getMessage()); + // Assertions.fail(e.getMessage()); // } // } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/test/java/org/apache/dolphinscheduler/plugin/task/python/PythonTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/test/java/org/apache/dolphinscheduler/plugin/task/python/PythonTaskTest.java index ea27ef7d3c..6abcabe4fc 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/test/java/org/apache/dolphinscheduler/plugin/task/python/PythonTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/test/java/org/apache/dolphinscheduler/plugin/task/python/PythonTaskTest.java @@ -17,18 +17,18 @@ package org.apache.dolphinscheduler.plugin.task.python; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class PythonTaskTest { @Test public void buildPythonExecuteCommand() throws Exception { PythonTask pythonTask = createPythonTask(); - Assert.assertEquals("${PYTHON_HOME} test.py", pythonTask.buildPythonExecuteCommand("test.py")); + Assertions.assertEquals("${PYTHON_HOME} test.py", pythonTask.buildPythonExecuteCommand("test.py")); } private PythonTask createPythonTask() { return new PythonTask(null); } -} \ No newline at end of file +} diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-pytorch/src/test/java/org/apache/dolphinscheduler/plugin/task/pytorch/PytorchTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-pytorch/src/test/java/org/apache/dolphinscheduler/plugin/task/pytorch/PytorchTaskTest.java index e0c2938249..cc38f60b2b 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-pytorch/src/test/java/org/apache/dolphinscheduler/plugin/task/pytorch/PytorchTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-pytorch/src/test/java/org/apache/dolphinscheduler/plugin/task/pytorch/PytorchTaskTest.java @@ -18,13 +18,10 @@ package org.apache.dolphinscheduler.plugin.task.pytorch; import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.RWXR_XR_X; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContextCacheManager; import org.apache.dolphinscheduler.spi.utils.JSONUtils; -import org.apache.dolphinscheduler.spi.utils.PropertyUtils; import org.apache.commons.lang3.SystemUtils; @@ -36,18 +33,16 @@ import java.nio.file.Paths; import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermissions; -import java.util.Date; import java.util.Set; import java.util.UUID; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class PytorchTaskTest { private final String pythonPath = "."; @@ -60,37 +55,42 @@ public class PytorchTaskTest { envManager.setPythonEnvTool(PythonEnvManager.ENV_TOOL_CONDA); envManager.setCondaPythonVersion("3.9"); String condaEnvCommand39 = envManager.getBuildEnvCommand(requirementPath); - Assert.assertEquals(condaEnvCommand39, "conda create -y python=3.9 -p ./venv && source activate ./venv && ./venv/bin/python -m pip install -r " + requirementPath); + Assertions.assertEquals(condaEnvCommand39, + "conda create -y python=3.9 -p ./venv && source activate ./venv && ./venv/bin/python -m pip install -r " + + requirementPath); envManager.setCondaPythonVersion("3.8"); String condaEnvCommand38 = envManager.getBuildEnvCommand(requirementPath); - Assert.assertEquals(condaEnvCommand38, "conda create -y python=3.8 -p ./venv && source activate ./venv && ./venv/bin/python -m pip install -r " + requirementPath); - + Assertions.assertEquals(condaEnvCommand38, + "conda create -y python=3.8 -p ./venv && source activate ./venv && ./venv/bin/python -m pip install -r " + + requirementPath); envManager.setPythonEnvTool(PythonEnvManager.ENV_TOOL_VENV); String venvEnvCommand = envManager.getBuildEnvCommand(requirementPath); - Assert.assertEquals(venvEnvCommand, "virtualenv -p ${PYTHON_HOME} ./venv && source ./venv/bin/activate && ./venv/bin/python -m pip install -r " + requirementPath); + Assertions.assertEquals(venvEnvCommand, + "virtualenv -p ${PYTHON_HOME} ./venv && source ./venv/bin/activate && ./venv/bin/python -m pip install -r " + + requirementPath); } @Test public void testGitProject() { - assertFalse(GitProjectManager.isGitPath("dolphinscheduler/test")); - assertFalse(GitProjectManager.isGitPath("/dolphinscheduler/test")); - assertTrue(GitProjectManager.isGitPath("https://github.com/apache/dolphinscheduler.git")); - assertTrue(GitProjectManager.isGitPath("git@github.com:apache/dolphinscheduler.git")); - assertTrue(GitProjectManager.isGitPath("git@github.com:apache/dolphinscheduler.git#doc")); + Assertions.assertFalse(GitProjectManager.isGitPath("dolphinscheduler/test")); + Assertions.assertFalse(GitProjectManager.isGitPath("/dolphinscheduler/test")); + Assertions.assertTrue(GitProjectManager.isGitPath("https://github.com/apache/dolphinscheduler.git")); + Assertions.assertTrue(GitProjectManager.isGitPath("git@github.com:apache/dolphinscheduler.git")); + Assertions.assertTrue(GitProjectManager.isGitPath("git@github.com:apache/dolphinscheduler.git#doc")); GitProjectManager gpm1 = new GitProjectManager(); gpm1.setPath("git@github.com:apache/dolphinscheduler.git#doc"); - Assert.assertEquals("git@github.com:apache/dolphinscheduler.git", gpm1.getGitUrl()); - Assert.assertEquals("./GIT_PROJECT/doc", gpm1.getGitLocalPath()); + Assertions.assertEquals("git@github.com:apache/dolphinscheduler.git", gpm1.getGitUrl()); + Assertions.assertEquals("./GIT_PROJECT/doc", gpm1.getGitLocalPath()); GitProjectManager gpm2 = new GitProjectManager(); gpm2.setPath("git@github.com:apache/dolphinscheduler.git"); - Assert.assertEquals("git@github.com:apache/dolphinscheduler.git", gpm2.getGitUrl()); - Assert.assertEquals("./GIT_PROJECT", gpm2.getGitLocalPath()); + Assertions.assertEquals("git@github.com:apache/dolphinscheduler.git", gpm2.getGitUrl()); + Assertions.assertEquals("./GIT_PROJECT", gpm2.getGitLocalPath()); } @@ -101,25 +101,24 @@ public class PytorchTaskTest { parameters.setScriptParams("--epochs=1 --dry-run"); PytorchTask task1 = initTask(parameters); - Assert.assertEquals(task1.buildPythonExecuteCommand(), - "export PYTHONPATH=.\n" + - "${PYTHON_HOME} main.py --epochs=1 --dry-run"); + Assertions.assertEquals(task1.buildPythonExecuteCommand(), + "export PYTHONPATH=.\n" + + "${PYTHON_HOME} main.py --epochs=1 --dry-run"); parameters.setPythonCommand(""); PytorchTask task2 = initTask(parameters); - Assert.assertEquals(task2.buildPythonExecuteCommand(), - "export PYTHONPATH=.\n" + - "${PYTHON_HOME} main.py --epochs=1 --dry-run"); + Assertions.assertEquals(task2.buildPythonExecuteCommand(), + "export PYTHONPATH=.\n" + + "${PYTHON_HOME} main.py --epochs=1 --dry-run"); parameters.setPythonCommand("/usr/bin/python"); PytorchTask task3 = initTask(parameters); - Assert.assertEquals(task3.buildPythonExecuteCommand(), - "export PYTHONPATH=.\n" + - "/usr/bin/python main.py --epochs=1 --dry-run"); + Assertions.assertEquals(task3.buildPythonExecuteCommand(), + "export PYTHONPATH=.\n" + + "/usr/bin/python main.py --epochs=1 --dry-run"); } - @Test public void testBuildPythonCommandWithCreateCondeEnv() throws Exception { PytorchParameters parameters = new PytorchParameters(); @@ -132,10 +131,11 @@ public class PytorchTaskTest { parameters.setScriptParams("--epochs=1 --dry-run"); PytorchTask task = initTask(parameters); - Assert.assertEquals(task.buildPythonExecuteCommand(), - "export PYTHONPATH=.\n" + - "conda create -y python=3.6 -p ./venv && source activate ./venv && ./venv/bin/python -m pip install -r requirements.txt\n" + - "./venv/bin/python main.py --epochs=1 --dry-run"); + Assertions.assertEquals(task.buildPythonExecuteCommand(), + "export PYTHONPATH=.\n" + + "conda create -y python=3.6 -p ./venv && source activate ./venv && ./venv/bin/python -m pip install -r requirements.txt\n" + + + "./venv/bin/python main.py --epochs=1 --dry-run"); } @Test @@ -149,10 +149,11 @@ public class PytorchTaskTest { parameters.setScriptParams("--epochs=1 --dry-run"); PytorchTask task = initTask(parameters); - Assert.assertEquals(task.buildPythonExecuteCommand(), - "export PYTHONPATH=.\n" + - "virtualenv -p ${PYTHON_HOME} ./venv && source ./venv/bin/activate && ./venv/bin/python -m pip install -r requirements.txt\n" + - "./venv/bin/python main.py --epochs=1 --dry-run"); + Assertions.assertEquals(task.buildPythonExecuteCommand(), + "export PYTHONPATH=.\n" + + "virtualenv -p ${PYTHON_HOME} ./venv && source ./venv/bin/activate && ./venv/bin/python -m pip install -r requirements.txt\n" + + + "./venv/bin/python main.py --epochs=1 --dry-run"); } @@ -177,14 +178,15 @@ public class PytorchTaskTest { createFile(scriptFile); String expected = "export PYTHONPATH=%s\n" + - "virtualenv -p ${PYTHON_HOME} ./venv && source ./venv/bin/activate && ./venv/bin/python -m pip install -r %s\n" + - "./venv/bin/python %s"; + "virtualenv -p ${PYTHON_HOME} ./venv && source ./venv/bin/activate && ./venv/bin/python -m pip install -r %s\n" + + + "./venv/bin/python %s"; System.out.println(task.buildPythonExecuteCommand()); - Assert.assertEquals(String.format(expected, pythonPath, requirementFile, scriptFile), task.buildPythonExecuteCommand()); + Assertions.assertEquals(String.format(expected, pythonPath, requirementFile, scriptFile), + task.buildPythonExecuteCommand()); } - private PytorchTask initTask(PytorchParameters pytorchParameters) { TaskExecutionContext taskExecutionContext = createContext(pytorchParameters); PytorchTask task = new PytorchTask(taskExecutionContext); @@ -221,5 +223,3 @@ public class PytorchTaskTest { } } - - diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-sagemaker/src/test/java/org/apache/dolphinscheduler/plugin/task/sagemaker/SagemakerTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-sagemaker/src/test/java/org/apache/dolphinscheduler/plugin/task/sagemaker/SagemakerTaskTest.java index f29a7cc36e..f91236be2a 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-sagemaker/src/test/java/org/apache/dolphinscheduler/plugin/task/sagemaker/SagemakerTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-sagemaker/src/test/java/org/apache/dolphinscheduler/plugin/task/sagemaker/SagemakerTaskTest.java @@ -27,12 +27,12 @@ import org.apache.commons.io.IOUtils; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import com.amazonaws.services.sagemaker.AmazonSageMaker; import com.amazonaws.services.sagemaker.model.DescribePipelineExecutionResult; @@ -40,7 +40,7 @@ import com.amazonaws.services.sagemaker.model.StartPipelineExecutionRequest; import com.amazonaws.services.sagemaker.model.StartPipelineExecutionResult; import com.amazonaws.services.sagemaker.model.StopPipelineExecutionResult; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SagemakerTaskTest { private final String pipelineExecutionArn = "test-pipeline-arn"; @@ -49,7 +49,7 @@ public class SagemakerTaskTest { private AmazonSageMaker client; private PipelineUtils pipelineUtils = new PipelineUtils(); - @Before + @BeforeEach public void before() { String parameters = buildParameters(); TaskExecutionContext taskExecutionContext = Mockito.mock(TaskExecutionContext.class); @@ -60,35 +60,38 @@ public class SagemakerTaskTest { sagemakerTask.init(); StartPipelineExecutionResult startPipelineExecutionResult = Mockito.mock(StartPipelineExecutionResult.class); - Mockito.when(startPipelineExecutionResult.getPipelineExecutionArn()).thenReturn(pipelineExecutionArn); + Mockito.lenient().when(startPipelineExecutionResult.getPipelineExecutionArn()).thenReturn(pipelineExecutionArn); StopPipelineExecutionResult stopPipelineExecutionResult = Mockito.mock(StopPipelineExecutionResult.class); - Mockito.when(stopPipelineExecutionResult.getPipelineExecutionArn()).thenReturn(pipelineExecutionArn); + Mockito.lenient().when(stopPipelineExecutionResult.getPipelineExecutionArn()).thenReturn(pipelineExecutionArn); - DescribePipelineExecutionResult describePipelineExecutionResult = Mockito.mock(DescribePipelineExecutionResult.class); - Mockito.when(describePipelineExecutionResult.getPipelineExecutionStatus()).thenReturn("Executing", "Succeeded"); + DescribePipelineExecutionResult describePipelineExecutionResult = + Mockito.mock(DescribePipelineExecutionResult.class); + Mockito.lenient().when(describePipelineExecutionResult.getPipelineExecutionStatus()).thenReturn("Executing", + "Succeeded"); - Mockito.when(client.startPipelineExecution(any())).thenReturn(startPipelineExecutionResult); - Mockito.when(client.stopPipelineExecution(any())).thenReturn(stopPipelineExecutionResult); - Mockito.when(client.describePipelineExecution(any())).thenReturn(describePipelineExecutionResult); + Mockito.lenient().when(client.startPipelineExecution(any())).thenReturn(startPipelineExecutionResult); + Mockito.lenient().when(client.stopPipelineExecution(any())).thenReturn(stopPipelineExecutionResult); + Mockito.lenient().when(client.describePipelineExecution(any())).thenReturn(describePipelineExecutionResult); } @Test public void testStartPipelineRequest() throws Exception { StartPipelineExecutionRequest request = sagemakerTask.createStartPipelineRequest(); - Assert.assertEquals("AbalonePipeline", request.getPipelineName()); - Assert.assertEquals("test Pipeline", request.getPipelineExecutionDescription()); - Assert.assertEquals("AbalonePipeline", request.getPipelineExecutionDisplayName()); - Assert.assertEquals("AbalonePipeline", request.getPipelineName()); - Assert.assertEquals(new Integer(1), request.getParallelismConfiguration().getMaxParallelExecutionSteps()); + Assertions.assertEquals("AbalonePipeline", request.getPipelineName()); + Assertions.assertEquals("test Pipeline", request.getPipelineExecutionDescription()); + Assertions.assertEquals("AbalonePipeline", request.getPipelineExecutionDisplayName()); + Assertions.assertEquals("AbalonePipeline", request.getPipelineName()); + Assertions.assertEquals(Integer.valueOf(1), + request.getParallelismConfiguration().getMaxParallelExecutionSteps()); } @Test public void testPipelineExecution() throws Exception { PipelineUtils.PipelineId pipelineId = pipelineUtils.startPipelineExecution(client, sagemakerTask.createStartPipelineRequest()); - Assert.assertEquals(pipelineExecutionArn, pipelineId.getPipelineExecutionArn()); - Assert.assertEquals(0, pipelineUtils.checkPipelineExecutionStatus(client, pipelineId)); + Assertions.assertEquals(pipelineExecutionArn, pipelineId.getPipelineExecutionArn()); + Assertions.assertEquals(0, pipelineUtils.checkPipelineExecutionStatus(client, pipelineId)); pipelineUtils.stopPipelineExecution(client, pipelineId); } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-spark/src/test/java/org/apache/dolphinscheduler/plugin/task/spark/SparkParametersTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-spark/src/test/java/org/apache/dolphinscheduler/plugin/task/spark/SparkParametersTest.java index 286bcbc0ba..42c1f5ccf1 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-spark/src/test/java/org/apache/dolphinscheduler/plugin/task/spark/SparkParametersTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-spark/src/test/java/org/apache/dolphinscheduler/plugin/task/spark/SparkParametersTest.java @@ -22,15 +22,15 @@ import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo; import java.util.LinkedList; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class SparkParametersTest { @Test public void getResourceFilesList() { SparkParameters sparkParameters = new SparkParameters(); - Assert.assertTrue(sparkParameters.getResourceFilesList().isEmpty()); + Assertions.assertTrue(sparkParameters.getResourceFilesList().isEmpty()); ResourceInfo mainResource = new ResourceInfo(); mainResource.setRes("testSparkMain-1.0.0-SNAPSHOT.jar\""); @@ -43,8 +43,8 @@ public class SparkParametersTest { sparkParameters.setResourceList(resourceInfos); List resourceFilesList = sparkParameters.getResourceFilesList(); - Assert.assertNotNull(resourceFilesList); - Assert.assertEquals(2, resourceFilesList.size()); + Assertions.assertNotNull(resourceFilesList); + Assertions.assertEquals(2, resourceFilesList.size()); ResourceInfo resourceInfo2 = new ResourceInfo(); resourceInfo2.setRes("testSparkParameters2.jar"); @@ -52,8 +52,8 @@ public class SparkParametersTest { sparkParameters.setResourceList(resourceInfos); resourceFilesList = sparkParameters.getResourceFilesList(); - Assert.assertNotNull(resourceFilesList); - Assert.assertEquals(3, resourceFilesList.size()); + Assertions.assertNotNull(resourceFilesList); + Assertions.assertEquals(3, resourceFilesList.size()); } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-spark/src/test/java/org/apache/dolphinscheduler/plugin/task/spark/SparkTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-spark/src/test/java/org/apache/dolphinscheduler/plugin/task/spark/SparkTaskTest.java index e9a935e1a8..78259716b4 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-spark/src/test/java/org/apache/dolphinscheduler/plugin/task/spark/SparkTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-spark/src/test/java/org/apache/dolphinscheduler/plugin/task/spark/SparkTaskTest.java @@ -23,13 +23,13 @@ import org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.Collections; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SparkTaskTest { @Test @@ -42,7 +42,7 @@ public class SparkTaskTest { SparkTask sparkTask = Mockito.spy(new SparkTask(taskExecutionContext)); sparkTask.init(); - Assert.assertEquals(sparkTask.buildCommand(), + Assertions.assertEquals(sparkTask.buildCommand(), "${SPARK_HOME}/bin/spark-sql " + "--master yarn " + "--deploy-mode client " + @@ -62,7 +62,7 @@ public class SparkTaskTest { Mockito.when(taskExecutionContext.getTaskParams()).thenReturn(parameters); SparkTask sparkTask = Mockito.spy(new SparkTask(taskExecutionContext)); sparkTask.init(); - Assert.assertEquals(sparkTask.buildCommand(), + Assertions.assertEquals(sparkTask.buildCommand(), "${SPARK_HOME}/bin/spark-submit " + "--master yarn " + "--deploy-mode client " + diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-sqoop/src/test/java/org/apache/dolphinscheduler/plugin/task/sqoop/SqoopParameterEntityTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-sqoop/src/test/java/org/apache/dolphinscheduler/plugin/task/sqoop/SqoopParameterEntityTest.java index 2b120c001d..1695edaada 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-sqoop/src/test/java/org/apache/dolphinscheduler/plugin/task/sqoop/SqoopParameterEntityTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-sqoop/src/test/java/org/apache/dolphinscheduler/plugin/task/sqoop/SqoopParameterEntityTest.java @@ -24,12 +24,12 @@ import org.apache.dolphinscheduler.plugin.task.sqoop.parameter.sources.SourceMys import org.apache.dolphinscheduler.plugin.task.sqoop.parameter.targets.TargetHdfsParameter; import org.apache.dolphinscheduler.plugin.task.sqoop.parameter.targets.TargetHiveParameter; import org.apache.dolphinscheduler.plugin.task.sqoop.parameter.targets.TargetMysqlParameter; + import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * sqoop parameter entity test diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/test/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/test/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTaskTest.java index b33b4d43ff..4a6f305f10 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/test/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/test/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTaskTest.java @@ -39,16 +39,16 @@ import org.apache.zeppelin.client.ZeppelinClient; import java.util.Map; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import com.fasterxml.jackson.databind.ObjectMapper; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ZeppelinTaskTest { private static final String MOCK_NOTE_ID = "2GYJR92R7"; @@ -67,7 +67,7 @@ public class ZeppelinTaskTest { }; - @Before + @BeforeEach public void before() throws Exception { String zeppelinParameters = buildZeppelinTaskParameters(); TaskExecutionContext taskExecutionContext = mock(TaskExecutionContext.class); @@ -78,13 +78,14 @@ public class ZeppelinTaskTest { this.paragraphResult = mock(ParagraphResult.class); doReturn(this.zClient).when(this.zeppelinTask).getZeppelinClient(); - when(this.zClient.executeParagraph(any(), any(), any(Map.class))).thenReturn(this.paragraphResult); - when(paragraphResult.getResultInText()).thenReturn("mock-zeppelin-paragraph-execution-result"); + this.zeppelinTask.init(); } @Test public void testHandleWithParagraphExecutionSuccess() throws Exception { + when(this.zClient.executeParagraph(any(), any(), any(Map.class))).thenReturn(this.paragraphResult); + when(paragraphResult.getResultInText()).thenReturn("mock-zeppelin-paragraph-execution-result"); when(this.paragraphResult.getStatus()).thenReturn(Status.FINISHED); this.zeppelinTask.handle(taskCallBack); Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID, @@ -92,45 +93,56 @@ public class ZeppelinTaskTest { (Map) mapper.readValue(MOCK_PARAMETERS, Map.class)); Mockito.verify(this.paragraphResult).getResultInText(); Mockito.verify(this.paragraphResult).getStatus(); - Assert.assertEquals(EXIT_CODE_SUCCESS, this.zeppelinTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, this.zeppelinTask.getExitStatusCode()); } @Test public void testHandleWithParagraphExecutionAborted() throws Exception { + when(this.zClient.executeParagraph(any(), any(), any(Map.class))).thenReturn(this.paragraphResult); + when(paragraphResult.getResultInText()).thenReturn("mock-zeppelin-paragraph-execution-result"); when(this.paragraphResult.getStatus()).thenReturn(Status.ABORT); + this.zeppelinTask.handle(taskCallBack); + Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID, MOCK_PARAGRAPH_ID, (Map) mapper.readValue(MOCK_PARAMETERS, Map.class)); Mockito.verify(this.paragraphResult).getResultInText(); Mockito.verify(this.paragraphResult).getStatus(); - Assert.assertEquals(EXIT_CODE_KILL, this.zeppelinTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_KILL, this.zeppelinTask.getExitStatusCode()); } @Test public void testHandleWithParagraphExecutionError() throws Exception { + when(this.zClient.executeParagraph(any(), any(), any(Map.class))).thenReturn(this.paragraphResult); + when(paragraphResult.getResultInText()).thenReturn("mock-zeppelin-paragraph-execution-result"); when(this.paragraphResult.getStatus()).thenReturn(Status.ERROR); + this.zeppelinTask.handle(taskCallBack); + Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID, MOCK_PARAGRAPH_ID, (Map) mapper.readValue(MOCK_PARAMETERS, Map.class)); Mockito.verify(this.paragraphResult).getResultInText(); Mockito.verify(this.paragraphResult).getStatus(); - Assert.assertEquals(EXIT_CODE_FAILURE, this.zeppelinTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_FAILURE, this.zeppelinTask.getExitStatusCode()); } - @Test(expected = TaskException.class) + @Test public void testHandleWithParagraphExecutionException() throws Exception { when(this.zClient.executeParagraph(any(), any(), any(Map.class))) .thenThrow(new TaskException("Something wrong happens from zeppelin side")); - this.zeppelinTask.handle(taskCallBack); + + Assertions.assertThrows(TaskException.class, () -> { + this.zeppelinTask.handle(taskCallBack); + }); Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID, MOCK_PARAGRAPH_ID, (Map) mapper.readValue(MOCK_PARAMETERS, Map.class)); Mockito.verify(this.paragraphResult, Mockito.times(0)).getResultInText(); Mockito.verify(this.paragraphResult, Mockito.times(0)).getStatus(); - Assert.assertEquals(EXIT_CODE_FAILURE, this.zeppelinTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_FAILURE, this.zeppelinTask.getExitStatusCode()); } @Test @@ -139,19 +151,18 @@ public class ZeppelinTaskTest { TaskExecutionContext taskExecutionContext = mock(TaskExecutionContext.class); when(taskExecutionContext.getTaskParams()).thenReturn(zeppelinParametersWithNoParagraphId); this.zeppelinTask = spy(new ZeppelinTask(taskExecutionContext)); - this.zClient = mock(ZeppelinClient.class); this.noteResult = mock(NoteResult.class); - doReturn(this.zClient).when(this.zeppelinTask).getZeppelinClient(); when(this.zClient.executeNote(any(), any(Map.class))).thenReturn(this.noteResult); + this.zeppelinTask.init(); this.zeppelinTask.handle(taskCallBack); Mockito.verify(this.zClient).executeNote(MOCK_NOTE_ID, (Map) mapper.readValue(MOCK_PARAMETERS, Map.class)); Mockito.verify(this.noteResult).getParagraphResultList(); - Assert.assertEquals(EXIT_CODE_SUCCESS, this.zeppelinTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, this.zeppelinTask.getExitStatusCode()); } @Test @@ -159,18 +170,19 @@ public class ZeppelinTaskTest { String zeppelinParametersWithNoParagraphId = buildZeppelinTaskParametersWithProductionSetting(); TaskExecutionContext taskExecutionContext = mock(TaskExecutionContext.class); Mockito.mockStatic(DateUtils.class); + when(DateUtils.getTimestampString()).thenReturn("123456789"); when(taskExecutionContext.getTaskParams()).thenReturn(zeppelinParametersWithNoParagraphId); this.zeppelinTask = spy(new ZeppelinTask(taskExecutionContext)); - this.zClient = mock(ZeppelinClient.class); this.noteResult = mock(NoteResult.class); doReturn(this.zClient).when(this.zeppelinTask).getZeppelinClient(); when(this.zClient.cloneNote(any(String.class), any(String.class))).thenReturn(MOCK_CLONE_NOTE_ID); when(this.zClient.executeNote(any(), any(Map.class))).thenReturn(this.noteResult); + this.zeppelinTask.init(); - when(DateUtils.getTimestampString()).thenReturn("123456789"); this.zeppelinTask.handle(taskCallBack); + Mockito.verify(this.zClient).cloneNote( MOCK_NOTE_ID, String.format("%s%s_%s", MOCK_PRODUCTION_DIRECTORY, MOCK_NOTE_ID, "123456789")); @@ -178,7 +190,7 @@ public class ZeppelinTaskTest { (Map) mapper.readValue(MOCK_PARAMETERS, Map.class)); Mockito.verify(this.noteResult).getParagraphResultList(); Mockito.verify(this.zClient).deleteNote(MOCK_CLONE_NOTE_ID); - Assert.assertEquals(EXIT_CODE_SUCCESS, this.zeppelinTask.getExitStatusCode()); + Assertions.assertEquals(EXIT_CODE_SUCCESS, this.zeppelinTask.getExitStatusCode()); } private String buildZeppelinTaskParameters() {