refactoring: alarm - test start
This commit is contained in:
parent
5fef80a990
commit
0cd24bb16e
@ -147,7 +147,7 @@ public class AlarmController extends BaseController {
|
||||
try {
|
||||
AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
|
||||
Alarm alarm = checkAlarmId(alarmId, Operation.WRITE);
|
||||
return tbAlarmService.delete(alarm, getCurrentUser());
|
||||
return tbAlarmService.delete(alarm, getCurrentUser().getCustomerId(), getCurrentUser());
|
||||
} catch (Exception e) {
|
||||
throw handleException(e);
|
||||
}
|
||||
|
||||
@ -52,6 +52,7 @@ import org.thingsboard.server.service.gateway_device.GatewayNotificationsService
|
||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@ -335,28 +336,7 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
|
||||
return null;
|
||||
}
|
||||
|
||||
private EdgeEventActionType edgeTypeByActionType(ActionType actionType) {
|
||||
switch (actionType) {
|
||||
case ADDED:
|
||||
return EdgeEventActionType.ADDED;
|
||||
case UPDATED:
|
||||
return EdgeEventActionType.UPDATED;
|
||||
case ALARM_ACK:
|
||||
return EdgeEventActionType.ALARM_ACK;
|
||||
case ALARM_CLEAR:
|
||||
return EdgeEventActionType.ALARM_CLEAR;
|
||||
case DELETED:
|
||||
return EdgeEventActionType.DELETED;
|
||||
case RELATION_ADD_OR_UPDATE:
|
||||
return EdgeEventActionType.RELATION_ADD_OR_UPDATE;
|
||||
case RELATION_DELETED:
|
||||
return EdgeEventActionType.RELATION_DELETED;
|
||||
case ASSIGNED_TO_EDGE:
|
||||
return EdgeEventActionType.ASSIGNED_TO_EDGE;
|
||||
case UNASSIGNED_FROM_EDGE:
|
||||
return EdgeEventActionType.UNASSIGNED_FROM_EDGE;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
public static EdgeEventActionType edgeTypeByActionType(ActionType actionType) {
|
||||
return EdgeEventActionType.valueOf(actionType.toString().toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ import org.thingsboard.server.common.data.alarm.Alarm;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmStatus;
|
||||
import org.thingsboard.server.common.data.audit.ActionType;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.EdgeId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||
@ -77,12 +78,13 @@ public class DefaultTbAlarmService extends AbstractTbEntityService implements Tb
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delete(Alarm alarm, SecurityUser user) throws ThingsboardException {
|
||||
public Boolean delete(Alarm alarm, CustomerId customerId, SecurityUser user) throws ThingsboardException {
|
||||
TenantId tenantId = alarm.getTenantId();
|
||||
try {
|
||||
List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(user.getTenantId(), alarm.getOriginator());
|
||||
notificationEntityService.notifyDeleteAlarm(user.getTenantId(), alarm, alarm.getOriginator(), user.getCustomerId(),
|
||||
List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(tenantId, alarm.getOriginator());
|
||||
notificationEntityService.notifyDeleteAlarm(tenantId, alarm, alarm.getOriginator(), customerId,
|
||||
relatedEdgeIds, user, JacksonUtil.OBJECT_MAPPER.writeValueAsString(alarm));
|
||||
return alarmService.deleteAlarm(user.getTenantId(), alarm.getId()).isSuccessful();
|
||||
return alarmService.deleteAlarm(tenantId, alarm.getId()).isSuccessful();
|
||||
} catch (Exception e) {
|
||||
throw handleException(e);
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ package org.thingsboard.server.service.entitiy.alarm;
|
||||
|
||||
import org.thingsboard.server.common.data.alarm.Alarm;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||
|
||||
public interface TbAlarmService {
|
||||
@ -27,5 +28,5 @@ public interface TbAlarmService {
|
||||
|
||||
void clear(Alarm alarm, SecurityUser user) throws ThingsboardException;
|
||||
|
||||
Boolean delete(Alarm alarm, SecurityUser user) throws ThingsboardException;
|
||||
Boolean delete(Alarm alarm, CustomerId customerId, SecurityUser user) throws ThingsboardException;
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnableWebSocket
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@Slf4j
|
||||
public abstract class AbstractControllerTest extends AbstractWebTest {
|
||||
public abstract class AbstractControllerTest extends AbstractNotifyEntityTest {
|
||||
|
||||
public static final String WS_URL = "ws://localhost:";
|
||||
|
||||
|
||||
@ -0,0 +1,132 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.controller;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.thingsboard.server.cluster.TbClusterService;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.HasName;
|
||||
import org.thingsboard.server.common.data.audit.ActionType;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.EntityIdFactory;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.id.UserId;
|
||||
import org.thingsboard.server.dao.audit.AuditLogService;
|
||||
import org.thingsboard.server.dao.model.ModelConstants;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.thingsboard.server.service.entitiy.DefaultTbNotificationEntityService.edgeTypeByActionType;
|
||||
|
||||
public abstract class AbstractNotifyEntityTest extends AbstractWebTest {
|
||||
|
||||
@SpyBean
|
||||
protected TbClusterService tbClusterService;
|
||||
|
||||
@SpyBean
|
||||
protected AuditLogService auditLogService;
|
||||
|
||||
protected void testNotifyEntityOk(HasName entity, EntityId entityId, EntityId originatorId,
|
||||
TenantId tenantId, CustomerId customerId, UserId userId, String userName,
|
||||
ActionType actionType) {
|
||||
testSendNotificationMsgToEdgeServiceOk(entityId, tenantId, actionType);
|
||||
testLogEntityActionOk(entity, originatorId, tenantId, customerId, userId, userName, actionType);
|
||||
testPushMsgToRuleEngineOk(entity, originatorId, tenantId, customerId, userId, userName, actionType);
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
}
|
||||
|
||||
protected void testNotifyEntityDeleteOk(HasName entity, EntityId entityId, EntityId originatorId,
|
||||
TenantId tenantId, CustomerId customerId, UserId userId, String userName,
|
||||
ActionType actionType) {
|
||||
Mockito.verify(tbClusterService, never()).sendNotificationMsgToEdgeService(Mockito.any(),
|
||||
Mockito.any(), Mockito.any(entityId.getClass()), Mockito.any(), Mockito.any(), Mockito.any());
|
||||
testLogEntityActionOk(entity, originatorId, tenantId, customerId, userId, userName, actionType);
|
||||
testPushMsgToRuleEngineOk(entity, originatorId, tenantId, customerId, userId, userName, actionType);
|
||||
}
|
||||
|
||||
private void testNotifyEntityError(EntityId entityId, HasName entity, TenantId tenantId,
|
||||
UserId userId, String userName, ActionType actionType, Exception exp,
|
||||
Object... additionalInfo) {
|
||||
CustomerId customer_NULL_UUID = (CustomerId) EntityIdFactory.getByTypeAndUuid(EntityType.CUSTOMER, ModelConstants.NULL_UUID);
|
||||
EntityId entity_NULL_UUID = EntityIdFactory.getByTypeAndUuid(EntityType.valueOf(entity.getClass().toString().substring(entity.getClass().toString().lastIndexOf(".") + 1).toUpperCase(Locale.ENGLISH)),
|
||||
ModelConstants.NULL_UUID);
|
||||
testNotificationMsgToEdgeServiceNever(entityId);
|
||||
if (additionalInfo.length > 0) {
|
||||
Mockito.verify(auditLogService, times(1)).logEntityAction(Mockito.eq(tenantId),
|
||||
Mockito.eq(customer_NULL_UUID), Mockito.eq(userId), Mockito.eq(userName),
|
||||
Mockito.eq(entity_NULL_UUID), Mockito.any(entity.getClass()), Mockito.eq(actionType),
|
||||
Mockito.any(exp.getClass()), Mockito.eq(additionalInfo));
|
||||
} else {
|
||||
Mockito.verify(auditLogService, times(1)).logEntityAction(Mockito.eq(tenantId),
|
||||
Mockito.eq(customer_NULL_UUID), Mockito.eq(userId), Mockito.eq(userName),
|
||||
Mockito.eq(entity_NULL_UUID), Mockito.any(entity.getClass()), Mockito.eq(actionType),
|
||||
Mockito.any(exp.getClass()), Mockito.isNull());
|
||||
}
|
||||
Mockito.verify(tbClusterService, never()).pushMsgToRuleEngine(Mockito.any(), Mockito.any(entityId.getClass()),
|
||||
Mockito.any(), Mockito.any());
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
}
|
||||
|
||||
protected void testNotifyEntityNever(EntityId entityId, HasName entity) {
|
||||
testNotificationMsgToEdgeServiceNever(entityId);
|
||||
testLogEntityActionNever(entityId, entity);
|
||||
testPushMsgToRuleEngineNever(entityId);
|
||||
}
|
||||
|
||||
protected void testNotificationMsgToEdgeServiceNever(EntityId entityId) {
|
||||
Mockito.verify(tbClusterService, never()).sendNotificationMsgToEdgeService(Mockito.any(),
|
||||
Mockito.any(), Mockito.any(entityId.getClass()), Mockito.any(), Mockito.any(), Mockito.any());
|
||||
}
|
||||
|
||||
protected void testLogEntityActionNever(EntityId entityId, HasName entity) {
|
||||
Mockito.verify(auditLogService, never()).logEntityAction(Mockito.any(), Mockito.any(),
|
||||
Mockito.any(), Mockito.any(), Mockito.any(entityId.getClass()), Mockito.any(entity.getClass()),
|
||||
Mockito.any(), Mockito.any());
|
||||
}
|
||||
|
||||
protected void testPushMsgToRuleEngineNever(EntityId entityId) {
|
||||
Mockito.verify(tbClusterService, never()).pushMsgToRuleEngine(Mockito.any(),
|
||||
Mockito.any(entityId.getClass()), Mockito.any(), Mockito.any());
|
||||
}
|
||||
|
||||
private void testLogEntityActionOk(HasName entity, EntityId originatorId,
|
||||
TenantId tenantId, CustomerId customerId, UserId userId, String userName,
|
||||
ActionType actionType) {
|
||||
Mockito.verify(auditLogService, times(1)).logEntityAction(Mockito.eq(tenantId), Mockito.eq(customerId),
|
||||
Mockito.eq(userId), Mockito.eq(userName), Mockito.eq(originatorId),
|
||||
Mockito.eq(entity), Mockito.eq(actionType), Mockito.isNull());
|
||||
}
|
||||
|
||||
private void testPushMsgToRuleEngineOk(HasName entity, EntityId originatorId,
|
||||
TenantId tenantId, CustomerId customerId, UserId userId, String userName,
|
||||
ActionType actionType) {
|
||||
|
||||
Mockito.verify(auditLogService, times(1)).logEntityAction(Mockito.eq(tenantId), Mockito.eq(customerId),
|
||||
Mockito.eq(userId), Mockito.eq(userName), Mockito.eq(originatorId),
|
||||
Mockito.eq(entity), Mockito.eq(actionType), Mockito.isNull());
|
||||
}
|
||||
|
||||
private void testSendNotificationMsgToEdgeServiceOk(EntityId entityId, TenantId tenantId, ActionType actionType) {
|
||||
Mockito.verify(tbClusterService, times(1)).sendNotificationMsgToEdgeService(Mockito.eq(tenantId),
|
||||
Mockito.isNull(), Mockito.eq(entityId), Mockito.isNull(), Mockito.isNull(),
|
||||
Mockito.eq(edgeTypeByActionType(actionType)));
|
||||
}
|
||||
|
||||
}
|
||||
@ -75,11 +75,6 @@ import org.thingsboard.server.common.data.id.UserId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.common.data.page.TimePageLink;
|
||||
import org.thingsboard.server.common.data.queue.ProcessingStrategy;
|
||||
import org.thingsboard.server.common.data.queue.ProcessingStrategyType;
|
||||
import org.thingsboard.server.common.data.queue.Queue;
|
||||
import org.thingsboard.server.common.data.queue.SubmitStrategy;
|
||||
import org.thingsboard.server.common.data.queue.SubmitStrategyType;
|
||||
import org.thingsboard.server.common.data.security.Authority;
|
||||
import org.thingsboard.server.config.ThingsboardSecurityConfiguration;
|
||||
import org.thingsboard.server.dao.tenant.TenantProfileService;
|
||||
@ -137,7 +132,9 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest {
|
||||
|
||||
protected TenantId tenantId;
|
||||
protected UserId tenantAdminUserId;
|
||||
protected CustomerId tenantAdminCustomerId;
|
||||
protected CustomerId customerId;
|
||||
protected UserId customerUserId;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private HttpMessageConverter mappingJackson2HttpMessageConverter;
|
||||
@ -202,6 +199,7 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest {
|
||||
|
||||
tenantAdmin = createUserAndLogin(tenantAdmin, TENANT_ADMIN_PASSWORD);
|
||||
tenantAdminUserId = tenantAdmin.getId();
|
||||
tenantAdminCustomerId = tenantAdmin.getCustomerId();
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.setTitle("Customer");
|
||||
@ -215,7 +213,8 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest {
|
||||
customerUser.setCustomerId(savedCustomer.getId());
|
||||
customerUser.setEmail(CUSTOMER_USER_EMAIL);
|
||||
|
||||
createUserAndLogin(customerUser, CUSTOMER_USER_PASSWORD);
|
||||
customerUser = createUserAndLogin(customerUser, CUSTOMER_USER_PASSWORD);
|
||||
customerUserId = customerUser.getId();
|
||||
|
||||
logout();
|
||||
|
||||
|
||||
@ -15,17 +15,21 @@
|
||||
*/
|
||||
package org.thingsboard.server.controller;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.alarm.Alarm;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmSeverity;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmStatus;
|
||||
import org.thingsboard.server.common.data.audit.ActionType;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@Slf4j
|
||||
public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
|
||||
public static final String TEST_ALARM_TYPE = "Test";
|
||||
@ -56,36 +60,68 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
@Test
|
||||
public void testCreateAlarmViaCustomer() throws Exception {
|
||||
loginCustomerUser();
|
||||
createAlarm(TEST_ALARM_TYPE);
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
|
||||
testNotifyEntityOk(alarm, alarm.getId(), alarm.getOriginator(),
|
||||
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ADDED);
|
||||
logout();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAlarmViaTenant() throws Exception {
|
||||
loginTenantAdmin();
|
||||
createAlarm(TEST_ALARM_TYPE);
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
|
||||
testNotifyEntityOk(alarm, alarm.getId(), alarm.getOriginator(),
|
||||
tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.ADDED);
|
||||
logout();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAlarmViaCustomer() throws Exception {
|
||||
loginCustomerUser();
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
|
||||
testNotifyEntityOk(alarm, alarm.getId(), alarm.getOriginator(),
|
||||
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ADDED);
|
||||
|
||||
alarm.setSeverity(AlarmSeverity.MAJOR);
|
||||
Alarm updatedAlarm = doPost("/api/alarm", alarm, Alarm.class);
|
||||
Assert.assertNotNull(updatedAlarm);
|
||||
Assert.assertEquals(AlarmSeverity.MAJOR, updatedAlarm.getSeverity());
|
||||
|
||||
testNotifyEntityOk(alarm, alarm.getId(), alarm.getOriginator(),
|
||||
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.UPDATED);
|
||||
logout();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAlarmViaTenant() throws Exception {
|
||||
loginTenantAdmin();
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
|
||||
testNotifyEntityOk(alarm, alarm.getId(), alarm.getOriginator(),
|
||||
tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.ADDED);
|
||||
|
||||
alarm.setSeverity(AlarmSeverity.MAJOR);
|
||||
Alarm updatedAlarm = doPost("/api/alarm", alarm, Alarm.class);
|
||||
Assert.assertNotNull(updatedAlarm);
|
||||
Assert.assertEquals(AlarmSeverity.MAJOR, updatedAlarm.getSeverity());
|
||||
|
||||
testNotifyEntityOk(updatedAlarm, updatedAlarm.getId(), updatedAlarm.getOriginator(),
|
||||
tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.UPDATED);
|
||||
logout();
|
||||
}
|
||||
|
||||
@ -93,9 +129,15 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
public void testUpdateAlarmViaDifferentTenant() throws Exception {
|
||||
loginTenantAdmin();
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
|
||||
alarm.setSeverity(AlarmSeverity.MAJOR);
|
||||
loginDifferentTenant();
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
doPost("/api/alarm", alarm).andExpect(status().isForbidden());
|
||||
|
||||
testNotifyEntityNever(alarm.getId(), alarm);
|
||||
logout();
|
||||
}
|
||||
|
||||
@ -103,9 +145,15 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
public void testUpdateAlarmViaDifferentCustomer() throws Exception {
|
||||
loginCustomerUser();
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
|
||||
loginDifferentCustomer();
|
||||
alarm.setSeverity(AlarmSeverity.MAJOR);
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
doPost("/api/alarm", alarm).andExpect(status().isForbidden());
|
||||
|
||||
testNotifyEntityNever(alarm.getId(), alarm);
|
||||
logout();
|
||||
}
|
||||
|
||||
@ -113,7 +161,13 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
public void testDeleteAlarmViaCustomer() throws Exception {
|
||||
loginCustomerUser();
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isOk());
|
||||
|
||||
testNotifyEntityDeleteOk(alarm, alarm.getId(), alarm.getOriginator(),
|
||||
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.DELETED);
|
||||
logout();
|
||||
}
|
||||
|
||||
@ -121,7 +175,13 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
public void testDeleteAlarmViaTenant() throws Exception {
|
||||
loginTenantAdmin();
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isOk());
|
||||
|
||||
testNotifyEntityDeleteOk(alarm, alarm.getId(), alarm.getOriginator(),
|
||||
tenantId, tenantAdminCustomerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.DELETED);
|
||||
logout();
|
||||
}
|
||||
|
||||
@ -129,8 +189,15 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
public void testDeleteAlarmViaDifferentTenant() throws Exception {
|
||||
loginTenantAdmin();
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
|
||||
loginDifferentTenant();
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isForbidden());
|
||||
|
||||
testNotifyEntityNever(alarm.getId(), alarm);
|
||||
|
||||
logout();
|
||||
}
|
||||
|
||||
@ -139,7 +206,13 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
loginCustomerUser();
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
loginDifferentCustomer();
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isForbidden());
|
||||
|
||||
testNotifyEntityNever(alarm.getId(), alarm);
|
||||
|
||||
logout();
|
||||
}
|
||||
|
||||
@ -147,10 +220,17 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
public void testClearAlarmViaCustomer() throws Exception {
|
||||
loginCustomerUser();
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
doPost("/api/alarm/" + alarm.getId() + "/clear").andExpect(status().isOk());
|
||||
|
||||
Alarm foundAlarm = doGet("/api/alarm/" + alarm.getId(), Alarm.class);
|
||||
Assert.assertNotNull(foundAlarm);
|
||||
Assert.assertEquals(AlarmStatus.CLEARED_UNACK, foundAlarm.getStatus());
|
||||
|
||||
testNotifyEntityOk(foundAlarm, foundAlarm.getId(), foundAlarm.getOriginator(),
|
||||
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ALARM_CLEAR);
|
||||
logout();
|
||||
}
|
||||
|
||||
@ -158,10 +238,16 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
public void testClearAlarmViaTenant() throws Exception {
|
||||
loginTenantAdmin();
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
doPost("/api/alarm/" + alarm.getId() + "/clear").andExpect(status().isOk());
|
||||
Alarm foundAlarm = doGet("/api/alarm/" + alarm.getId(), Alarm.class);
|
||||
Assert.assertNotNull(foundAlarm);
|
||||
Assert.assertEquals(AlarmStatus.CLEARED_UNACK, foundAlarm.getStatus());
|
||||
|
||||
testNotifyEntityOk(foundAlarm, foundAlarm.getId(), foundAlarm.getOriginator(),
|
||||
tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.ALARM_CLEAR);
|
||||
logout();
|
||||
}
|
||||
|
||||
@ -169,10 +255,17 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
public void testAcknowledgeAlarmViaCustomer() throws Exception {
|
||||
loginCustomerUser();
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
doPost("/api/alarm/" + alarm.getId() + "/ack").andExpect(status().isOk());
|
||||
|
||||
Alarm foundAlarm = doGet("/api/alarm/" + alarm.getId(), Alarm.class);
|
||||
Assert.assertNotNull(foundAlarm);
|
||||
Assert.assertEquals(AlarmStatus.ACTIVE_ACK, foundAlarm.getStatus());
|
||||
|
||||
testNotifyEntityOk(foundAlarm, foundAlarm.getId(), foundAlarm.getOriginator(),
|
||||
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ALARM_ACK);
|
||||
logout();
|
||||
}
|
||||
|
||||
@ -181,7 +274,12 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
loginCustomerUser();
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
loginDifferentCustomer();
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
doPost("/api/alarm/" + alarm.getId() + "/clear").andExpect(status().isForbidden());
|
||||
|
||||
testNotifyEntityNever(alarm.getId(), alarm);
|
||||
logout();
|
||||
}
|
||||
|
||||
@ -190,7 +288,12 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
loginTenantAdmin();
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
loginDifferentTenant();
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
doPost("/api/alarm/" + alarm.getId() + "/clear").andExpect(status().isForbidden());
|
||||
|
||||
testNotifyEntityNever(alarm.getId(), alarm);
|
||||
logout();
|
||||
}
|
||||
|
||||
@ -199,7 +302,12 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
loginCustomerUser();
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
loginDifferentCustomer();
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
doPost("/api/alarm/" + alarm.getId() + "/ack").andExpect(status().isForbidden());
|
||||
|
||||
testNotifyEntityNever(alarm.getId(), alarm);
|
||||
logout();
|
||||
}
|
||||
|
||||
@ -208,7 +316,12 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
loginTenantAdmin();
|
||||
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
|
||||
loginDifferentTenant();
|
||||
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
doPost("/api/alarm/" + alarm.getId() + "/ack").andExpect(status().isForbidden());
|
||||
|
||||
testNotifyEntityNever(alarm.getId(), alarm);
|
||||
logout();
|
||||
}
|
||||
|
||||
@ -221,10 +334,8 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
.severity(AlarmSeverity.CRITICAL)
|
||||
.type(type)
|
||||
.build();
|
||||
|
||||
alarm = doPost("/api/alarm", alarm, Alarm.class);
|
||||
Assert.assertNotNull(alarm);
|
||||
|
||||
return alarm;
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,12 +40,12 @@ import org.thingsboard.server.common.data.device.profile.AlarmConditionFilter;
|
||||
import org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey;
|
||||
import org.thingsboard.server.common.data.device.profile.AlarmConditionKeyType;
|
||||
import org.thingsboard.server.common.data.device.profile.AlarmRule;
|
||||
import org.thingsboard.server.common.data.device.profile.CustomTimeSchedule;
|
||||
import org.thingsboard.server.common.data.device.profile.CustomTimeScheduleItem;
|
||||
import org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm;
|
||||
import org.thingsboard.server.common.data.device.profile.DeviceProfileData;
|
||||
import org.thingsboard.server.common.data.device.profile.DurationAlarmConditionSpec;
|
||||
import org.thingsboard.server.common.data.device.profile.RepeatingAlarmConditionSpec;
|
||||
import org.thingsboard.server.common.data.device.profile.CustomTimeSchedule;
|
||||
import org.thingsboard.server.common.data.device.profile.CustomTimeScheduleItem;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||
@ -70,10 +70,10 @@ import org.thingsboard.server.dao.timeseries.TimeseriesService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
import java.util.TreeMap;
|
||||
import java.util.UUID;
|
||||
@ -1157,7 +1157,7 @@ public class TbDeviceProfileNodeTest {
|
||||
.thenReturn(listListenableFutureActiveSchedule);
|
||||
|
||||
TbMsg theMsg = TbMsg.newMsg("ALARM", deviceId, new TbMsgMetaData(), "");
|
||||
Mockito.when(ctx.newMsg(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyString()))
|
||||
Mockito.when(ctx.newMsg(Mockito.any(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyString()))
|
||||
.thenReturn(theMsg);
|
||||
|
||||
ObjectNode data = mapper.createObjectNode();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user