From a96ac1a407b91f73a963b92e45971130ab831d1b Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Sat, 27 Apr 2024 10:37:22 +0800 Subject: [PATCH 1/2] Improve test code checkstyle --- .../alert/AlerterWorkerPoolTest.java | 3 +- .../controller/AlertDefineControllerTest.java | 12 ++-- .../AlertDefinesControllerTest.java | 18 ++++-- .../controller/AlertReportControllerTest.java | 7 +- .../controller/AlertsControllerTest.java | 17 +++-- .../alert/service/AlertDefineServiceTest.java | 21 ++++-- .../alert/util/AlertTemplateUtilTest.java | 9 ++- .../collect/ftp/FtpCollectImplTest.java | 1 - .../exporter/ExporterParserTest.java | 64 +++++++++---------- .../dispatch/unit/TimeLengthConvertTest.java | 3 +- .../collector/util/CollectUtilTest.java | 21 +++--- .../collector/util/PrivateKeyUtilsTest.java | 57 ++++++++--------- .../config/AviatorConfigurationTest.java | 5 +- .../hertzbeat/common/util/CommonUtilTest.java | 13 ++-- .../common/util/IpDomainUtilTest.java | 3 +- .../hertzbeat/common/util/JsonUtilTest.java | 5 +- .../apache/hertzbeat/manager/ManagerTest.java | 10 ++- ...ngTalkRobotAlertNotifyHandlerImplTest.java | 31 +++++---- .../DiscordBotAlertNotifyHandlerImplTest.java | 27 ++++---- .../FlyBookAlertNotifyHandlerImplTest.java | 29 ++++----- ...weiCloudSmnAlertNotifyHandlerImplTest.java | 25 ++++---- .../impl/SlackAlertNotifyHandlerImplTest.java | 29 ++++----- ...TelegramBotAlertNotifyHandlerImplTest.java | 31 +++++---- .../WeChatAppAlertNotifyHandlerImplTest.java | 9 ++- ...WeWorkRobotAlertNotifyHandlerImplTest.java | 29 ++++----- .../controller/AccountControllerTest.java | 7 +- .../manager/controller/AppControllerTest.java | 16 ++--- .../controller/I18nControllerTest.java | 6 +- .../controller/MonitorControllerTest.java | 12 ++-- .../controller/MonitorsControllerTest.java | 10 ++- .../NoticeConfigControllerTest.java | 31 +++++---- .../controller/SummaryControllerTest.java | 10 ++- .../manager/controller/TagControllerTest.java | 15 ++--- .../hertzbeat/manager/dao/MonitorDaoTest.java | 19 ++++-- .../manager/dao/NoticeRuleDaoTest.java | 14 ++-- .../hertzbeat/manager/dao/ParamDaoTest.java | 16 ++--- .../manager/dao/ParamDefineDaoTest.java | 15 ++--- .../hertzbeat/manager/dao/TagDaoTest.java | 20 +++--- .../manager/service/AppServiceTest.java | 13 ++-- .../manager/service/MailServiceTest.java | 20 +++--- .../manager/service/MonitorServiceTest.java | 47 +++++++++----- .../service/NoticeConfigServiceTest.java | 25 ++++---- .../manager/service/TagServiceTest.java | 20 +++--- .../remoting/RemotingServiceTest.java | 4 +- .../warehouse/WarehouseWorkerPoolTest.java | 1 - .../controller/MetricsDataControllerTest.java | 24 +++---- 46 files changed, 406 insertions(+), 418 deletions(-) diff --git a/alerter/src/test/java/org/apache/hertzbeat/alert/AlerterWorkerPoolTest.java b/alerter/src/test/java/org/apache/hertzbeat/alert/AlerterWorkerPoolTest.java index 1d4a1de6005..442c0873ab4 100644 --- a/alerter/src/test/java/org/apache/hertzbeat/alert/AlerterWorkerPoolTest.java +++ b/alerter/src/test/java/org/apache/hertzbeat/alert/AlerterWorkerPoolTest.java @@ -18,7 +18,6 @@ package org.apache.hertzbeat.alert; import static org.junit.jupiter.api.Assertions.assertEquals; - import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; import org.junit.jupiter.api.BeforeEach; @@ -31,7 +30,7 @@ class AlerterWorkerPoolTest { private static final int NUMBER_OF_THREADS = 10; - private AlerterWorkerPool pool ; + private AlerterWorkerPool pool; private AtomicInteger counter; private CountDownLatch latch; diff --git a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefineControllerTest.java b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefineControllerTest.java index d8aae059756..fa2fe11c615 100644 --- a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefineControllerTest.java +++ b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefineControllerTest.java @@ -17,11 +17,15 @@ package org.apache.hertzbeat.alert.controller; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.util.Collections; +import java.util.List; import org.apache.hertzbeat.alert.service.impl.AlertDefineServiceImpl; +import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.alerter.AlertDefine; import org.apache.hertzbeat.common.entity.alerter.AlertDefineMonitorBind; import org.apache.hertzbeat.common.entity.manager.Monitor; -import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.util.JsonUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,12 +39,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import java.util.Collections; -import java.util.List; - -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - /** * Test case for {@link AlertDefineController} */ diff --git a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefinesControllerTest.java b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefinesControllerTest.java index 58239f9b66d..551c5a12caa 100644 --- a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefinesControllerTest.java +++ b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefinesControllerTest.java @@ -17,9 +17,19 @@ package org.apache.hertzbeat.alert.controller; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.hertzbeat.alert.service.AlertDefineService; -import org.apache.hertzbeat.common.entity.alerter.AlertDefine; import org.apache.hertzbeat.common.constants.CommonConstants; +import org.apache.hertzbeat.common.entity.alerter.AlertDefine; import org.apache.hertzbeat.common.util.JsonUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,12 +46,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - /** * Test case for {@link AlertDefinesController} * Test whether the data mocked at the mock is correct, and test whether the format of the returned data is correct diff --git a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertReportControllerTest.java b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertReportControllerTest.java index 2666364bc11..cb7f4e04588 100644 --- a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertReportControllerTest.java +++ b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertReportControllerTest.java @@ -17,6 +17,9 @@ package org.apache.hertzbeat.alert.controller; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import org.apache.hertzbeat.alert.dto.GeneralCloudAlertReport; import org.apache.hertzbeat.alert.dto.TenCloudAlertReport; import org.apache.hertzbeat.alert.service.AlertService; @@ -33,10 +36,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - /** * unit test for {@link AlertReportController } */ diff --git a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertsControllerTest.java b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertsControllerTest.java index 144595f71ae..c35ee78f02b 100644 --- a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertsControllerTest.java +++ b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertsControllerTest.java @@ -17,10 +17,17 @@ package org.apache.hertzbeat.alert.controller; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.LongStream; import org.apache.hertzbeat.alert.dto.AlertSummary; import org.apache.hertzbeat.alert.service.AlertService; -import org.apache.hertzbeat.common.entity.alerter.Alert; import org.apache.hertzbeat.common.constants.CommonConstants; +import org.apache.hertzbeat.common.entity.alerter.Alert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -37,13 +44,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.LongStream; - -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - /** * Test case for {@link AlertsController} */ @@ -67,7 +67,6 @@ void setUp() { ids = LongStream.rangeClosed(1, 10).boxed().collect(Collectors.toList()); } -// @Test // todo: fix this test void getAlerts() throws Exception { String sortField = "id"; diff --git a/alerter/src/test/java/org/apache/hertzbeat/alert/service/AlertDefineServiceTest.java b/alerter/src/test/java/org/apache/hertzbeat/alert/service/AlertDefineServiceTest.java index acbc20dc81c..cf9d655f559 100644 --- a/alerter/src/test/java/org/apache/hertzbeat/alert/service/AlertDefineServiceTest.java +++ b/alerter/src/test/java/org/apache/hertzbeat/alert/service/AlertDefineServiceTest.java @@ -17,6 +17,19 @@ package org.apache.hertzbeat.alert.service; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.anySet; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.when; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; import org.apache.hertzbeat.alert.dao.AlertDefineBindDao; import org.apache.hertzbeat.alert.dao.AlertDefineDao; import org.apache.hertzbeat.alert.service.impl.AlertDefineServiceImpl; @@ -26,18 +39,14 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.*; +import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.Specification; import org.springframework.test.util.ReflectionTestUtils; -import java.util.*; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - /** * Test case for {@link AlertDefineService} */ diff --git a/alerter/src/test/java/org/apache/hertzbeat/alert/util/AlertTemplateUtilTest.java b/alerter/src/test/java/org/apache/hertzbeat/alert/util/AlertTemplateUtilTest.java index cdff331b5d9..096a76e22ee 100644 --- a/alerter/src/test/java/org/apache/hertzbeat/alert/util/AlertTemplateUtilTest.java +++ b/alerter/src/test/java/org/apache/hertzbeat/alert/util/AlertTemplateUtilTest.java @@ -17,13 +17,12 @@ package org.apache.hertzbeat.alert.util; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.HashMap; import java.util.Map; - -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test case for {@link AlertTemplateUtil} diff --git a/collector/src/test/java/org/apache/hertzbeat/collector/collect/ftp/FtpCollectImplTest.java b/collector/src/test/java/org/apache/hertzbeat/collector/collect/ftp/FtpCollectImplTest.java index 529559592f0..90c49d00a61 100644 --- a/collector/src/test/java/org/apache/hertzbeat/collector/collect/ftp/FtpCollectImplTest.java +++ b/collector/src/test/java/org/apache/hertzbeat/collector/collect/ftp/FtpCollectImplTest.java @@ -29,7 +29,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.MockedConstruction; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; diff --git a/collector/src/test/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/ExporterParserTest.java b/collector/src/test/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/ExporterParserTest.java index cde41da2600..c15449b9655 100644 --- a/collector/src/test/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/ExporterParserTest.java +++ b/collector/src/test/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/ExporterParserTest.java @@ -17,11 +17,9 @@ package org.apache.hertzbeat.collector.collect.http.promethus.exporter; -import org.junit.jupiter.api.Test; - +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Map; - -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; /** * @@ -31,35 +29,35 @@ class ExporterParserTest { @Test void textToMetric() { - String resp = "# HELP disk_total_bytes Total space for path\n" + - "# TYPE disk_total_bytes gauge\n" + - "disk_total_bytes{path=\"C:\\\\hertzbeat\\\\repo\\\\testpath\",} 4.29496725504E11\n" + - "# HELP go_gc_cycles_automatic_gc_cycles_total Count of completed GC cycles generated by the Go runtime.\n" + - "# TYPE go_gc_cycles_automatic_gc_cycles_total counter\n" + - "go_gc_cycles_automatic_gc_cycles_total 0\n" + - "# HELP go_gc_cycles_forced_gc_cycles_total Count of completed GC cycles forced by the application.\n" + - "# TYPE go_gc_cycles_forced_gc_cycles_total counter\n" + - "go_gc_cycles_forced_gc_cycles_total 0\n" + - "# HELP go_gc_cycles_total_gc_cycles_total Count of all completed GC cycles.\n" + - "# TYPE go_gc_cycles_total_gc_cycles_total counter\n" + - "go_gc_cycles_total_gc_cycles_total 0\n" + - "# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.\n" + - "# TYPE go_gc_duration_seconds summary\n" + - "go_gc_duration_seconds{quantile=\"0\"} 0\n" + - "go_gc_duration_seconds{quantile=\"0.25\"} 0\n" + - "go_gc_duration_seconds{quantile=\"0.5\"} 0\n" + - "go_gc_duration_seconds{quantile=\"0.75\"} 0\n" + - "go_gc_duration_seconds{quantile=\"1\"} 0\n" + - "# TYPE jvm info\n" + - "# HELP jvm VM version info\n" + - "jvm_info{runtime=\"OpenJDK Runtime Environment\",vendor=\"Azul Systems, Inc.\",version=\"11.0.13+8-LTS\"} 1.0\n" + - "# TYPE jvm_gc_collection_seconds summary\n" + - "# HELP jvm_gc_collection_seconds Time spent in a given JVM garbage collector in seconds.\n" + - "jvm_gc_collection_seconds_count{gc=\"G1 Young Generation\"} 10.0\n" + - "jvm_gc_collection_seconds_sum{gc=\"G1 Young Generation\"} 0.051\n" + - "jvm_gc_collection_seconds_count{gc=\"G1 Old Generation\"} 0.0\n" + - "jvm_gc_collection_seconds_sum{gc=\"G1 Old Generation\"} 0.0\n" + - "# EOF"; + String resp = "# HELP disk_total_bytes Total space for path\n" + + "# TYPE disk_total_bytes gauge\n" + + "disk_total_bytes{path=\"C:\\\\hertzbeat\\\\repo\\\\testpath\",} 4.29496725504E11\n" + + "# HELP go_gc_cycles_automatic_gc_cycles_total Count of completed GC cycles generated by the Go runtime.\n" + + "# TYPE go_gc_cycles_automatic_gc_cycles_total counter\n" + + "go_gc_cycles_automatic_gc_cycles_total 0\n" + + "# HELP go_gc_cycles_forced_gc_cycles_total Count of completed GC cycles forced by the application.\n" + + "# TYPE go_gc_cycles_forced_gc_cycles_total counter\n" + + "go_gc_cycles_forced_gc_cycles_total 0\n" + + "# HELP go_gc_cycles_total_gc_cycles_total Count of all completed GC cycles.\n" + + "# TYPE go_gc_cycles_total_gc_cycles_total counter\n" + + "go_gc_cycles_total_gc_cycles_total 0\n" + + "# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.\n" + + "# TYPE go_gc_duration_seconds summary\n" + + "go_gc_duration_seconds{quantile=\"0\"} 0\n" + + "go_gc_duration_seconds{quantile=\"0.25\"} 0\n" + + "go_gc_duration_seconds{quantile=\"0.5\"} 0\n" + + "go_gc_duration_seconds{quantile=\"0.75\"} 0\n" + + "go_gc_duration_seconds{quantile=\"1\"} 0\n" + + "# TYPE jvm info\n" + + "# HELP jvm VM version info\n" + + "jvm_info{runtime=\"OpenJDK Runtime Environment\",vendor=\"Azul Systems, Inc.\",version=\"11.0.13+8-LTS\"} 1.0\n" + + "# TYPE jvm_gc_collection_seconds summary\n" + + "# HELP jvm_gc_collection_seconds Time spent in a given JVM garbage collector in seconds.\n" + + "jvm_gc_collection_seconds_count{gc=\"G1 Young Generation\"} 10.0\n" + + "jvm_gc_collection_seconds_sum{gc=\"G1 Young Generation\"} 0.051\n" + + "jvm_gc_collection_seconds_count{gc=\"G1 Old Generation\"} 0.0\n" + + "jvm_gc_collection_seconds_sum{gc=\"G1 Old Generation\"} 0.0\n" + + "# EOF"; ExporterParser parser = new ExporterParser(); Map metricFamilyMap = parser.textToMetric(resp); assertEquals(7, metricFamilyMap.size()); diff --git a/collector/src/test/java/org/apache/hertzbeat/collector/dispatch/unit/TimeLengthConvertTest.java b/collector/src/test/java/org/apache/hertzbeat/collector/dispatch/unit/TimeLengthConvertTest.java index 11b1d69de23..56ef4da1c33 100644 --- a/collector/src/test/java/org/apache/hertzbeat/collector/dispatch/unit/TimeLengthConvertTest.java +++ b/collector/src/test/java/org/apache/hertzbeat/collector/dispatch/unit/TimeLengthConvertTest.java @@ -17,12 +17,11 @@ package org.apache.hertzbeat.collector.dispatch.unit; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.hertzbeat.collector.dispatch.unit.impl.TimeLengthConvert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - /** * Test case for {@link TimeLengthConvert} */ diff --git a/collector/src/test/java/org/apache/hertzbeat/collector/util/CollectUtilTest.java b/collector/src/test/java/org/apache/hertzbeat/collector/util/CollectUtilTest.java index 2f10ab0df45..da5ec6f721a 100644 --- a/collector/src/test/java/org/apache/hertzbeat/collector/util/CollectUtilTest.java +++ b/collector/src/test/java/org/apache/hertzbeat/collector/util/CollectUtilTest.java @@ -17,25 +17,24 @@ package org.apache.hertzbeat.collector.util; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; import com.google.gson.JsonElement; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.apache.hertzbeat.common.entity.job.Configmap; import org.apache.hertzbeat.common.entity.job.Metrics; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -import static org.junit.jupiter.api.Assertions.*; - /** * Test case for {@link CollectUtil} */ diff --git a/collector/src/test/java/org/apache/hertzbeat/collector/util/PrivateKeyUtilsTest.java b/collector/src/test/java/org/apache/hertzbeat/collector/util/PrivateKeyUtilsTest.java index cf14e131d36..6570880b9e9 100644 --- a/collector/src/test/java/org/apache/hertzbeat/collector/util/PrivateKeyUtilsTest.java +++ b/collector/src/test/java/org/apache/hertzbeat/collector/util/PrivateKeyUtilsTest.java @@ -15,11 +15,10 @@ package org.apache.hertzbeat.collector.util; +import java.io.IOException; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.io.IOException; - /** * * Created by gcdd1993 on 2023/7/9 @@ -29,33 +28,33 @@ class PrivateKeyUtilsTest { @DisplayName("write key to ~/.ssh") @Test void writePrivateKey() throws IOException { - var key = "-----BEGIN RSA PRIVATE KEY-----\n" + - "MIIEogIBAAKCAQEA4ctFYk/xy89L6/6YFeeMrwCW9lCP/ThXMn+9G63s5bGn4oIN\n" + - "8cEf/JYkmGw8vMP41IAP9dyH8ji2wIZSLeTPWucEK6P6jA01iIBQ95ng6RTsnQgL\n" + - "h4pYHxlEaNHcXkjy5GlMdzaWadjdRevpThGR1VOtWFtK3yoC0c/te2Junu04f+11\n" + - "cpk8QvmVfzrBUooVnG0/7oekwUy1c5sSl0qVoLzXOv4XG9w34cyvacFC30zv1Nl8\n" + - "ASi2pmOBVx9njPvqQ7qZrDk0nwn+RZUmGh/PbmHxrBV7ZA5NjZcEnf2VGIfjGUVu\n" + - "qE4VnkbvS4j03afV2rsp1yo74K+k/ZC6GCHB5QIBIwKCAQBG9r4I9I3SVxfcdJYy\n" + - "xR2WFiDREgFeNkdKYqkl9NVsws5dIY9am8g5cQQv54DNnK1KGZ6dulaclXtD0nGZ\n" + - "ZSs505OYr+EHcd2f7dBN0Uavp32QcD4jSLycD0FixZ0HsIbaEnceJxlUd1t8YBYf\n" + - "2aLcpUUbxOulORbUOgjPAa286uDeQYN5IbdruDfvbuFFm7hBoGZoKLJ7FPcJ0U3A\n" + - "14KRK+Z1oCYJIS0ubaHbhaPIVPPQEmTNHpsvxIJXfZtVy9+XIuBGmD3+Aq6SSFPC\n" + - "A8mU1iKzzdRCXZwvPeUiivIIZc6DRXjhtJ2Lya/XndKidOT/QUj8Z+f9pWAonlzM\n" + - "3PMXAoGBAPvzctkkDjUJjLyEuYQq8soYokS4n4ykFTP5oFgnodK/cYocbxTT6Tn9\n" + - "vH7b6lK6ZAf+tZk8rcEeIO650pOvmaa1/OuZSxfcFUGBvOvYXiHF7zmkePh/pQgB\n" + - "7Cl0RYrI52Cjbd9aCUIYK3A82qsUq30INGeOhMNrfaHn2pgx8xlDAoGBAOVsNctw\n" + - "CHnLaIQX8eS+eUcQEm+NZppnDBJavdpP48ZZM/t5v/2fQ5ytbYqk0KEzIGu0dP8g\n" + - "jfB76JbMvStvTfB+TrXsfhGyA3oJrEcG+3IUshsRU2sohT1ScY27z2VMLgilnWvF\n" + - "7t49sQm9uB/yn669n8LIciHxDItOpvqgKdG3AoGBAO2NxA6PtZ+4jAIz/19bsbc7\n" + - "zDIqaovrKe8tMMglXg/ZE0e0aLvdvqRkRAKU1Z51Ob5lLuDwEYoyWZCgk1gL90Vp\n" + - "wpT+P3zlcyCBo39IWMDB8C8IydRbF/GbaaNtoKds92m+qWwwUd87XCf+3M0wvvI6\n" + - "75TW1PLEbyOgFz8Khh8hAoGBAJbDc87Ul9sCAtp2Ip2hvWk2coPR8vfADz9C8cn5\n" + - "/BShBOcVfipSt2b1n8GCP/TnFU4XgBVeiSkA9+4Rg6AzMzejdY1+JvWvfqCnRVM/\n" + - "GkOnMzZb17tyZi+ck8OKC/IcHkAyUYFWL0GWQSOojvBsPQxt+0V8aEIwsHjNSSha\n" + - "nyNpAoGAd0XqdByRxbWgg5ZsvM0tvrpMITpEZsGMG9VeQPGl0wsQvC2zw5QGLvz/\n" + - "57YhofOOr0M3yElcFA9Imvek5CYZsyL8eIWGZyadfRiYvGOUyvDDO3BYRG4DmhyF\n" + - "KVk3URjEuOCC29ORvZ/7HaCO9iuEbvAA/mrAtd7KdCA+3PzfEOw=\n" + - "-----END RSA PRIVATE KEY-----"; + var key = "-----BEGIN RSA PRIVATE KEY-----\n" + + "MIIEogIBAAKCAQEA4ctFYk/xy89L6/6YFeeMrwCW9lCP/ThXMn+9G63s5bGn4oIN\n" + + "8cEf/JYkmGw8vMP41IAP9dyH8ji2wIZSLeTPWucEK6P6jA01iIBQ95ng6RTsnQgL\n" + + "h4pYHxlEaNHcXkjy5GlMdzaWadjdRevpThGR1VOtWFtK3yoC0c/te2Junu04f+11\n" + + "cpk8QvmVfzrBUooVnG0/7oekwUy1c5sSl0qVoLzXOv4XG9w34cyvacFC30zv1Nl8\n" + + "ASi2pmOBVx9njPvqQ7qZrDk0nwn+RZUmGh/PbmHxrBV7ZA5NjZcEnf2VGIfjGUVu\n" + + "qE4VnkbvS4j03afV2rsp1yo74K+k/ZC6GCHB5QIBIwKCAQBG9r4I9I3SVxfcdJYy\n" + + "xR2WFiDREgFeNkdKYqkl9NVsws5dIY9am8g5cQQv54DNnK1KGZ6dulaclXtD0nGZ\n" + + "ZSs505OYr+EHcd2f7dBN0Uavp32QcD4jSLycD0FixZ0HsIbaEnceJxlUd1t8YBYf\n" + + "2aLcpUUbxOulORbUOgjPAa286uDeQYN5IbdruDfvbuFFm7hBoGZoKLJ7FPcJ0U3A\n" + + "14KRK+Z1oCYJIS0ubaHbhaPIVPPQEmTNHpsvxIJXfZtVy9+XIuBGmD3+Aq6SSFPC\n" + + "A8mU1iKzzdRCXZwvPeUiivIIZc6DRXjhtJ2Lya/XndKidOT/QUj8Z+f9pWAonlzM\n" + + "3PMXAoGBAPvzctkkDjUJjLyEuYQq8soYokS4n4ykFTP5oFgnodK/cYocbxTT6Tn9\n" + + "vH7b6lK6ZAf+tZk8rcEeIO650pOvmaa1/OuZSxfcFUGBvOvYXiHF7zmkePh/pQgB\n" + + "7Cl0RYrI52Cjbd9aCUIYK3A82qsUq30INGeOhMNrfaHn2pgx8xlDAoGBAOVsNctw\n" + + "CHnLaIQX8eS+eUcQEm+NZppnDBJavdpP48ZZM/t5v/2fQ5ytbYqk0KEzIGu0dP8g\n" + + "jfB76JbMvStvTfB+TrXsfhGyA3oJrEcG+3IUshsRU2sohT1ScY27z2VMLgilnWvF\n" + + "7t49sQm9uB/yn669n8LIciHxDItOpvqgKdG3AoGBAO2NxA6PtZ+4jAIz/19bsbc7\n" + + "zDIqaovrKe8tMMglXg/ZE0e0aLvdvqRkRAKU1Z51Ob5lLuDwEYoyWZCgk1gL90Vp\n" + + "wpT+P3zlcyCBo39IWMDB8C8IydRbF/GbaaNtoKds92m+qWwwUd87XCf+3M0wvvI6\n" + + "75TW1PLEbyOgFz8Khh8hAoGBAJbDc87Ul9sCAtp2Ip2hvWk2coPR8vfADz9C8cn5\n" + + "/BShBOcVfipSt2b1n8GCP/TnFU4XgBVeiSkA9+4Rg6AzMzejdY1+JvWvfqCnRVM/\n" + + "GkOnMzZb17tyZi+ck8OKC/IcHkAyUYFWL0GWQSOojvBsPQxt+0V8aEIwsHjNSSha\n" + + "nyNpAoGAd0XqdByRxbWgg5ZsvM0tvrpMITpEZsGMG9VeQPGl0wsQvC2zw5QGLvz/\n" + + "57YhofOOr0M3yElcFA9Imvek5CYZsyL8eIWGZyadfRiYvGOUyvDDO3BYRG4DmhyF\n" + + "KVk3URjEuOCC29ORvZ/7HaCO9iuEbvAA/mrAtd7KdCA+3PzfEOw=\n" + + "-----END RSA PRIVATE KEY-----"; PrivateKeyUtils.writePrivateKey("127.0.0.1", key); } } \ No newline at end of file diff --git a/common/src/test/java/org/apache/hertzbeat/common/config/AviatorConfigurationTest.java b/common/src/test/java/org/apache/hertzbeat/common/config/AviatorConfigurationTest.java index 4ca9dda797a..0b0df67c994 100644 --- a/common/src/test/java/org/apache/hertzbeat/common/config/AviatorConfigurationTest.java +++ b/common/src/test/java/org/apache/hertzbeat/common/config/AviatorConfigurationTest.java @@ -19,13 +19,12 @@ import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.exception.UnsupportedFeatureException; +import java.util.HashMap; +import java.util.Map; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.util.HashMap; -import java.util.Map; - /** * * diff --git a/common/src/test/java/org/apache/hertzbeat/common/util/CommonUtilTest.java b/common/src/test/java/org/apache/hertzbeat/common/util/CommonUtilTest.java index 826c86af65e..694d35f3ce5 100644 --- a/common/src/test/java/org/apache/hertzbeat/common/util/CommonUtilTest.java +++ b/common/src/test/java/org/apache/hertzbeat/common/util/CommonUtilTest.java @@ -17,10 +17,11 @@ package org.apache.hertzbeat.common.util; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; - /** * Test case for {@link CommonUtil} */ @@ -28,10 +29,10 @@ class CommonUtilTest { @Test void testParseDoubleStr() { - assertEquals("9.3454",CommonUtil.parseDoubleStr("9.345435345", null)); - assertEquals("9.3454",CommonUtil.parseDoubleStr("9.345435345%", "%")); - assertEquals("10",CommonUtil.parseDoubleStr("10%", "%")); - assertEquals("588",CommonUtil.parseDoubleStr("588Mb", "Mb")); + assertEquals("9.3454", CommonUtil.parseDoubleStr("9.345435345", null)); + assertEquals("9.3454", CommonUtil.parseDoubleStr("9.345435345%", "%")); + assertEquals("10", CommonUtil.parseDoubleStr("10%", "%")); + assertEquals("588", CommonUtil.parseDoubleStr("588Mb", "Mb")); } @Test diff --git a/common/src/test/java/org/apache/hertzbeat/common/util/IpDomainUtilTest.java b/common/src/test/java/org/apache/hertzbeat/common/util/IpDomainUtilTest.java index f1a8a4349df..4e182a91a9d 100644 --- a/common/src/test/java/org/apache/hertzbeat/common/util/IpDomainUtilTest.java +++ b/common/src/test/java/org/apache/hertzbeat/common/util/IpDomainUtilTest.java @@ -17,10 +17,9 @@ package org.apache.hertzbeat.common.util; -import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; /** * Test case for {@link IpDomainUtil} diff --git a/common/src/test/java/org/apache/hertzbeat/common/util/JsonUtilTest.java b/common/src/test/java/org/apache/hertzbeat/common/util/JsonUtilTest.java index a7456508db2..bc25e5b8822 100644 --- a/common/src/test/java/org/apache/hertzbeat/common/util/JsonUtilTest.java +++ b/common/src/test/java/org/apache/hertzbeat/common/util/JsonUtilTest.java @@ -18,13 +18,12 @@ package org.apache.hertzbeat.common.util; import com.fasterxml.jackson.core.type.TypeReference; +import java.util.ArrayList; +import java.util.List; import org.apache.hertzbeat.common.entity.manager.TagItem; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.List; - /** * Test case for {@link JsonUtil} */ diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/ManagerTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/ManagerTest.java index b29345046e7..c99db688f24 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/ManagerTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/ManagerTest.java @@ -17,6 +17,10 @@ package org.apache.hertzbeat.manager; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import javax.annotation.Resource; +import javax.naming.NamingException; import org.apache.hertzbeat.alert.AlerterProperties; import org.apache.hertzbeat.alert.AlerterWorkerPool; import org.apache.hertzbeat.alert.calculate.CalculateAlarm; @@ -51,12 +55,6 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.context.ApplicationContext; -import javax.annotation.Resource; -import javax.naming.NamingException; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; - /** * * @version 2.1 diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/DingTalkRobotAlertNotifyHandlerImplTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/DingTalkRobotAlertNotifyHandlerImplTest.java index baccfcc2a9a..0df9e7bc472 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/DingTalkRobotAlertNotifyHandlerImplTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/DingTalkRobotAlertNotifyHandlerImplTest.java @@ -17,19 +17,18 @@ package org.apache.hertzbeat.manager.component.alerter.impl; +import jakarta.annotation.Resource; +import java.util.HashMap; +import java.util.Map; +import lombok.extern.slf4j.Slf4j; +import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.alerter.Alert; import org.apache.hertzbeat.common.entity.manager.NoticeReceiver; -import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.manager.NoticeTemplate; import org.apache.hertzbeat.manager.AbstractSpringIntegrationTest; -import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.util.StringUtils; -import jakarta.annotation.Resource; -import java.util.HashMap; -import java.util.Map; - /** * Test case for {@link DingTalkRobotAlertNotifyHandlerImpl} */ @@ -50,17 +49,17 @@ void send() { receiver.setId(1L); receiver.setName("Mock 告警"); receiver.setAccessToken(ddAccessToken); - NoticeTemplate noticeTemplate=new NoticeTemplate(); + NoticeTemplate noticeTemplate = new NoticeTemplate(); noticeTemplate.setId(1L); noticeTemplate.setName("dingding"); - noticeTemplate.setContent("#### [${title}]\n" + - "##### **${targetLabel}** : ${target}\n" + - "<#if (monitorId??)>##### **${monitorIdLabel}** : ${monitorId} \n" + - "<#if (monitorName??)>##### **${monitorNameLabel}** : ${monitorName} \n" + - "<#if (monitorHost??)>##### **${monitorHostLabel}** : ${monitorHost} \n" + - "##### **${priorityLabel}** : ${priority}\n" + - "##### **${triggerTimeLabel}** : ${triggerTime}\n" + - "##### **${contentLabel}** : ${content}"); + noticeTemplate.setContent("#### [${title}]\n" + + "##### **${targetLabel}** : ${target}\n" + + "<#if (monitorId??)>##### **${monitorIdLabel}** : ${monitorId} \n" + + "<#if (monitorName??)>##### **${monitorNameLabel}** : ${monitorName} \n" + + "<#if (monitorHost??)>##### **${monitorHostLabel}** : ${monitorHost} \n" + + "##### **${priorityLabel}** : ${priority}\n" + + "##### **${triggerTimeLabel}** : ${triggerTime}\n" + + "##### **${contentLabel}** : ${content}"); Alert alert = new Alert(); alert.setId(1L); alert.setTarget("Mock Target"); @@ -73,7 +72,7 @@ void send() { alert.setPriority((byte) 0); alert.setLastAlarmTime(System.currentTimeMillis()); - dingTalkRobotAlertNotifyHandler.send(receiver,noticeTemplate, alert); + dingTalkRobotAlertNotifyHandler.send(receiver, noticeTemplate, alert); } } diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/DiscordBotAlertNotifyHandlerImplTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/DiscordBotAlertNotifyHandlerImplTest.java index f1f52d78b36..f3573701496 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/DiscordBotAlertNotifyHandlerImplTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/DiscordBotAlertNotifyHandlerImplTest.java @@ -17,18 +17,17 @@ package org.apache.hertzbeat.manager.component.alerter.impl; +import jakarta.annotation.Resource; +import java.util.Map; +import lombok.extern.slf4j.Slf4j; +import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.alerter.Alert; import org.apache.hertzbeat.common.entity.manager.NoticeReceiver; -import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.manager.NoticeTemplate; import org.apache.hertzbeat.manager.AbstractSpringIntegrationTest; -import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.util.StringUtils; -import jakarta.annotation.Resource; -import java.util.Map; - /** * Test case for {@link DiscordBotAlertNotifyHandlerImpl} */ @@ -51,16 +50,16 @@ void send() { receiver.setName("Mock 告警"); receiver.setDiscordChannelId(discordChannelId); receiver.setDiscordBotToken(discordBotToken); - var noticeTemplate=new NoticeTemplate(); + var noticeTemplate = new NoticeTemplate(); noticeTemplate.setId(1L); noticeTemplate.setName("DiscordBot"); - noticeTemplate.setContent("${targetLabel} : ${target}\n" + - "<#if (monitorId??)>${monitorIdLabel} : ${monitorId} \n" + - "<#if (monitorName??)>${monitorNameLabel} : ${monitorName} \n" + - "<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} \n" + - "${priorityLabel} : ${priority}\n" + - "${triggerTimeLabel} : ${triggerTime}\n" + - "${contentLabel} : ${content}"); + noticeTemplate.setContent("${targetLabel} : ${target}\n" + + "<#if (monitorId??)>${monitorIdLabel} : ${monitorId} \n" + + "<#if (monitorName??)>${monitorNameLabel} : ${monitorName} \n" + + "<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} \n" + + "${priorityLabel} : ${priority}\n" + + "${triggerTimeLabel} : ${triggerTime}\n" + + "${contentLabel} : ${content}"); var alert = new Alert(); alert.setId(1L); alert.setTarget("Mock Target"); @@ -74,6 +73,6 @@ void send() { alert.setPriority((byte) 0); alert.setLastAlarmTime(System.currentTimeMillis()); - discordBotAlertNotifyHandler.send(receiver, noticeTemplate,alert); + discordBotAlertNotifyHandler.send(receiver, noticeTemplate, alert); } } diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/FlyBookAlertNotifyHandlerImplTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/FlyBookAlertNotifyHandlerImplTest.java index 1f0d1457df9..3d92ae3adb5 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/FlyBookAlertNotifyHandlerImplTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/FlyBookAlertNotifyHandlerImplTest.java @@ -17,19 +17,18 @@ package org.apache.hertzbeat.manager.component.alerter.impl; +import jakarta.annotation.Resource; +import java.util.HashMap; +import java.util.Map; +import lombok.extern.slf4j.Slf4j; +import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.alerter.Alert; import org.apache.hertzbeat.common.entity.manager.NoticeReceiver; -import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.manager.NoticeTemplate; import org.apache.hertzbeat.manager.AbstractSpringIntegrationTest; -import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.util.StringUtils; -import jakarta.annotation.Resource; -import java.util.HashMap; -import java.util.Map; - /** * Test case for {@link FlyBookAlertNotifyHandlerImpl} */ @@ -50,16 +49,16 @@ void send() { receiver.setId(1L); receiver.setName("Mock 告警"); receiver.setWechatId(flyBookId); - NoticeTemplate noticeTemplate=new NoticeTemplate(); + NoticeTemplate noticeTemplate = new NoticeTemplate(); noticeTemplate.setId(1L); noticeTemplate.setName("FlyBook"); - noticeTemplate.setContent("{targetLabel} : ${target}\n" + - "<#if (monitorId??)>${monitorIdLabel} : ${monitorId} \n" + - "<#if (monitorName??)>${monitorNameLabel} : ${monitorName} \n" + - "<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} \n" + - "${priorityLabel} : ${priority}\n" + - "${triggerTimeLabel} : ${triggerTime}\n" + - "${contentLabel} : ${content}"); + noticeTemplate.setContent("{targetLabel} : ${target}\n" + + "<#if (monitorId??)>${monitorIdLabel} : ${monitorId} \n" + + "<#if (monitorName??)>${monitorNameLabel} : ${monitorName} \n" + + "<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} \n" + + "${priorityLabel} : ${priority}\n" + + "${triggerTimeLabel} : ${triggerTime}\n" + + "${contentLabel} : ${content}"); Alert alert = new Alert(); alert.setId(1L); alert.setTarget("Mock Target"); @@ -72,7 +71,7 @@ void send() { alert.setPriority((byte) 0); alert.setLastAlarmTime(System.currentTimeMillis()); - flyBookAlertNotifyHandler.send(receiver,noticeTemplate, alert); + flyBookAlertNotifyHandler.send(receiver, noticeTemplate, alert); } } diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/HuaweiCloudSmnAlertNotifyHandlerImplTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/HuaweiCloudSmnAlertNotifyHandlerImplTest.java index b165a3080c8..20d19ecf949 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/HuaweiCloudSmnAlertNotifyHandlerImplTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/HuaweiCloudSmnAlertNotifyHandlerImplTest.java @@ -15,6 +15,8 @@ package org.apache.hertzbeat.manager.component.alerter.impl; +import jakarta.annotation.Resource; +import java.util.Map; import lombok.extern.slf4j.Slf4j; import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.alerter.Alert; @@ -24,9 +26,6 @@ import org.junit.jupiter.api.Test; import org.springframework.util.StringUtils; -import jakarta.annotation.Resource; -import java.util.Map; - /** * */ @@ -71,17 +70,17 @@ void send() throws InterruptedException { receiver.setSmnProjectId(smnProjectId); receiver.setSmnRegion(smnRegion); receiver.setSmnTopicUrn(smnTopicUrn); - var noticeTemplate=new NoticeTemplate(); + var noticeTemplate = new NoticeTemplate(); noticeTemplate.setId(1L); noticeTemplate.setName("HuaWeiCloud"); - noticeTemplate.setContent("[${title}]\n" + - "${targetLabel} : ${target}\n" + - "<#if (monitorId??)>${monitorIdLabel} : ${monitorId} \n" + - "<#if (monitorName??)>${monitorNameLabel} : ${monitorName} \n" + - "<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} \n" + - "${priorityLabel} : ${priority}\n" + - "${triggerTimeLabel} : ${triggerTime}\n" + - "${contentLabel} : ${content}"); + noticeTemplate.setContent("[${title}]\n" + + "${targetLabel} : ${target}\n" + + "<#if (monitorId??)>${monitorIdLabel} : ${monitorId} \n" + + "<#if (monitorName??)>${monitorNameLabel} : ${monitorName} \n" + + "<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} \n" + + "${priorityLabel} : ${priority}\n" + + "${triggerTimeLabel} : ${triggerTime}\n" + + "${contentLabel} : ${content}"); var alert = new Alert(); alert.setId(1L); alert.setTarget("Mock Target"); @@ -95,6 +94,6 @@ void send() throws InterruptedException { alert.setPriority((byte) 0); alert.setLastAlarmTime(System.currentTimeMillis()); - huaweiyunSmnAlertNotifyHandler.send(receiver, noticeTemplate,alert); + huaweiyunSmnAlertNotifyHandler.send(receiver, noticeTemplate, alert); } } diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/SlackAlertNotifyHandlerImplTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/SlackAlertNotifyHandlerImplTest.java index 8f2c8263d57..12a0866aa00 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/SlackAlertNotifyHandlerImplTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/SlackAlertNotifyHandlerImplTest.java @@ -17,18 +17,17 @@ package org.apache.hertzbeat.manager.component.alerter.impl; +import jakarta.annotation.Resource; +import java.util.Map; +import lombok.extern.slf4j.Slf4j; +import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.alerter.Alert; import org.apache.hertzbeat.common.entity.manager.NoticeReceiver; -import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.manager.NoticeTemplate; import org.apache.hertzbeat.manager.AbstractSpringIntegrationTest; -import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.util.StringUtils; -import jakarta.annotation.Resource; -import java.util.Map; - /** * Test case for {@link SlackAlertNotifyHandlerImpl} * @@ -54,17 +53,17 @@ void send() { var alert = new Alert(); alert.setId(1L); alert.setTarget("Mock Target"); - var noticeTemplate=new NoticeTemplate(); + var noticeTemplate = new NoticeTemplate(); noticeTemplate.setId(1L); noticeTemplate.setName("Slack"); - noticeTemplate.setContent("*[${title}]*\n" + - "${targetLabel} : ${target}\n" + - "<#if (monitorId??)>${monitorIdLabel} : ${monitorId} \n" + - "<#if (monitorName??)>${monitorNameLabel} : ${monitorName} \n" + - "<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} \n" + - "${priorityLabel} : ${priority}\n" + - "${triggerTimeLabel} : ${triggerTime}\n" + - "${contentLabel} : ${content}"); + noticeTemplate.setContent("*[${title}]*\n" + + "${targetLabel} : ${target}\n" + + "<#if (monitorId??)>${monitorIdLabel} : ${monitorId} \n" + + "<#if (monitorName??)>${monitorNameLabel} : ${monitorName} \n" + + "<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} \n" + + "${priorityLabel} : ${priority}\n" + + "${triggerTimeLabel} : ${triggerTime}\n" + + "${contentLabel} : ${content}"); var map = Map.of( CommonConstants.TAG_MONITOR_ID, "Mock monitor id", CommonConstants.TAG_MONITOR_NAME, "Mock monitor name", @@ -75,6 +74,6 @@ void send() { alert.setPriority((byte) 0); alert.setLastAlarmTime(System.currentTimeMillis()); - slackAlertNotifyHandler.send(receiver, noticeTemplate,alert); + slackAlertNotifyHandler.send(receiver, noticeTemplate, alert); } } diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/TelegramBotAlertNotifyHandlerImplTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/TelegramBotAlertNotifyHandlerImplTest.java index 8a85b41a741..5a49dfe1c1b 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/TelegramBotAlertNotifyHandlerImplTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/TelegramBotAlertNotifyHandlerImplTest.java @@ -17,19 +17,18 @@ package org.apache.hertzbeat.manager.component.alerter.impl; +import jakarta.annotation.Resource; +import java.util.HashMap; +import java.util.Map; +import lombok.extern.slf4j.Slf4j; +import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.alerter.Alert; import org.apache.hertzbeat.common.entity.manager.NoticeReceiver; -import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.manager.NoticeTemplate; import org.apache.hertzbeat.manager.AbstractSpringIntegrationTest; -import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.util.StringUtils; -import jakarta.annotation.Resource; -import java.util.HashMap; -import java.util.Map; - /** * * @version 2.1 @@ -56,17 +55,17 @@ void send() { Alert alert = new Alert(); alert.setId(1L); alert.setTarget("Mock Target"); - NoticeTemplate noticeTemplate=new NoticeTemplate(); + NoticeTemplate noticeTemplate = new NoticeTemplate(); noticeTemplate.setId(1L); noticeTemplate.setName("Telegram"); - noticeTemplate.setContent("[${title}]\n" + - "${targetLabel} : ${target}\n" + - "<#if (monitorId??)>${monitorIdLabel} : ${monitorId} \n" + - "<#if (monitorName??)>${monitorNameLabel} : ${monitorName} \n" + - "<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} \n" + - "${priorityLabel} : ${priority}\n" + - "${triggerTimeLabel} : ${triggerTime}\n" + - "${contentLabel} : ${content}"); + noticeTemplate.setContent("[${title}]\n" + + "${targetLabel} : ${target}\n" + + "<#if (monitorId??)>${monitorIdLabel} : ${monitorId} \n" + + "<#if (monitorName??)>${monitorNameLabel} : ${monitorName} \n" + + "<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} \n" + + "${priorityLabel} : ${priority}\n" + + "${triggerTimeLabel} : ${triggerTime}\n" + + "${contentLabel} : ${content}"); Map map = new HashMap<>(); map.put(CommonConstants.TAG_MONITOR_ID, "Mock monitor id"); map.put(CommonConstants.TAG_MONITOR_NAME, "Mock monitor name"); @@ -76,6 +75,6 @@ void send() { alert.setPriority((byte) 0); alert.setLastAlarmTime(System.currentTimeMillis()); - telegramBotAlertNotifyHandler.send(receiver, noticeTemplate,alert); + telegramBotAlertNotifyHandler.send(receiver, noticeTemplate, alert); } } diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/WeChatAppAlertNotifyHandlerImplTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/WeChatAppAlertNotifyHandlerImplTest.java index 5ca06adfc2b..ce4285ea169 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/WeChatAppAlertNotifyHandlerImplTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/WeChatAppAlertNotifyHandlerImplTest.java @@ -17,19 +17,18 @@ package org.apache.hertzbeat.manager.component.alerter.impl; +import jakarta.annotation.Resource; +import java.util.HashMap; +import java.util.Map; import lombok.extern.slf4j.Slf4j; +import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.alerter.Alert; import org.apache.hertzbeat.common.entity.manager.NoticeReceiver; -import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.manager.NoticeTemplate; import org.apache.hertzbeat.manager.AbstractSpringIntegrationTest; import org.junit.jupiter.api.Test; import org.springframework.util.StringUtils; -import jakarta.annotation.Resource; -import java.util.HashMap; -import java.util.Map; - /** * unit test case for WeChatAppAlertNotifyHandlerImpl * diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/WeWorkRobotAlertNotifyHandlerImplTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/WeWorkRobotAlertNotifyHandlerImplTest.java index 1919a8cb5f2..d288a1cd8d9 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/WeWorkRobotAlertNotifyHandlerImplTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/component/alerter/impl/WeWorkRobotAlertNotifyHandlerImplTest.java @@ -17,19 +17,18 @@ package org.apache.hertzbeat.manager.component.alerter.impl; +import jakarta.annotation.Resource; +import java.util.HashMap; +import java.util.Map; +import lombok.extern.slf4j.Slf4j; +import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.alerter.Alert; import org.apache.hertzbeat.common.entity.manager.NoticeReceiver; -import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.manager.NoticeTemplate; import org.apache.hertzbeat.manager.AbstractSpringIntegrationTest; -import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.util.StringUtils; -import jakarta.annotation.Resource; -import java.util.HashMap; -import java.util.Map; - /** * Test case for {@link WeWorkRobotAlertNotifyHandlerImpl} */ @@ -53,17 +52,17 @@ void send() { Alert alert = new Alert(); alert.setId(1L); alert.setTarget("Mock Target"); - NoticeTemplate noticeTemplate=new NoticeTemplate(); + NoticeTemplate noticeTemplate = new NoticeTemplate(); noticeTemplate.setId(1L); noticeTemplate.setName("WeWork"); - noticeTemplate.setContent("[${title}]\n" + - "${targetLabel} : ${target}\n" + - "<#if (monitorId??)>${monitorIdLabel} : ${monitorId} \n" + - "<#if (monitorName??)>${monitorNameLabel} : ${monitorName} \n" + - "<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} \n" + - "${priorityLabel} : ${priority}\n" + - "${triggerTimeLabel} : ${triggerTime}\n" + - "${contentLabel} : ${content}"); + noticeTemplate.setContent("[${title}]\n" + + "${targetLabel} : ${target}\n" + + "<#if (monitorId??)>${monitorIdLabel} : ${monitorId} \n" + + "<#if (monitorName??)>${monitorNameLabel} : ${monitorName} \n" + + "<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} \n" + + "${priorityLabel} : ${priority}\n" + + "${triggerTimeLabel} : ${triggerTime}\n" + + "${contentLabel} : ${content}"); Map map = new HashMap<>(); map.put(CommonConstants.TAG_MONITOR_ID, "Mock monitor id"); map.put(CommonConstants.TAG_MONITOR_NAME, "Mock monitor name"); diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/controller/AccountControllerTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/controller/AccountControllerTest.java index 3ee34d41835..634c32a4ef3 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/controller/AccountControllerTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/controller/AccountControllerTest.java @@ -17,10 +17,12 @@ package org.apache.hertzbeat.manager.controller; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.usthe.sureness.util.JsonWebTokenUtil; import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.util.JsonUtil; import org.apache.hertzbeat.manager.pojo.dto.LoginDto; -import com.usthe.sureness.util.JsonWebTokenUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -31,9 +33,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - /** * Test case for {@link AccountController} */ diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/controller/AppControllerTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/controller/AppControllerTest.java index e1bf39d3f91..10ab5eb01fe 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/controller/AppControllerTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/controller/AppControllerTest.java @@ -17,9 +17,13 @@ package org.apache.hertzbeat.manager.controller; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.job.Job; import org.apache.hertzbeat.common.entity.manager.ParamDefine; -import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.manager.pojo.dto.Hierarchy; import org.apache.hertzbeat.manager.service.impl.AppServiceImpl; import org.junit.jupiter.api.BeforeEach; @@ -33,13 +37,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; - /** * Test case for {@link AppController} */ @@ -53,6 +50,7 @@ class AppControllerTest { @InjectMocks private AppController appController; + @BeforeEach void setUp() { this.mockMvc = MockMvcBuilders.standaloneSetup(appController).build(); @@ -124,7 +122,7 @@ void queryAppsHierarchy() throws Exception { // Request interface this.mockMvc.perform(MockMvcRequestBuilders.get("/api/apps/hierarchy", "zh-CN")) - .andExpect( jsonPath("$.code").value((int) CommonConstants.SUCCESS_CODE)) + .andExpect(jsonPath("$.code").value((int) CommonConstants.SUCCESS_CODE)) .andExpect(jsonPath("$.data[0].category").value("os")) .andReturn(); diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/controller/I18nControllerTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/controller/I18nControllerTest.java index 860a4b04602..e5ba24defe2 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/controller/I18nControllerTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/controller/I18nControllerTest.java @@ -17,6 +17,8 @@ package org.apache.hertzbeat.manager.controller; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import java.util.HashMap; import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.manager.service.impl.AppServiceImpl; import org.junit.jupiter.api.BeforeEach; @@ -30,10 +32,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import java.util.HashMap; - -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; - /** * Test case for {@link I18nController} */ diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/controller/MonitorControllerTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/controller/MonitorControllerTest.java index 59af720cf36..b3de1ee088c 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/controller/MonitorControllerTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/controller/MonitorControllerTest.java @@ -17,9 +17,13 @@ package org.apache.hertzbeat.manager.controller; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.util.ArrayList; +import java.util.List; +import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.manager.Monitor; import org.apache.hertzbeat.common.entity.manager.Param; -import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.util.JsonUtil; import org.apache.hertzbeat.manager.pojo.dto.MonitorDto; import org.apache.hertzbeat.manager.service.impl.MonitorServiceImpl; @@ -35,12 +39,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import java.util.ArrayList; -import java.util.List; - -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - /** * Test case for {@link MonitorController} */ diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/controller/MonitorsControllerTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/controller/MonitorsControllerTest.java index 5128a4b51f2..c8d5bc873fa 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/controller/MonitorsControllerTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/controller/MonitorsControllerTest.java @@ -17,6 +17,10 @@ package org.apache.hertzbeat.manager.controller; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.util.ArrayList; +import java.util.List; import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.util.JsonUtil; import org.apache.hertzbeat.manager.service.impl.MonitorServiceImpl; @@ -31,12 +35,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import java.util.ArrayList; -import java.util.List; - -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - /** * Test case for {@link MonitorsController} */ diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/controller/NoticeConfigControllerTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/controller/NoticeConfigControllerTest.java index b679a0a9bf1..33a775818a5 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/controller/NoticeConfigControllerTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/controller/NoticeConfigControllerTest.java @@ -17,11 +17,15 @@ package org.apache.hertzbeat.manager.controller; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.util.ArrayList; +import java.util.List; +import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.manager.NoticeReceiver; +import org.apache.hertzbeat.common.entity.manager.NoticeRule; import org.apache.hertzbeat.common.entity.manager.NoticeTemplate; import org.apache.hertzbeat.common.entity.manager.TagItem; -import org.apache.hertzbeat.common.entity.manager.NoticeRule; -import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.util.JsonUtil; import org.apache.hertzbeat.manager.service.impl.NoticeConfigServiceImpl; import org.junit.jupiter.api.BeforeEach; @@ -36,12 +40,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import java.util.ArrayList; -import java.util.List; - -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - /** * Test case for {@link NoticeConfigController} */ @@ -91,17 +89,18 @@ public NoticeReceiver getNoticeReceiver(){ return noticeReceiver; } + public NoticeTemplate getNoticeTemplate(){ NoticeTemplate template = new NoticeTemplate(); template.setId(5L); template.setName("Dingding"); - template.setContent("[${title}]\n" + - "${targetLabel} : ${target}\n" + - "<#if (monitorId??)>${monitorIdLabel} : ${monitorId} \n" + - "<#if (monitorName??)>${monitorNameLabel} : ${monitorName} \n" + - "${priorityLabel} : ${priority}\n" + - "${triggerTimeLabel} : ${triggerTime}\n" + - "${contentLabel} : ${content}"); + template.setContent("[${title}]\n" + + "${targetLabel} : ${target}\n" + + "<#if (monitorId??)>${monitorIdLabel} : ${monitorId} \n" + + "<#if (monitorName??)>${monitorNameLabel} : ${monitorName} \n" + + "${priorityLabel} : ${priority}\n" + + "${triggerTimeLabel} : ${triggerTime}\n" + + "${contentLabel} : ${content}"); template.setType((byte) 5); return template; @@ -259,7 +258,7 @@ void sendTestMsg() throws Exception { .content(JsonUtil.toJson(noticeReceiver))) .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value((int) CommonConstants.SUCCESS_CODE)) -// .andExpect(jsonPath("$.msg").value("Notify service not available, please check config!")) + //.andExpect(jsonPath("$.msg").value("Notify service not available, please check config!")) .andReturn(); } } diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/controller/SummaryControllerTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/controller/SummaryControllerTest.java index e573bc386c2..babbfde1fda 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/controller/SummaryControllerTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/controller/SummaryControllerTest.java @@ -17,6 +17,10 @@ package org.apache.hertzbeat.manager.controller; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.util.ArrayList; +import java.util.List; import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.manager.pojo.dto.AppCount; import org.apache.hertzbeat.manager.service.impl.MonitorServiceImpl; @@ -31,12 +35,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import java.util.ArrayList; -import java.util.List; - -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - /** * Test case for {@link SummaryController} */ diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/controller/TagControllerTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/controller/TagControllerTest.java index bcdb64bbda0..f895acf663e 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/controller/TagControllerTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/controller/TagControllerTest.java @@ -17,8 +17,12 @@ package org.apache.hertzbeat.manager.controller; -import org.apache.hertzbeat.common.entity.manager.Tag; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.util.ArrayList; +import java.util.List; import org.apache.hertzbeat.common.constants.CommonConstants; +import org.apache.hertzbeat.common.entity.manager.Tag; import org.apache.hertzbeat.common.util.JsonUtil; import org.apache.hertzbeat.manager.service.impl.TagServiceImpl; import org.junit.jupiter.api.BeforeEach; @@ -32,12 +36,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import java.util.ArrayList; -import java.util.List; - -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - /** * Test case for {@link TagController} */ @@ -106,7 +104,8 @@ void modifyMonitor() throws Exception { @Test void getTags() throws Exception { - this.mockMvc.perform(MockMvcRequestBuilders.get("/api/tag?type={type}&search={search}", (byte)1, "status")) + this.mockMvc.perform(MockMvcRequestBuilders.get("/api/tag?type={type}&search={search}", + (byte) 1, "status")) .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value((int) CommonConstants.SUCCESS_CODE)) .andReturn(); diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/dao/MonitorDaoTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/dao/MonitorDaoTest.java index 3520c65c2d7..46226193cf5 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/dao/MonitorDaoTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/dao/MonitorDaoTest.java @@ -17,20 +17,25 @@ package org.apache.hertzbeat.manager.dao; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import jakarta.annotation.Resource; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; import org.apache.hertzbeat.common.entity.manager.Monitor; -import org.apache.hertzbeat.manager.pojo.dto.AppCount; import org.apache.hertzbeat.manager.AbstractSpringIntegrationTest; +import org.apache.hertzbeat.manager.pojo.dto.AppCount; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.transaction.annotation.Transactional; -import jakarta.annotation.Resource; - -import java.util.*; - -import static org.junit.jupiter.api.Assertions.*; - /** * Test case for {@link MonitorDao} */ diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/dao/NoticeRuleDaoTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/dao/NoticeRuleDaoTest.java index 51361fd1d67..7da24c6c43b 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/dao/NoticeRuleDaoTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/dao/NoticeRuleDaoTest.java @@ -17,6 +17,12 @@ package org.apache.hertzbeat.manager.dao; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import jakarta.annotation.Resource; +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.List; import org.apache.hertzbeat.common.entity.manager.NoticeRule; import org.apache.hertzbeat.manager.AbstractSpringIntegrationTest; import org.junit.jupiter.api.AfterEach; @@ -24,14 +30,6 @@ import org.junit.jupiter.api.Test; import org.springframework.transaction.annotation.Transactional; -import jakarta.annotation.Resource; -import java.time.LocalDateTime; -import java.util.Collections; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - /** * Test case for {@link NoticeRuleDao} */ diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/dao/ParamDaoTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/dao/ParamDaoTest.java index c2b6930ade5..b379b866a2f 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/dao/ParamDaoTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/dao/ParamDaoTest.java @@ -17,6 +17,13 @@ package org.apache.hertzbeat.manager.dao; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import jakarta.annotation.Resource; +import java.time.LocalDateTime; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import org.apache.hertzbeat.common.entity.manager.Param; import org.apache.hertzbeat.manager.AbstractSpringIntegrationTest; import org.junit.jupiter.api.AfterEach; @@ -24,15 +31,6 @@ import org.junit.jupiter.api.Test; import org.springframework.transaction.annotation.Transactional; -import jakarta.annotation.Resource; -import java.time.LocalDateTime; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - /** * Test case for {@link ParamDao} */ diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/dao/ParamDefineDaoTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/dao/ParamDefineDaoTest.java index d660b9964a6..6fe0eeaaa6c 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/dao/ParamDefineDaoTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/dao/ParamDefineDaoTest.java @@ -17,6 +17,12 @@ package org.apache.hertzbeat.manager.dao; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import jakarta.annotation.Resource; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; import org.apache.hertzbeat.common.entity.manager.ParamDefine; import org.apache.hertzbeat.manager.AbstractSpringIntegrationTest; import org.junit.jupiter.api.AfterEach; @@ -24,15 +30,6 @@ import org.junit.jupiter.api.Test; import org.springframework.transaction.annotation.Transactional; -import jakarta.annotation.Resource; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - /** * Test case for {@link ParamDefineDao} */ diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/dao/TagDaoTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/dao/TagDaoTest.java index 9efee005733..8aa6de244a5 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/dao/TagDaoTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/dao/TagDaoTest.java @@ -17,6 +17,15 @@ package org.apache.hertzbeat.manager.dao; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import jakarta.annotation.Resource; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import org.apache.hertzbeat.common.entity.manager.Tag; import org.apache.hertzbeat.manager.AbstractSpringIntegrationTest; import org.junit.jupiter.api.AfterEach; @@ -24,17 +33,6 @@ import org.junit.jupiter.api.Test; import org.springframework.transaction.annotation.Transactional; -import jakarta.annotation.Resource; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - /** * Test case for {@link TagDao} */ diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/service/AppServiceTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/service/AppServiceTest.java index d6efd37b93d..4581077ae99 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/service/AppServiceTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/service/AppServiceTest.java @@ -17,6 +17,12 @@ package org.apache.hertzbeat.manager.service; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; +import java.util.Collections; import org.apache.hertzbeat.common.entity.manager.Monitor; import org.apache.hertzbeat.manager.dao.MonitorDao; import org.apache.hertzbeat.manager.service.impl.AppServiceImpl; @@ -29,13 +35,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.util.Collections; - -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.when; - /** * Test case for {@link AppService} */ diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/service/MailServiceTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/service/MailServiceTest.java index cbbcced2053..0bc754d4e35 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/service/MailServiceTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/service/MailServiceTest.java @@ -17,7 +17,11 @@ package org.apache.hertzbeat.manager.service; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import freemarker.template.TemplateException; +import java.io.IOException; +import java.util.ResourceBundle; import org.apache.hertzbeat.alert.AlerterProperties; import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.alerter.Alert; @@ -30,14 +34,6 @@ import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; -import java.io.IOException; -import java.util.ResourceBundle; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; - /** * Test case for {@link MailService} */ @@ -57,8 +53,8 @@ class MailServiceTest { @Test void buildAlertHtmlTemplate() throws TemplateException, IOException { - Alert alert=new Alert(); - NoticeTemplate noticeTemplate=new NoticeTemplate(); + Alert alert = new Alert(); + NoticeTemplate noticeTemplate = new NoticeTemplate(); alert.setTarget("Test Target"); alert.setContent("Test"); alert.setTriggerTimes(1); @@ -69,7 +65,7 @@ void buildAlertHtmlTemplate() throws TemplateException, IOException { noticeTemplate.setName("test"); noticeTemplate.setContent("result"); - assertEquals("result", mailService.buildAlertHtmlTemplate(alert,noticeTemplate)); - assertNotNull(mailService.buildAlertHtmlTemplate(alert,noticeTemplate)); + assertEquals("result", mailService.buildAlertHtmlTemplate(alert, noticeTemplate)); + assertNotNull(mailService.buildAlertHtmlTemplate(alert, noticeTemplate)); } } diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/service/MonitorServiceTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/service/MonitorServiceTest.java index 2303ee56187..ff1c2ca5c67 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/service/MonitorServiceTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/service/MonitorServiceTest.java @@ -17,7 +17,26 @@ package org.apache.hertzbeat.manager.service; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import org.apache.hertzbeat.alert.dao.AlertDefineBindDao; +import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.alerter.Alert; import org.apache.hertzbeat.common.entity.job.Job; import org.apache.hertzbeat.common.entity.job.Metrics; @@ -25,14 +44,13 @@ import org.apache.hertzbeat.common.entity.manager.Param; import org.apache.hertzbeat.common.entity.manager.ParamDefine; import org.apache.hertzbeat.common.entity.message.CollectRep; -import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.manager.dao.CollectorDao; -import org.apache.hertzbeat.manager.dao.MonitorDao; -import org.apache.hertzbeat.manager.pojo.dto.AppCount; -import org.apache.hertzbeat.manager.pojo.dto.MonitorDto; import org.apache.hertzbeat.manager.dao.CollectorMonitorBindDao; +import org.apache.hertzbeat.manager.dao.MonitorDao; import org.apache.hertzbeat.manager.dao.ParamDao; import org.apache.hertzbeat.manager.dao.TagMonitorBindDao; +import org.apache.hertzbeat.manager.pojo.dto.AppCount; +import org.apache.hertzbeat.manager.pojo.dto.MonitorDto; import org.apache.hertzbeat.manager.scheduler.CollectJobScheduling; import org.apache.hertzbeat.manager.service.impl.MonitorServiceImpl; import org.apache.hertzbeat.manager.support.exception.MonitorDatabaseException; @@ -53,17 +71,14 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.Specification; -import java.util.*; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - /** * newBranch feature-clickhouse#179 * ... *

* ... - * docker run -d --name some-clickhouse-server -p 8123:8123 -p 9009:9009 -p 9090:9000 -p 9363:9363 --ulimit nofile=262144:262144 --volume=/opt/clickhouse/data:/var/lib/clickhouse --volume=/opt/clickhouse/log:/var/log/clickhouse-server --volume=/opt/clickhouse/conf/config.xml:/etc/clickhouse-server/config.xml --volume=/opt/clickhouse/conf/users.xml:/etc/clickhouse-server/users.xml clickhouse/clickhouse-server + * docker run -d --name some-clickhouse-server -p 8123:8123 -p 9009:9009 -p 9090:9000 -p 9363:9363 + * --ulimit nofile=262144:262144 --volume=/opt/clickhouse/data:/var/lib/clickhouse --volume=/opt/clickhouse/log:/var/log/clickhouse-server + * --volume=/opt/clickhouse/conf/config.xml:/etc/clickhouse-server/config.xml --volume=/opt/clickhouse/conf/users.xml:/etc/clickhouse-server/users.xml clickhouse/clickhouse-server *

*

* ... @@ -577,8 +592,8 @@ void modifyMonitor() { assertEquals("The Monitor " + monitorId + " not exists", e.getMessage()); } reset(); - /** - * The [monitoring type] of monitor cannot be modified. + /* + The [monitoring type] of monitor cannot be modified. */ Monitor existErrorMonitor = Monitor.builder().app("app2").name("memory").host("host").id(monitorId).build(); when(monitorDao.findById(monitorId)).thenReturn(Optional.of(existErrorMonitor)); @@ -588,8 +603,8 @@ void modifyMonitor() { assertEquals("Can not modify monitor's app type", e.getMessage()); } reset(); - Monitor existOKMonitor = Monitor.builder().jobId(1L).intervals(1).app("app").name("memory").host("host").id(monitorId).build(); - when(monitorDao.findById(monitorId)).thenReturn(Optional.of(existOKMonitor)); + Monitor existOkMonitor = Monitor.builder().jobId(1L).intervals(1).app("app").name("memory").host("host").id(monitorId).build(); + when(monitorDao.findById(monitorId)).thenReturn(Optional.of(existOkMonitor)); when(monitorDao.save(monitor)).thenThrow(RuntimeException.class); assertThrows(MonitorDatabaseException.class, () -> monitorService.modifyMonitor(dto.getMonitor(), dto.getParams(), null)); @@ -598,8 +613,8 @@ void modifyMonitor() { @Test void deleteMonitor() { long id = 1L; - Monitor existOKMonitor = Monitor.builder().jobId(id).intervals(1).app("app").name("memory").host("host").id(id).build(); - when(monitorDao.findById(id)).thenReturn(Optional.of(existOKMonitor)); + Monitor existOkMonitor = Monitor.builder().jobId(id).intervals(1).app("app").name("memory").host("host").id(id).build(); + when(monitorDao.findById(id)).thenReturn(Optional.of(existOkMonitor)); doNothing().when(alertDefineBindDao).deleteAlertDefineMonitorBindsByMonitorIdEquals(id); doNothing().when(tagMonitorBindDao).deleteTagMonitorBindsByMonitorId(id); assertDoesNotThrow(() -> monitorService.deleteMonitor(id)); diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/service/NoticeConfigServiceTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/service/NoticeConfigServiceTest.java index eabc261d18a..c595b724237 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/service/NoticeConfigServiceTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/service/NoticeConfigServiceTest.java @@ -17,18 +17,27 @@ package org.apache.hertzbeat.manager.service; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import com.google.common.collect.Lists; -import org.apache.hertzbeat.manager.dao.NoticeReceiverDao; -import org.apache.hertzbeat.manager.dao.NoticeRuleDao; -import org.apache.hertzbeat.manager.dao.NoticeTemplateDao; -import org.assertj.core.util.Maps; +import java.util.List; +import java.util.Map; import org.apache.hertzbeat.common.entity.alerter.Alert; import org.apache.hertzbeat.common.entity.manager.NoticeReceiver; import org.apache.hertzbeat.common.entity.manager.NoticeRule; import org.apache.hertzbeat.common.entity.manager.NoticeTemplate; import org.apache.hertzbeat.common.entity.manager.TagItem; import org.apache.hertzbeat.manager.component.alerter.DispatcherAlarm; +import org.apache.hertzbeat.manager.dao.NoticeReceiverDao; +import org.apache.hertzbeat.manager.dao.NoticeRuleDao; +import org.apache.hertzbeat.manager.dao.NoticeTemplateDao; import org.apache.hertzbeat.manager.service.impl.NoticeConfigServiceImpl; +import org.assertj.core.util.Maps; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -37,14 +46,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.jpa.domain.Specification; -import java.util.List; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.*; - /** * Test case for {@link NoticeConfigService} */ diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/service/TagServiceTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/service/TagServiceTest.java index d428eadca95..649abfd2614 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/service/TagServiceTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/service/TagServiceTest.java @@ -17,6 +17,18 @@ package org.apache.hertzbeat.manager.service; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anySet; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.when; +import java.util.Collections; +import java.util.HashSet; +import java.util.Optional; import org.apache.hertzbeat.common.entity.manager.Tag; import org.apache.hertzbeat.manager.dao.TagDao; import org.apache.hertzbeat.manager.service.impl.TagServiceImpl; @@ -29,14 +41,6 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.Specification; -import java.util.Collections; -import java.util.HashSet; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; - /** * Test case for {@link TagService} */ diff --git a/remoting/src/test/java/org/apache/hertzbeat/remoting/RemotingServiceTest.java b/remoting/src/test/java/org/apache/hertzbeat/remoting/RemotingServiceTest.java index 27041454834..b37e23ff1e5 100644 --- a/remoting/src/test/java/org/apache/hertzbeat/remoting/RemotingServiceTest.java +++ b/remoting/src/test/java/org/apache/hertzbeat/remoting/RemotingServiceTest.java @@ -17,13 +17,13 @@ package org.apache.hertzbeat.remoting; +import org.apache.hertzbeat.common.entity.message.ClusterMsg; +import org.apache.hertzbeat.common.support.CommonThreadPool; import org.apache.hertzbeat.remoting.netty.NettyClientConfig; import org.apache.hertzbeat.remoting.netty.NettyRemotingClient; import org.apache.hertzbeat.remoting.netty.NettyRemotingServer; import org.apache.hertzbeat.remoting.netty.NettyServerConfig; import org.assertj.core.util.Lists; -import org.apache.hertzbeat.common.entity.message.ClusterMsg; -import org.apache.hertzbeat.common.support.CommonThreadPool; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; diff --git a/warehouse/src/test/java/org/apache/hertzbeat/warehouse/WarehouseWorkerPoolTest.java b/warehouse/src/test/java/org/apache/hertzbeat/warehouse/WarehouseWorkerPoolTest.java index 44c4f897db9..028ae722cb1 100644 --- a/warehouse/src/test/java/org/apache/hertzbeat/warehouse/WarehouseWorkerPoolTest.java +++ b/warehouse/src/test/java/org/apache/hertzbeat/warehouse/WarehouseWorkerPoolTest.java @@ -18,7 +18,6 @@ package org.apache.hertzbeat.warehouse; import static org.junit.jupiter.api.Assertions.assertEquals; - import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; import org.junit.jupiter.api.BeforeEach; diff --git a/warehouse/src/test/java/org/apache/hertzbeat/warehouse/controller/MetricsDataControllerTest.java b/warehouse/src/test/java/org/apache/hertzbeat/warehouse/controller/MetricsDataControllerTest.java index e6355089fa4..6d8c07134e5 100644 --- a/warehouse/src/test/java/org/apache/hertzbeat/warehouse/controller/MetricsDataControllerTest.java +++ b/warehouse/src/test/java/org/apache/hertzbeat/warehouse/controller/MetricsDataControllerTest.java @@ -17,10 +17,22 @@ package org.apache.hertzbeat.warehouse.controller; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import jakarta.servlet.ServletException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.common.entity.dto.Value; import org.apache.hertzbeat.common.entity.message.CollectRep; -import org.apache.hertzbeat.common.constants.CommonConstants; import org.apache.hertzbeat.warehouse.store.AbstractHistoryDataStorage; import org.apache.hertzbeat.warehouse.store.AbstractRealTimeDataStorage; import org.junit.jupiter.api.BeforeEach; @@ -35,16 +47,6 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import java.util.*; - -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.lenient; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - /** * Test case for {@link MetricsDataController} */ From ba81702689ea0b07e38fc86f65c93b1373cfce91 Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Sat, 27 Apr 2024 22:22:22 +0800 Subject: [PATCH 2/2] merge from master --- .../org/apache/hertzbeat/manager/ManagerTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/manager/src/test/java/org/apache/hertzbeat/manager/ManagerTest.java b/manager/src/test/java/org/apache/hertzbeat/manager/ManagerTest.java index 22bbb369f45..79d8f528532 100644 --- a/manager/src/test/java/org/apache/hertzbeat/manager/ManagerTest.java +++ b/manager/src/test/java/org/apache/hertzbeat/manager/ManagerTest.java @@ -17,6 +17,8 @@ package org.apache.hertzbeat.manager; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import javax.annotation.Resource; import javax.naming.NamingException; import org.apache.hertzbeat.alert.AlerterProperties; @@ -51,8 +53,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.context.ApplicationContext; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; /** * @@ -108,11 +108,11 @@ void testAutoImport() { } @Test - void testJNDI() throws NamingException { -// System.setProperty("jdk.jndi.object.factoriesFilter", "!com.zaxxer.hikari.HikariJNDIFactory"); + void testJndi() throws NamingException { + //System.setProperty("jdk.jndi.object.factoriesFilter", "!com.zaxxer.hikari.HikariJNDIFactory"); // for CI -// InitialContext initialContext = new InitialContext(); -// initialContext.lookup("rmi://localhost:1099/Exploit"); + //InitialContext initialContext = new InitialContext(); + //initialContext.lookup("rmi://localhost:1099/Exploit"); } }