Browse Source

Improve NotificationRuleApiTest

pull/14661/head
Andrii Landiak 5 months ago
parent
commit
c6af9659fa
  1. 8
      application/src/test/java/org/thingsboard/server/service/notification/AbstractNotificationApiTest.java
  2. 10
      application/src/test/java/org/thingsboard/server/service/notification/NotificationRuleApiTest.java

8
application/src/test/java/org/thingsboard/server/service/notification/AbstractNotificationApiTest.java

@ -19,9 +19,8 @@ import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.After;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.util.Pair;
import org.thingsboard.rule.engine.api.MailService;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.thingsboard.rule.engine.api.notification.SlackService;
import org.thingsboard.server.common.data.User;
import org.thingsboard.server.common.data.id.NotificationRequestId;
@ -69,10 +68,8 @@ public abstract class AbstractNotificationApiTest extends AbstractControllerTest
protected NotificationApiWsClient wsClient;
protected NotificationApiWsClient otherWsClient;
@MockBean
@MockitoBean
protected SlackService slackService;
@Autowired
protected MailService mailService;
@Autowired
protected NotificationRuleService notificationRuleService;
@ -225,4 +222,5 @@ public abstract class AbstractNotificationApiTest extends AbstractControllerTest
public NotificationApiWsClient getAnotherWsClient() {
return (NotificationApiWsClient) super.getAnotherWsClient();
}
}

10
application/src/test/java/org/thingsboard/server/service/notification/NotificationRuleApiTest.java

@ -812,13 +812,13 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
@Test
public void testNotificationsDeduplication_resourcesShortage() throws Exception {
loginSysAdmin();
NotificationTarget sysadmins = createNotificationTarget(new SystemAdministratorsFilter());
ResourcesShortageNotificationRuleTriggerConfig triggerConfig = ResourcesShortageNotificationRuleTriggerConfig.builder()
.ramThreshold(0.01f)
.cpuThreshold(1f)
.storageThreshold(1f)
.build();
createNotificationRule(triggerConfig, "Warning: ${resource} shortage", "${resource} shortage", createNotificationTarget(tenantAdminUserId).getId());
loginTenantAdmin();
createNotificationRule(triggerConfig, "Warning: ${resource} shortage", "${resource} shortage", sysadmins.getId());
assertThat(getMyNotifications(false, 100)).size().isZero();
for (int i = 0; i < 10; i++) {
@ -848,13 +848,13 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
@Test
public void testNotificationsResourcesShortage_whenThresholdChangeToMatchingFilter_thenSendNotification() throws Exception {
loginSysAdmin();
NotificationTarget sysadmins = createNotificationTarget(new SystemAdministratorsFilter());
ResourcesShortageNotificationRuleTriggerConfig triggerConfig = ResourcesShortageNotificationRuleTriggerConfig.builder()
.ramThreshold(1f)
.cpuThreshold(1f)
.storageThreshold(1f)
.build();
NotificationRule rule = createNotificationRule(triggerConfig, "Warning: ${resource} shortage", "${resource} shortage", createNotificationTarget(tenantAdminUserId).getId());
loginTenantAdmin();
NotificationRule rule = createNotificationRule(triggerConfig, "Warning: ${resource} shortage", "${resource} shortage", sysadmins.getId());
Method method = DefaultSystemInfoService.class.getDeclaredMethod("saveCurrentMonolithSystemInfo");
method.setAccessible(true);
@ -863,7 +863,6 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
TimeUnit.SECONDS.sleep(5);
assertThat(getMyNotifications(false, 100)).size().isZero();
loginSysAdmin();
triggerConfig = ResourcesShortageNotificationRuleTriggerConfig.builder()
.ramThreshold(0.01f)
.cpuThreshold(1f)
@ -871,7 +870,6 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
.build();
rule.setTriggerConfig(triggerConfig);
saveNotificationRule(rule);
loginTenantAdmin();
method.invoke(systemInfoService);

Loading…
Cancel
Save