Skip to content

Commit

Permalink
alert warnings and tests fix (#1555)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-little-fool committed Feb 20, 2024
1 parent 1c8ea86 commit 85e9296
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public ResponseEntity<Message<Void>> addNewAlertReportFromCloud(@PathVariable("c
CloudAlertReportAbstract cloudAlertReport = JsonUtil
.fromJson(alertReport, cloudService.getCloudServiceAlarmInformationEntity());
// 模板填充
assert cloudAlertReport != null;
alert = AlertReport.builder()
.content(cloudAlertReport.getContent())
.alertName(cloudAlertReport.getAlertName())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package org.dromara.hertzbeat.alert.service;

import com.fasterxml.jackson.databind.json.JsonMapper;
import org.dromara.hertzbeat.alert.dao.AlertDefineBindDao;
import org.dromara.hertzbeat.alert.dao.AlertDefineDao;
import org.dromara.hertzbeat.alert.service.impl.AlertDefineExcelImExportServiceImpl;
import org.dromara.hertzbeat.alert.service.impl.AlertDefineJsonImExportServiceImpl;
import org.dromara.hertzbeat.alert.service.impl.AlertDefineServiceImpl;
import org.dromara.hertzbeat.alert.service.impl.AlertDefineYamlImExportServiceImpl;
import org.dromara.hertzbeat.common.entity.alerter.AlertDefine;
import org.dromara.hertzbeat.common.entity.alerter.AlertDefineMonitorBind;
import org.dromara.hertzbeat.common.entity.manager.Monitor;
Expand All @@ -20,7 +16,6 @@
import org.springframework.data.jpa.domain.Specification;
import org.springframework.test.util.ReflectionTestUtils;

import javax.persistence.criteria.CriteriaBuilder;
import java.util.*;

import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -46,7 +41,7 @@ class AlertDefineServiceTest {
private List<AlertDefineImExportService> alertDefineImExportServiceList;

@InjectMocks
private AlertDefineServiceImpl alertDefineService = new AlertDefineServiceImpl(Collections.emptyList());
private AlertDefineServiceImpl alertDefineService;

@BeforeEach
void setUp() {
Expand Down Expand Up @@ -88,15 +83,13 @@ void setUp() {
void validate() {
assertDoesNotThrow(() -> alertDefineService.validate(alertDefine, true));
assertDoesNotThrow(() -> alertDefineService.validate(alertDefine, false));

}

@Test
void addAlertDefine() {
assertDoesNotThrow(() -> alertDefineService.addAlertDefine(alertDefine));
when(alertDefineDao.save(alertDefine)).thenThrow(new RuntimeException());
assertThrows(RuntimeException.class, () -> alertDefineService.addAlertDefine(alertDefine));

}

@Test
Expand All @@ -115,7 +108,6 @@ void deleteAlertDefine() {
doNothing().doThrow(new RuntimeException()).when(alertDefineDao).deleteById(id);
assertDoesNotThrow(() -> alertDefineService.deleteAlertDefine(id));
assertThrows(RuntimeException.class, () -> alertDefineService.deleteAlertDefine(id));

}

@Test
Expand All @@ -137,8 +129,6 @@ void getMonitorBindAlertDefines() {
Specification<AlertDefine> specification = mock(Specification.class);
when(alertDefineDao.findAll(specification, PageRequest.of(1, 1))).thenReturn(Page.empty());
assertNotNull(alertDefineService.getMonitorBindAlertDefines(specification, PageRequest.of(1, 1)));


}

@Test
Expand All @@ -156,7 +146,6 @@ void testGetMonitorBindAlertDefines() {
when(alertDefineDao.queryAlertDefinesByMonitor(1L, "app", "test")).thenReturn(alertDefineList);
when(alertDefineDao.queryAlertDefinesByAppAndMetricAndPresetTrueAndEnableTrue("app", "test")).thenReturn(alertDefineList);
assertNotNull(alertDefineService.getMonitorBindAlertDefines(1L, "app", "test"));

}

@Test
Expand Down

0 comments on commit 85e9296

Please sign in to comment.