@ -22,9 +22,9 @@ import org.junit.Before;
import org.junit.Test ;
import org.junit.function.ThrowingRunnable ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.boot.test.mock.mockito.SpyBean ;
import org.springframework.data.util.Pair ;
import org.springframework.test.context.TestPropertySource ;
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean ;
import org.thingsboard.common.util.JacksonUtil ;
import org.thingsboard.server.cache.limits.RateLimitService ;
import org.thingsboard.server.common.data.DataConstants ;
@ -137,7 +137,7 @@ import static org.thingsboard.server.common.data.notification.rule.trigger.confi
} )
public class NotificationRuleApiTest extends AbstractNotificationApiTest {
@SpyBean
@Mockito SpyBean
private AlarmSubscriptionService alarmSubscriptionService ;
@Autowired
private DefaultSystemInfoService systemInfoService ;
@ -193,7 +193,7 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
@Test
public void testNotificationRuleProcessing_alarmTrigger ( ) throws Exception {
String notificationSubject = "Alarm type: ${alarmType}, status: ${alarmStatus}, " +
"severity: ${alarmSeverity}, deviceId: ${alarmOriginatorId}" ;
"severity: ${alarmSeverity}, deviceId: ${alarmOriginatorId}, details: ${data}. " ;
String notificationText = "Status: ${alarmStatus}, severity: ${alarmSeverity}" ;
NotificationTemplate notificationTemplate = createNotificationTemplate ( NotificationType . ALARM , notificationSubject , notificationText , NotificationDeliveryMethod . WEB ) ;
@ -221,12 +221,12 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
clients . put ( delay , userAndClient . getSecond ( ) ) ;
}
notificationRule . setRecipientsConfig ( recipientsConfig ) ;
notificationRule = saveNotificationRule ( notificationRule ) ;
saveNotificationRule ( notificationRule ) ;
String alarmType = "myBoolIsTrue" ;
DeviceProfile deviceProfile = createDeviceProfileWithAlarmRules ( alarmType ) ;
Device device = createDevice ( "Device 1" , deviceProfile . getName ( ) , "1234" ) ;
Device device = createDevice ( "Device 1" , deviceProfile . getName ( ) , "label" , " 1234" ) ;
clients . values ( ) . forEach ( wsClient - > {
wsClient . subscribeForUnreadNotifications ( 10 ) . waitForReply ( true ) ;
@ -250,7 +250,7 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
assertThat ( actualDelay ) . isCloseTo ( expectedDelay , offset ( 2 . 0 ) ) ;
assertThat ( notification . getSubject ( ) ) . isEqualTo ( "Alarm type: " + alarmType + ", status: " + AlarmStatus . ACTIVE_UNACK + ", " +
"severity: " + AlarmSeverity . CRITICAL . toString ( ) . toLowerCase ( ) + ", deviceId: " + device . getId ( ) ) ;
"severity: " + AlarmSeverity . CRITICAL . toString ( ) . toLowerCase ( ) + ", deviceId: " + device . getId ( ) + ", details: attribute is true." ) ;
assertThat ( notification . getText ( ) ) . isEqualTo ( "Status: " + AlarmStatus . ACTIVE_UNACK + ", severity: " + AlarmSeverity . CRITICAL . toString ( ) . toLowerCase ( ) ) ;
assertThat ( notification . getType ( ) ) . isEqualTo ( NotificationType . ALARM ) ;
@ -270,7 +270,7 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
wsClient . waitForUpdate ( true ) ;
Notification updatedNotification = wsClient . getLastDataUpdate ( ) . getUpdate ( ) ;
assertThat ( updatedNotification . getSubject ( ) ) . isEqualTo ( "Alarm type: " + alarmType + ", status: " + expectedStatus + ", " +
"severity: " + expectedSeverity . toString ( ) . toLowerCase ( ) + ", deviceId: " + device . getId ( ) ) ;
"severity: " + expectedSeverity . toString ( ) . toLowerCase ( ) + ", deviceId: " + device . getId ( ) + ", details: attribute is true." ) ;
assertThat ( updatedNotification . getText ( ) ) . isEqualTo ( "Status: " + expectedStatus + ", severity: " + expectedSeverity . toString ( ) . toLowerCase ( ) ) ;
wsClient . close ( ) ;
@ -516,10 +516,10 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
. notifyOn ( Set . of ( ASSIGNED , UNASSIGNED ) )
. build ( ) ;
NotificationTarget target = createNotificationTarget ( tenantAdminUserId ) ;
String template = "${userEmail} ${action} alarm on ${alarmOriginatorEntityType} '${alarmOriginatorName}'. Assignee: ${assigneeEmail}" ;
String template = "${userEmail} ${action} alarm on ${alarmOriginatorEntityType} '${alarmOriginatorName}' with label '${alarmOriginatorLabel}' . Assignee: ${assigneeEmail}" ;
createNotificationRule ( triggerConfig , "Test" , template , target . getId ( ) ) ;
Device device = createDevice ( "Device A" , "123" ) ;
Device device = createDevice ( "Device A" , "default" , "test" , " 123" ) ;
Alarm alarm = Alarm . builder ( )
. tenantId ( tenantId )
. originator ( device . getId ( ) )
@ -536,7 +536,7 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
doPost ( "/api/alarm/" + alarmId + "/assign/" + tenantAdminUserId ) . andExpect ( status ( ) . isOk ( ) ) ;
} , notification - > {
assertThat ( notification . getText ( ) ) . isEqualTo (
TENANT_ADMIN_EMAIL + " assigned alarm on Device 'Device A'. Assignee: " + TENANT_ADMIN_EMAIL
TENANT_ADMIN_EMAIL + " assigned alarm on Device 'Device A' with label 'test' . Assignee: " + TENANT_ADMIN_EMAIL
) ;
} ) ;
@ -544,7 +544,7 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
doDelete ( "/api/alarm/" + alarmId + "/assign" ) . andExpect ( status ( ) . isOk ( ) ) ;
} , notification - > {
assertThat ( notification . getText ( ) ) . isEqualTo (
TENANT_ADMIN_EMAIL + " unassigned alarm on Device 'Device A'. Assignee: "
TENANT_ADMIN_EMAIL + " unassigned alarm on Device 'Device A' with label 'test' . Assignee: "
) ;
} ) ;
}
@ -950,7 +950,7 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
alarm . setAlarmType ( alarmType ) ;
alarm . setId ( alarmType ) ;
AlarmRule alarmRule = new AlarmRule ( ) ;
alarmRule . setAlarmDetails ( "Details " ) ;
alarmRule . setAlarmDetails ( "attribute is ${bool} " ) ;
AlarmCondition alarmCondition = new AlarmCondition ( ) ;
alarmCondition . setSpec ( new SimpleAlarmConditionSpec ( ) ) ;
List < AlarmConditionFilter > condition = new ArrayList < > ( ) ;