Browse Source

Fix notification system tests

pull/7911/head
ViacheslavKlimov 4 years ago
parent
commit
4673e812b0
  1. 10
      application/src/test/java/org/thingsboard/server/service/notification/NotificationApiTest.java
  2. 19
      application/src/test/java/org/thingsboard/server/service/notification/NotificationRuleApiTest.java

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

@ -439,14 +439,14 @@ public class NotificationApiTest extends AbstractNotificationApiTest {
assertThat(processedTemplates.get(NotificationDeliveryMethod.SLACK)).asInstanceOf(type(SlackDeliveryMethodNotificationTemplate.class)) assertThat(processedTemplates.get(NotificationDeliveryMethod.SLACK)).asInstanceOf(type(SlackDeliveryMethodNotificationTemplate.class))
.satisfies(template -> { .satisfies(template -> {
assertThat(template.getBody()) assertThat(template.getBody())
.isEqualTo("Message for SLACK: ${recipientEmail}"); // ${recipientEmail} should not be processed .isEqualTo("Message for SLACK: "); // ${recipientEmail} should be removed
}); });
} }
@Test @Test
public void testNotificationRequestInfo() throws Exception { public void testNotificationRequestInfo() throws Exception {
NotificationDeliveryMethod[] deliveryMethods = new NotificationDeliveryMethod[]{ NotificationDeliveryMethod[] deliveryMethods = new NotificationDeliveryMethod[]{
NotificationDeliveryMethod.WEB, NotificationDeliveryMethod.EMAIL NotificationDeliveryMethod.WEB
}; };
NotificationTemplate template = createNotificationTemplate(NotificationType.GENERAL, "Test subject", "Test text", deliveryMethods); NotificationTemplate template = createNotificationTemplate(NotificationType.GENERAL, "Test subject", "Test text", deliveryMethods);
NotificationTarget target = createNotificationTarget(tenantAdminUserId); NotificationTarget target = createNotificationTarget(tenantAdminUserId);
@ -465,8 +465,7 @@ public class NotificationApiTest extends AbstractNotificationApiTest {
wsClient.registerWaitForUpdate(); wsClient.registerWaitForUpdate();
NotificationTarget notificationTarget = createNotificationTarget(customerUserId); NotificationTarget notificationTarget = createNotificationTarget(customerUserId);
NotificationRequest notificationRequest = submitNotificationRequest(notificationTarget.getId(), "Test :)", NotificationRequest notificationRequest = submitNotificationRequest(notificationTarget.getId(), "Test :)", NotificationDeliveryMethod.WEB);
NotificationDeliveryMethod.WEB, NotificationDeliveryMethod.SMS);
wsClient.waitForUpdate(); wsClient.waitForUpdate();
await().atMost(2, TimeUnit.SECONDS) await().atMost(2, TimeUnit.SECONDS)
@ -474,7 +473,6 @@ public class NotificationApiTest extends AbstractNotificationApiTest {
NotificationRequestStats stats = getStats(notificationRequest.getId()); NotificationRequestStats stats = getStats(notificationRequest.getId());
assertThat(stats.getSent().get(NotificationDeliveryMethod.WEB)).hasValue(1); assertThat(stats.getSent().get(NotificationDeliveryMethod.WEB)).hasValue(1);
assertThat(stats.getErrors().get(NotificationDeliveryMethod.SMS)).size().isOne();
} }
@Test @Test
@ -559,7 +557,7 @@ public class NotificationApiTest extends AbstractNotificationApiTest {
NotificationRequest successfulNotificationRequest = submitNotificationRequest(List.of(notificationTarget.getId()), notificationTemplate.getId(), 0); NotificationRequest successfulNotificationRequest = submitNotificationRequest(List.of(notificationTarget.getId()), notificationTemplate.getId(), 0);
await().atMost(2, TimeUnit.SECONDS) await().atMost(2, TimeUnit.SECONDS)
.until(() -> findNotificationRequest(successfulNotificationRequest.getId()).isSent()); .until(() -> findNotificationRequest(successfulNotificationRequest.getId()).isSent());
verify(slackService).sendMessage(eq(tenantId), eq(slackToken), eq(conversationId), eq(slackNotificationTemplate.getBody())); verify(slackService).sendMessage(eq(tenantId), eq(slackToken), eq(conversationId), eq("To Slack :) "));
NotificationRequestStats stats = getStats(successfulNotificationRequest.getId()); NotificationRequestStats stats = getStats(successfulNotificationRequest.getId());
assertThat(stats.getSent().get(NotificationDeliveryMethod.SLACK)).hasValue(1); assertThat(stats.getSent().get(NotificationDeliveryMethod.SLACK)).hasValue(1);

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

@ -232,20 +232,17 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
double actualDelay = (double) (notification.getCreatedTime() - ts) / 1000; double actualDelay = (double) (notification.getCreatedTime() - ts) / 1000;
assertThat(actualDelay).isCloseTo(expectedDelay, offset(0.5)); assertThat(actualDelay).isCloseTo(expectedDelay, offset(0.5));
AlarmStatus expectedStatus = AlarmStatus.ACTIVE_UNACK; assertThat(notification.getSubject()).isEqualTo("Alarm type: " + alarmType + ", status: " + AlarmStatus.ACTIVE_UNACK + ", " +
String expectedSeverity = AlarmSeverity.CRITICAL.toString().toLowerCase(); "severity: " + AlarmSeverity.CRITICAL.toString().toLowerCase() + ", deviceId: " + device.getId());
assertThat(notification.getText()).isEqualTo("Status: " + AlarmStatus.ACTIVE_UNACK + ", severity: " + AlarmSeverity.CRITICAL.toString().toLowerCase());
assertThat(notification.getSubject()).isEqualTo("Alarm type: " + alarmType + ", status: " + expectedStatus + ", " +
"severity: " + expectedSeverity + ", deviceId: " + device.getId());
assertThat(notification.getText()).isEqualTo("Status: " + expectedStatus + ", severity: " + expectedSeverity);
assertThat(notification.getType()).isEqualTo(NotificationType.ALARM); assertThat(notification.getType()).isEqualTo(NotificationType.ALARM);
assertThat(notification.getInfo()).isInstanceOf(AlarmNotificationInfo.class); assertThat(notification.getInfo()).isInstanceOf(AlarmNotificationInfo.class);
AlarmNotificationInfo info = (AlarmNotificationInfo) notification.getInfo(); AlarmNotificationInfo info = (AlarmNotificationInfo) notification.getInfo();
assertThat(info.getAlarmId()).isEqualTo(alarm.getUuidId()); assertThat(info.getAlarmId()).isEqualTo(alarm.getUuidId());
assertThat(info.getAlarmType()).isEqualTo(alarmType); assertThat(info.getAlarmType()).isEqualTo(alarmType);
assertThat(info.getAlarmSeverity()).isEqualTo(expectedSeverity); assertThat(info.getAlarmSeverity()).isEqualTo(AlarmSeverity.CRITICAL);
assertThat(info.getAlarmStatus()).isEqualTo(expectedStatus); assertThat(info.getAlarmStatus()).isEqualTo(AlarmStatus.ACTIVE_UNACK);
}); });
clients.values().forEach(wsClient -> wsClient.registerWaitForUpdate()); clients.values().forEach(wsClient -> wsClient.registerWaitForUpdate());
@ -256,8 +253,8 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
wsClient.waitForUpdate(true); wsClient.waitForUpdate(true);
Notification updatedNotification = wsClient.getLastDataUpdate().getUpdate(); Notification updatedNotification = wsClient.getLastDataUpdate().getUpdate();
assertThat(updatedNotification.getSubject()).isEqualTo("Alarm type: " + alarmType + ", status: " + expectedStatus + ", " + assertThat(updatedNotification.getSubject()).isEqualTo("Alarm type: " + alarmType + ", status: " + expectedStatus + ", " +
"severity: " + expectedSeverity + ", deviceId: " + device.getId()); "severity: " + expectedSeverity.toString().toLowerCase() + ", deviceId: " + device.getId());
assertThat(updatedNotification.getText()).isEqualTo("Status: " + expectedStatus + ", severity: " + expectedSeverity); assertThat(updatedNotification.getText()).isEqualTo("Status: " + expectedStatus + ", severity: " + expectedSeverity.toString().toLowerCase());
wsClient.close(); wsClient.close();
}); });
@ -325,7 +322,7 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
alarmSubscriptionService.clearAlarm(tenantId, alarm.getId(), System.currentTimeMillis(), null); alarmSubscriptionService.clearAlarm(tenantId, alarm.getId(), System.currentTimeMillis(), null);
getWsClient().waitForUpdate(true); getWsClient().waitForUpdate(true);
notification = getWsClient().getLastDataUpdate().getUpdate(); notification = getWsClient().getLastDataUpdate().getUpdate();
assertThat(notification.getSubject()).isEqualTo("CRITICAL alarm '" + alarmType + "' is CLEARED_UNACK"); assertThat(notification.getSubject()).isEqualTo("critical alarm '" + alarmType + "' is CLEARED_UNACK");
assertThat(findNotificationRequests(EntityType.ALARM).getData()).filteredOn(NotificationRequest::isScheduled).isEmpty(); assertThat(findNotificationRequests(EntityType.ALARM).getData()).filteredOn(NotificationRequest::isScheduled).isEmpty();
} }

Loading…
Cancel
Save