This is an automated email from the ASF dual-hosted git repository.

gongchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git


The following commit(s) were added to refs/heads/master by this push:
     new 9a3fc5911d [fix] fix jacoco can not generate test reports. (#3455)
9a3fc5911d is described below

commit 9a3fc5911d386551efec2993c537900745dbd6ad
Author: Duansg <[email protected]>
AuthorDate: Sat Jun 14 00:21:07 2025 +0800

    [fix] fix jacoco can not generate test reports. (#3455)
    
    Co-authored-by: tomsun28 <[email protected]>
---
 .../AlibabaCloudSlsExternAlertServiceTest.java     |  2 -
 .../service/HuaweiCloudExternAlertServiceTest.java |  2 -
 .../alert/service/SmsClientFactoryTest.java        | 92 ++++++++++++++++++++++
 .../service/impl/SmsLocalSmsClientImplTest.java    | 73 +++++++++++++++++
 .../alert/service/impl/UniSmsClientImplTest.java   | 85 ++++++++++++++++++++
 .../hertzbeat/alert/util/CryptoUtilsTest.java      | 48 +++++++++++
 .../apache/hertzbeat/alert/util/DateUtilTest.java  | 10 +++
 pom.xml                                            |  9 ++-
 8 files changed, 315 insertions(+), 6 deletions(-)

diff --git 
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/AlibabaCloudSlsExternAlertServiceTest.java
 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/AlibabaCloudSlsExternAlertServiceTest.java
index a518ba0081..d3aeb5aa95 100644
--- 
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/AlibabaCloudSlsExternAlertServiceTest.java
+++ 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/AlibabaCloudSlsExternAlertServiceTest.java
@@ -23,7 +23,6 @@ import org.apache.hertzbeat.alert.reduce.AlarmCommonReduce;
 import 
org.apache.hertzbeat.alert.service.impl.AlibabaCloudSlsExternAlertService;
 import org.apache.hertzbeat.common.entity.alerter.SingleAlert;
 import org.apache.hertzbeat.common.util.JsonUtil;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.InjectMocks;
@@ -43,7 +42,6 @@ import static org.mockito.Mockito.verify;
 /**
  * unit test for {@link AlibabaCloudSlsExternAlertServiceTest }
  */
-@Disabled
 @ExtendWith(MockitoExtension.class)
 public class AlibabaCloudSlsExternAlertServiceTest {
 
diff --git 
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/HuaweiCloudExternAlertServiceTest.java
 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/HuaweiCloudExternAlertServiceTest.java
index 7167a5dcca..b29b948251 100644
--- 
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/HuaweiCloudExternAlertServiceTest.java
+++ 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/HuaweiCloudExternAlertServiceTest.java
@@ -23,7 +23,6 @@ import 
org.apache.hertzbeat.alert.service.impl.HuaweiCloudExternAlertService;
 import org.apache.hertzbeat.common.entity.alerter.SingleAlert;
 import org.apache.hertzbeat.common.util.JsonUtil;
 import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.InjectMocks;
@@ -39,7 +38,6 @@ import static org.mockito.Mockito.verify;
 /**
  * unit test for {@link AlibabaCloudSlsExternAlertServiceTest }
  */
-@Disabled
 @ExtendWith(MockitoExtension.class)
 public class HuaweiCloudExternAlertServiceTest {
 
diff --git 
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/SmsClientFactoryTest.java
 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/SmsClientFactoryTest.java
new file mode 100644
index 0000000000..d40e112812
--- /dev/null
+++ 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/SmsClientFactoryTest.java
@@ -0,0 +1,92 @@
+/*
+ * 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.hertzbeat.alert.service;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.hertzbeat.alert.config.SmsConfig;
+import org.apache.hertzbeat.alert.config.SmslocalSmsProperties;
+import org.apache.hertzbeat.base.dao.GeneralConfigDao;
+import org.apache.hertzbeat.common.constants.GeneralConfigTypeEnum;
+import org.apache.hertzbeat.common.entity.manager.GeneralConfig;
+import org.apache.hertzbeat.common.util.JsonUtil;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.when;
+
+
+/**
+ * unit test for {@link SmsClientFactory }
+ */
+@ExtendWith(MockitoExtension.class)
+public class SmsClientFactoryTest {
+
+
+    @Mock
+    private GeneralConfigDao generalConfigDao;
+
+    @Mock
+    private ObjectMapper objectMapper;
+
+    @Mock
+    private SmsConfig yamlSmsConfig;
+
+    @InjectMocks
+    private SmsClientFactory smsClientFactory;
+
+
+    @Test
+    void testloadDbConfig() throws JsonProcessingException {
+        GeneralConfig generalConfig = new GeneralConfig();
+
+        SmsConfig smsConfig = new SmsConfig();
+        smsConfig.setType("smslocal");
+        smsConfig.setEnable(true);
+        smsConfig.setSmslocal(new SmslocalSmsProperties("11"));
+
+        generalConfig.setContent(JsonUtil.toJson(smsConfig));
+        when(objectMapper.readValue(generalConfig.getContent(), 
SmsConfig.class)).thenReturn(smsConfig);
+        
when(generalConfigDao.findByType(GeneralConfigTypeEnum.sms.name())).thenReturn(generalConfig);
+
+        assertNotNull(smsClientFactory.getSmsClient());
+
+    }
+
+    @Test
+    void testloadYamlConfig() {
+        
when(generalConfigDao.findByType(GeneralConfigTypeEnum.sms.name())).thenReturn(null);
+        when(yamlSmsConfig.getType()).thenReturn("smslocal");
+        when(yamlSmsConfig.isEnable()).thenReturn(true);
+        when(yamlSmsConfig.getSmslocal()).thenReturn(new 
SmslocalSmsProperties("11"));
+        assertNotNull(smsClientFactory.getSmsClient());
+    }
+
+    @Test
+    void testNull() {
+        
when(generalConfigDao.findByType(GeneralConfigTypeEnum.sms.name())).thenReturn(null);
+        when(yamlSmsConfig.getType()).thenReturn("");
+        assertNull(smsClientFactory.getSmsClient());
+    }
+
+}
\ No newline at end of file
diff --git 
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/impl/SmsLocalSmsClientImplTest.java
 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/impl/SmsLocalSmsClientImplTest.java
new file mode 100644
index 0000000000..1cbc8b017d
--- /dev/null
+++ 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/impl/SmsLocalSmsClientImplTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.hertzbeat.alert.service.impl;
+
+import com.google.common.collect.Lists;
+import org.apache.hertzbeat.alert.config.SmslocalSmsProperties;
+import org.apache.hertzbeat.common.entity.alerter.GroupAlert;
+import org.apache.hertzbeat.common.entity.alerter.NoticeReceiver;
+import org.apache.hertzbeat.common.entity.alerter.SingleAlert;
+import org.apache.hertzbeat.common.support.exception.SendMessageException;
+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.junit.jupiter.MockitoExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test case for {@link SmsLocalSmsClientImpl}
+ */
+@ExtendWith(MockitoExtension.class)
+public class SmsLocalSmsClientImplTest {
+
+    @Mock
+    private SmslocalSmsProperties smslocalSmsProperties;
+
+    private SmsLocalSmsClientImpl smsLocalSmsClient;
+
+
+    @BeforeEach
+    void setUp() {
+        smsLocalSmsClient = new SmsLocalSmsClientImpl(smslocalSmsProperties);
+        when(smslocalSmsProperties.getApiKey()).thenReturn("2");
+    }
+
+    @Test
+    void testSendMessage() {
+        assertEquals("smslocal", smsLocalSmsClient.getType());
+        assertTrue(smsLocalSmsClient.checkConfig());
+        //
+        NoticeReceiver noticeReceiver = new NoticeReceiver();
+        noticeReceiver.setPhone("13888888888");
+
+        SingleAlert singleAlert = new SingleAlert();
+        singleAlert.setContent("test");
+
+        GroupAlert groupAlert = new GroupAlert();
+        groupAlert.setAlerts(Lists.newArrayList(singleAlert));
+
+        assertThrows(SendMessageException.class,
+                () -> smsLocalSmsClient.sendMessage(noticeReceiver, null, 
groupAlert));
+    }
+
+}
\ No newline at end of file
diff --git 
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/impl/UniSmsClientImplTest.java
 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/impl/UniSmsClientImplTest.java
new file mode 100644
index 0000000000..95ca6cda44
--- /dev/null
+++ 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/impl/UniSmsClientImplTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.hertzbeat.alert.service.impl;
+
+import org.apache.hertzbeat.alert.config.UniSmsProperties;
+import org.apache.hertzbeat.common.entity.alerter.GroupAlert;
+import org.apache.hertzbeat.common.entity.alerter.NoticeReceiver;
+import org.apache.hertzbeat.common.support.exception.SendMessageException;
+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.junit.jupiter.MockitoExtension;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.when;
+
+
+/**
+ * Test case for {@link UniSmsClientImpl}
+ */
+@ExtendWith(MockitoExtension.class)
+public class UniSmsClientImplTest {
+
+    @Mock
+    private UniSmsProperties uniSmsProperties;
+
+    private UniSmsClientImpl uniSmsClient;
+
+    @BeforeEach
+    void setUp() {
+        uniSmsClient = new UniSmsClientImpl(uniSmsProperties);
+        when(uniSmsProperties.getSignature()).thenReturn("2");
+        when(uniSmsProperties.getTemplateId()).thenReturn("any(String.class)");
+        when(uniSmsProperties.getAuthMode()).thenReturn("hmac");
+        when(uniSmsProperties.getAccessKeyId()).thenReturn("hmac");
+        when(uniSmsProperties.getAccessKeySecret()).thenReturn("hmac");
+    }
+
+    @Test
+    void testSendMessage() {
+        assertEquals("unisms", uniSmsClient.getType());
+        assertTrue(uniSmsClient.checkConfig());
+        //
+        NoticeReceiver noticeReceiver = new NoticeReceiver();
+        noticeReceiver.setPhone("13888888888");
+
+        Map<String, String> commonLabels = new HashMap<>();
+        commonLabels.put("instance", "");
+        commonLabels.put("priority", "unknown");
+
+        Map<String, String> commonAnnotations = new HashMap<>();
+        commonAnnotations.put("test", "test");
+
+        GroupAlert groupAlert = new GroupAlert();
+        groupAlert.setCommonLabels(commonLabels);
+        groupAlert.setCommonAnnotations(commonAnnotations);
+
+        assertThrows(SendMessageException.class,
+                () -> uniSmsClient.sendMessage(noticeReceiver, null, 
groupAlert));
+
+    }
+
+
+}
\ No newline at end of file
diff --git 
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/util/CryptoUtilsTest.java
 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/util/CryptoUtilsTest.java
new file mode 100644
index 0000000000..cb8047264c
--- /dev/null
+++ 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/util/CryptoUtilsTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.hertzbeat.alert.util;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Test case for {@link CryptoUtils}
+ */
+public class CryptoUtilsTest {
+
+
+    @Test
+    void testSha256Hex() {
+        String sign = CryptoUtils.sha256Hex("Hello world.");
+        
assertEquals("aa3ec16e6acc809d8b2818662276256abfd2f1b441cb51574933f3d4bd115d11",
 sign);
+    }
+
+    @Test
+    void testHmacSha256Base64Debug() {
+        String signature = CryptoUtils.hmacSha256Base64("your-real-key", 
"your-real-data");
+        assertEquals("8JrfX0v5Tt3s8PfI85o6jcf5XM3C+vLlMwvFp45LupU=", 
signature);
+    }
+
+    @Test
+    void testHmacSha256Hex() {
+        String signature = CryptoUtils.hmacSha256Hex("your-real-key", 
"your-real-data");;
+        
assertEquals("41878ccd7ecd795a2dd7ec39be7f33fed4be3ec75f5307689e39dd6f41fdbaac",
 signature);
+    }
+
+}
\ No newline at end of file
diff --git 
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/util/DateUtilTest.java
 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/util/DateUtilTest.java
index 0c2c2a9fa2..e60515ac04 100644
--- 
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/util/DateUtilTest.java
+++ 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/util/DateUtilTest.java
@@ -19,6 +19,7 @@ package org.apache.hertzbeat.alert.util;
 
 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 java.util.Optional;
 import org.junit.jupiter.api.Test;
@@ -58,4 +59,13 @@ class DateUtilTest {
         actualTimestamp = DateUtil.getTimeStampFromFormat(date, format);
         assertFalse(actualTimestamp.isPresent());
     }
+
+    @Test
+    void getZonedTimeStampFromFormat() {
+        String dataStr = "2025/06/02 22:56:15 GMT+08:00";
+        Long time = DateUtil.getZonedTimeStampFromFormat(dataStr, "yyyy/MM/dd 
HH:mm:ss 'GMT'XXX");
+        assertNotNull(time);
+        assertEquals(1748876175000L, time);
+    }
+
 }
diff --git a/pom.xml b/pom.xml
index b9efd59f59..3f8880ffef 100644
--- a/pom.xml
+++ b/pom.xml
@@ -524,7 +524,9 @@
                 <artifactId>maven-surefire-plugin</artifactId>
                 <version>${maven-surefire-plugin.version}</version>
                 <configuration>
-                    
<argLine>--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED</argLine>
+                    <argLine>
+                        ${argLine} 
--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED
+                    </argLine>
                 </configuration>
             </plugin>
             <!-- java code style check -->
@@ -557,13 +559,16 @@
                 <version>${jacoco-maven-plugin.version}</version>
                 <executions>
                     <execution>
+                        <id>prepare-agent</id>
+                        <phase>initialize</phase>
                         <goals>
                             <goal>prepare-agent</goal>
                         </goals>
                     </execution>
+
                     <execution>
                         <id>report</id>
-                        <phase>test</phase>
+                        <phase>verify</phase>
                         <goals>
                             <goal>report</goal>
                         </goals>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to