Fix notification requests deletion test; drop all notifications after test
This commit is contained in:
parent
31f3c2a824
commit
9788a87ca3
@ -61,6 +61,7 @@ import org.thingsboard.server.dao.notification.NotificationRequestService;
|
|||||||
import org.thingsboard.server.dao.notification.NotificationRuleService;
|
import org.thingsboard.server.dao.notification.NotificationRuleService;
|
||||||
import org.thingsboard.server.dao.notification.NotificationTargetService;
|
import org.thingsboard.server.dao.notification.NotificationTargetService;
|
||||||
import org.thingsboard.server.dao.notification.NotificationTemplateService;
|
import org.thingsboard.server.dao.notification.NotificationTemplateService;
|
||||||
|
import org.thingsboard.server.dao.sqlts.insert.sql.SqlPartitioningRepository;
|
||||||
|
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -90,6 +91,8 @@ public abstract class AbstractNotificationApiTest extends AbstractControllerTest
|
|||||||
protected NotificationTargetService notificationTargetService;
|
protected NotificationTargetService notificationTargetService;
|
||||||
@Autowired
|
@Autowired
|
||||||
protected NotificationRequestService notificationRequestService;
|
protected NotificationRequestService notificationRequestService;
|
||||||
|
@Autowired
|
||||||
|
protected SqlPartitioningRepository partitioningRepository;
|
||||||
|
|
||||||
public static final String DEFAULT_NOTIFICATION_SUBJECT = "Just a test";
|
public static final String DEFAULT_NOTIFICATION_SUBJECT = "Just a test";
|
||||||
public static final NotificationType DEFAULT_NOTIFICATION_TYPE = NotificationType.GENERAL;
|
public static final NotificationType DEFAULT_NOTIFICATION_TYPE = NotificationType.GENERAL;
|
||||||
@ -100,6 +103,7 @@ public abstract class AbstractNotificationApiTest extends AbstractControllerTest
|
|||||||
notificationRuleService.deleteNotificationRulesByTenantId(TenantId.SYS_TENANT_ID);
|
notificationRuleService.deleteNotificationRulesByTenantId(TenantId.SYS_TENANT_ID);
|
||||||
notificationTemplateService.deleteNotificationTemplatesByTenantId(TenantId.SYS_TENANT_ID);
|
notificationTemplateService.deleteNotificationTemplatesByTenantId(TenantId.SYS_TENANT_ID);
|
||||||
notificationTargetService.deleteNotificationTargetsByTenantId(TenantId.SYS_TENANT_ID);
|
notificationTargetService.deleteNotificationTargetsByTenantId(TenantId.SYS_TENANT_ID);
|
||||||
|
partitioningRepository.dropPartitionsBefore("notification", Long.MAX_VALUE, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NotificationTarget createNotificationTarget(UserId... usersIds) {
|
protected NotificationTarget createNotificationTarget(UserId... usersIds) {
|
||||||
|
|||||||
@ -286,18 +286,19 @@ public class NotificationApiTest extends AbstractNotificationApiTest {
|
|||||||
@Test
|
@Test
|
||||||
public void whenTenantIsDeleted_thenDeleteNotificationRequests() throws Exception {
|
public void whenTenantIsDeleted_thenDeleteNotificationRequests() throws Exception {
|
||||||
createDifferentTenant();
|
createDifferentTenant();
|
||||||
|
TenantId tenantId = differentTenantId;
|
||||||
NotificationTarget target = createNotificationTarget(savedDifferentTenantUser.getId());
|
NotificationTarget target = createNotificationTarget(savedDifferentTenantUser.getId());
|
||||||
int notificationsCount = 20;
|
int notificationsCount = 20;
|
||||||
for (int i = 0; i < notificationsCount; i++) {
|
for (int i = 0; i < notificationsCount; i++) {
|
||||||
NotificationRequest request = submitNotificationRequest(target.getId(), "Test " + i, NotificationDeliveryMethod.WEB);
|
NotificationRequest request = submitNotificationRequest(target.getId(), "Test " + i, NotificationDeliveryMethod.WEB);
|
||||||
awaitNotificationRequest(request.getId());
|
awaitNotificationRequest(request.getId());
|
||||||
}
|
}
|
||||||
List<NotificationRequest> requests = notificationRequestService.findNotificationRequestsByTenantIdAndOriginatorType(differentTenantId, EntityType.USER, new PageLink(100)).getData();
|
List<NotificationRequest> requests = notificationRequestService.findNotificationRequestsByTenantIdAndOriginatorType(tenantId, EntityType.USER, new PageLink(100)).getData();
|
||||||
assertThat(requests).size().isEqualTo(notificationsCount);
|
assertThat(requests).size().isEqualTo(notificationsCount);
|
||||||
|
|
||||||
deleteDifferentTenant();
|
deleteDifferentTenant();
|
||||||
|
|
||||||
assertThat(notificationRequestService.findNotificationRequestsByTenantIdAndOriginatorType(differentTenantId, EntityType.USER, new PageLink(1)).getTotalElements())
|
assertThat(notificationRequestService.findNotificationRequestsByTenantIdAndOriginatorType(tenantId, EntityType.USER, new PageLink(1)).getTotalElements())
|
||||||
.isZero();
|
.isZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -456,9 +456,7 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
|
|||||||
|
|
||||||
loginSysAdmin();
|
loginSysAdmin();
|
||||||
notifications = await().atMost(30, TimeUnit.SECONDS)
|
notifications = await().atMost(30, TimeUnit.SECONDS)
|
||||||
.until(() -> getMyNotifications(true, 10).stream()
|
.until(() -> getMyNotifications(true, 10), list -> list.size() == 1);
|
||||||
.filter(notification -> notification.getType() == NotificationType.RATE_LIMITS)
|
|
||||||
.collect(Collectors.toList()), list -> list.size() == 1);
|
|
||||||
assertThat(notifications).allSatisfy(notification -> {
|
assertThat(notifications).allSatisfy(notification -> {
|
||||||
assertThat(notification.getSubject()).isEqualTo("Rate limits exceeded for tenant " + TEST_TENANT_NAME);
|
assertThat(notification.getSubject()).isEqualTo("Rate limits exceeded for tenant " + TEST_TENANT_NAME);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user