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

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

commit 293d44650587c740bcecb6a6727852e79ed0176d
Author: tomsun28 <[email protected]>
AuthorDate: Mon Oct 27 21:26:44 2025 +0800

    fix
    
    Signed-off-by: tomsun28 <[email protected]>
---
 .../alert/service/AlertDefineServiceTest.java      |   8 +-
 .../manager/service/AlertDefineServiceTest.java    | 124 ---------------------
 2 files changed, 4 insertions(+), 128 deletions(-)

diff --git 
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/AlertDefineServiceTest.java
 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/AlertDefineServiceTest.java
index 825e34434..4f40c17de 100644
--- 
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/AlertDefineServiceTest.java
+++ 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/AlertDefineServiceTest.java
@@ -105,19 +105,19 @@ class AlertDefineServiceTest {
 
     @Test
     void addAlertDefine() {
-        assertDoesNotThrow(() -> 
alertDefineService.addAlertDefine(alertDefine));
+        assertDoesNotThrow(() -> 
this.alertDefineService.addAlertDefine(alertDefine));
         when(alertDefineDao.saveAndFlush(alertDefine)).thenThrow(new 
RuntimeException());
-        assertThrows(RuntimeException.class, () -> 
alertDefineService.addAlertDefine(alertDefine));
+        assertThrows(RuntimeException.class, () -> 
this.alertDefineService.addAlertDefine(alertDefine));
     }
 
     @Test
     void modifyAlertDefine() {
         AlertDefine alertDefine = AlertDefine.builder().id(1L).build();
         when(alertDefineDao.saveAndFlush(alertDefine)).thenReturn(alertDefine);
-        assertDoesNotThrow(() -> 
alertDefineService.modifyAlertDefine(alertDefine));
+        assertDoesNotThrow(() -> 
this.alertDefineService.modifyAlertDefine(alertDefine));
         reset();
         when(alertDefineDao.saveAndFlush(alertDefine)).thenThrow(new 
RuntimeException());
-        assertThrows(RuntimeException.class, () -> 
alertDefineService.modifyAlertDefine(alertDefine));
+        assertThrows(RuntimeException.class, () -> 
this.alertDefineService.modifyAlertDefine(alertDefine));
     }
 
     @Test
diff --git 
a/hertzbeat-manager/src/test/java/org/apache/hertzbeat/manager/service/AlertDefineServiceTest.java
 
b/hertzbeat-manager/src/test/java/org/apache/hertzbeat/manager/service/AlertDefineServiceTest.java
deleted file mode 100644
index 2d7810d41..000000000
--- 
a/hertzbeat-manager/src/test/java/org/apache/hertzbeat/manager/service/AlertDefineServiceTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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.manager.service;
-
-import org.apache.hertzbeat.alert.dao.AlertDefineDao;
-import org.apache.hertzbeat.alert.service.AlertDefineService;
-import org.apache.hertzbeat.common.entity.alerter.AlertDefine;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-
-import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.List;
-
-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.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-/**
- * Test case for {@link AlertDefineService}
- */
-public class AlertDefineServiceTest {
-
-    @InjectMocks
-    private AlertDefineService alertDefineService;
-    
-    @Mock
-    private AlertDefineDao alertDefineDao;
-
-    private List<Long> createdIds = new ArrayList<>();
-
-    @BeforeEach
-    void setUp() {
-        createdIds.clear();
-    }
-
-    @AfterEach
-    void tearDown() {
-        for (Long id : createdIds) {
-            if (alertDefineDao.existsById(id)) {
-                alertDefineDao.deleteById(id);
-            }
-        }
-    }
-
-    @Test
-    void testAddAlertDefine() {
-        AlertDefine alertDefine = AlertDefine.builder()
-                .name("test-cpu-alert")
-                .expr("usage > 80")
-                .times(3)
-                .type("periodic")
-                .enable(true)
-                .period(10)
-                .template("CPU usage is excessively high: ${usage}%")
-                .creator("integration-test")
-                .modifier("integration-test")
-                .gmtCreate(LocalDateTime.now())
-                .gmtUpdate(LocalDateTime.now())
-                .build();
-        assertNull(alertDefine.getId());
-        assertDoesNotThrow(() -> 
alertDefineService.addAlertDefine(alertDefine));
-
-        assertNotNull(alertDefine.getId());
-        assertTrue(alertDefine.getId() > 0);
-
-        createdIds.add(alertDefine.getId());
-
-        AlertDefine savedAlertDefine = 
alertDefineDao.findById(alertDefine.getId()).orElse(null);
-        assertNotNull(savedAlertDefine);
-        assertEquals("usage > 80", savedAlertDefine.getExpr());
-        assertEquals("integration-test", savedAlertDefine.getCreator());
-    }
-
-    @Test
-    void testModifyAlertDefine() {
-        AlertDefine alertDefine = AlertDefine.builder()
-                .name("test-cpu-alert")
-                .expr("usage > 80")
-                .times(3)
-                .type("periodic")
-                .enable(true)
-                .period(10)
-                .template("CPU usage is excessively high: ${usage}%")
-                .creator("integration-test")
-                .modifier("integration-test")
-                .gmtCreate(LocalDateTime.now())
-                .gmtUpdate(LocalDateTime.now())
-                .build();
-        assertNull(alertDefine.getId());
-        assertDoesNotThrow(() -> 
alertDefineService.modifyAlertDefine(alertDefine));
-
-        assertNotNull(alertDefine.getId());
-        assertTrue(alertDefine.getId() > 0);
-
-        createdIds.add(alertDefine.getId());
-
-        AlertDefine savedAlertDefine = 
alertDefineDao.findById(alertDefine.getId()).orElse(null);
-        assertNotNull(savedAlertDefine);
-        assertEquals("usage > 80", savedAlertDefine.getExpr());
-        assertEquals("integration-test", savedAlertDefine.getCreator());
-    }
-
-}


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

Reply via email to