Merge pull request #6734 from thingsboard/refactoring_test_customer_05
[3.4] Refactoring test customer
This commit is contained in:
		
						commit
						774bb96853
					
				@ -350,6 +350,10 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
 | 
				
			|||||||
                return EdgeEventActionType.RELATION_ADD_OR_UPDATE;
 | 
					                return EdgeEventActionType.RELATION_ADD_OR_UPDATE;
 | 
				
			||||||
            case RELATION_DELETED:
 | 
					            case RELATION_DELETED:
 | 
				
			||||||
                return EdgeEventActionType.RELATION_DELETED;
 | 
					                return EdgeEventActionType.RELATION_DELETED;
 | 
				
			||||||
 | 
					            case ASSIGNED_TO_CUSTOMER:
 | 
				
			||||||
 | 
					                return EdgeEventActionType.ASSIGNED_TO_CUSTOMER;
 | 
				
			||||||
 | 
					            case UNASSIGNED_FROM_CUSTOMER:
 | 
				
			||||||
 | 
					                return EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER;
 | 
				
			||||||
            case ASSIGNED_TO_EDGE:
 | 
					            case ASSIGNED_TO_EDGE:
 | 
				
			||||||
                return EdgeEventActionType.ASSIGNED_TO_EDGE;
 | 
					                return EdgeEventActionType.ASSIGNED_TO_EDGE;
 | 
				
			||||||
            case UNASSIGNED_FROM_EDGE:
 | 
					            case UNASSIGNED_FROM_EDGE:
 | 
				
			||||||
 | 
				
			|||||||
@ -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.alarm.AlarmStatus;
 | 
				
			||||||
import org.thingsboard.server.common.data.audit.ActionType;
 | 
					import org.thingsboard.server.common.data.audit.ActionType;
 | 
				
			||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
 | 
					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.EdgeId;
 | 
				
			||||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
					import org.thingsboard.server.common.data.id.TenantId;
 | 
				
			||||||
import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
					import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
				
			||||||
@ -54,7 +55,7 @@ public class DefaultTbAlarmService extends AbstractTbEntityService implements Tb
 | 
				
			|||||||
    public void ack(Alarm alarm, SecurityUser user) throws ThingsboardException {
 | 
					    public void ack(Alarm alarm, SecurityUser user) throws ThingsboardException {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            long ackTs = System.currentTimeMillis();
 | 
					            long ackTs = System.currentTimeMillis();
 | 
				
			||||||
            alarmService.ackAlarm(user.getTenantId(), alarm.getId(), ackTs).get();
 | 
					            alarmService.ackAlarm(alarm.getTenantId(), alarm.getId(), ackTs).get();
 | 
				
			||||||
            alarm.setAckTs(ackTs);
 | 
					            alarm.setAckTs(ackTs);
 | 
				
			||||||
            alarm.setStatus(alarm.getStatus().isCleared() ? AlarmStatus.CLEARED_ACK : AlarmStatus.ACTIVE_ACK);
 | 
					            alarm.setStatus(alarm.getStatus().isCleared() ? AlarmStatus.CLEARED_ACK : AlarmStatus.ACTIVE_ACK);
 | 
				
			||||||
            notificationEntityService.notifyCreateOrUpdateAlarm(alarm, ActionType.ALARM_ACK, user);
 | 
					            notificationEntityService.notifyCreateOrUpdateAlarm(alarm, ActionType.ALARM_ACK, user);
 | 
				
			||||||
@ -67,7 +68,7 @@ public class DefaultTbAlarmService extends AbstractTbEntityService implements Tb
 | 
				
			|||||||
    public void clear(Alarm alarm, SecurityUser user) throws ThingsboardException {
 | 
					    public void clear(Alarm alarm, SecurityUser user) throws ThingsboardException {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            long clearTs = System.currentTimeMillis();
 | 
					            long clearTs = System.currentTimeMillis();
 | 
				
			||||||
            alarmService.clearAlarm(user.getTenantId(), alarm.getId(), null, clearTs).get();
 | 
					            alarmService.clearAlarm(alarm.getTenantId(), alarm.getId(), null, clearTs).get();
 | 
				
			||||||
            alarm.setClearTs(clearTs);
 | 
					            alarm.setClearTs(clearTs);
 | 
				
			||||||
            alarm.setStatus(alarm.getStatus().isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK);
 | 
					            alarm.setStatus(alarm.getStatus().isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK);
 | 
				
			||||||
            notificationEntityService.notifyCreateOrUpdateAlarm(alarm, ActionType.ALARM_CLEAR, user);
 | 
					            notificationEntityService.notifyCreateOrUpdateAlarm(alarm, ActionType.ALARM_CLEAR, user);
 | 
				
			||||||
@ -78,11 +79,20 @@ public class DefaultTbAlarmService extends AbstractTbEntityService implements Tb
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public Boolean delete(Alarm alarm, SecurityUser user) throws ThingsboardException {
 | 
					    public Boolean delete(Alarm alarm, SecurityUser user) throws ThingsboardException {
 | 
				
			||||||
 | 
					        return delete(alarm, user.getCustomerId(), user);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public Boolean delete(Alarm alarm, CustomerId customerId) throws ThingsboardException {
 | 
				
			||||||
 | 
					        return delete(alarm, customerId, null);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Boolean delete(Alarm alarm, CustomerId customerId, SecurityUser user) throws ThingsboardException {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(user.getTenantId(), alarm.getOriginator());
 | 
					            List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(alarm.getTenantId(), alarm.getOriginator());
 | 
				
			||||||
            notificationEntityService.notifyDeleteAlarm(user.getTenantId(), alarm, alarm.getOriginator(), user.getCustomerId(),
 | 
					            notificationEntityService.notifyDeleteAlarm(alarm.getTenantId(), alarm, alarm.getOriginator(), customerId,
 | 
				
			||||||
                    relatedEdgeIds, user, JacksonUtil.OBJECT_MAPPER.writeValueAsString(alarm));
 | 
					                    relatedEdgeIds, user, JacksonUtil.OBJECT_MAPPER.writeValueAsString(alarm));
 | 
				
			||||||
            return alarmService.deleteAlarm(user.getTenantId(), alarm.getId()).isSuccessful();
 | 
					            return alarmService.deleteAlarm(alarm.getTenantId(), alarm.getId()).isSuccessful();
 | 
				
			||||||
        } catch (Exception e) {
 | 
					        } catch (Exception e) {
 | 
				
			||||||
            throw handleException(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.alarm.Alarm;
 | 
				
			||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
 | 
					import org.thingsboard.server.common.data.exception.ThingsboardException;
 | 
				
			||||||
 | 
					import org.thingsboard.server.common.data.id.CustomerId;
 | 
				
			||||||
import org.thingsboard.server.service.security.model.SecurityUser;
 | 
					import org.thingsboard.server.service.security.model.SecurityUser;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public interface TbAlarmService {
 | 
					public interface TbAlarmService {
 | 
				
			||||||
@ -28,4 +29,6 @@ public interface TbAlarmService {
 | 
				
			|||||||
    void clear(Alarm alarm, SecurityUser user) throws ThingsboardException;
 | 
					    void clear(Alarm alarm, SecurityUser user) throws ThingsboardException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Boolean delete(Alarm alarm, SecurityUser user) throws ThingsboardException;
 | 
					    Boolean delete(Alarm alarm, SecurityUser user) throws ThingsboardException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Boolean delete(Alarm alarm, CustomerId customerId) throws ThingsboardException;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -23,7 +23,6 @@ import org.thingsboard.server.common.data.EntityType;
 | 
				
			|||||||
import org.thingsboard.server.common.data.asset.Asset;
 | 
					import org.thingsboard.server.common.data.asset.Asset;
 | 
				
			||||||
import org.thingsboard.server.common.data.audit.ActionType;
 | 
					import org.thingsboard.server.common.data.audit.ActionType;
 | 
				
			||||||
import org.thingsboard.server.common.data.edge.Edge;
 | 
					import org.thingsboard.server.common.data.edge.Edge;
 | 
				
			||||||
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
 | 
					 | 
				
			||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
 | 
					import org.thingsboard.server.common.data.exception.ThingsboardException;
 | 
				
			||||||
import org.thingsboard.server.common.data.id.AssetId;
 | 
					import org.thingsboard.server.common.data.id.AssetId;
 | 
				
			||||||
import org.thingsboard.server.common.data.id.CustomerId;
 | 
					import org.thingsboard.server.common.data.id.CustomerId;
 | 
				
			||||||
@ -35,6 +34,8 @@ import org.thingsboard.server.service.security.model.SecurityUser;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import static org.thingsboard.server.service.entitiy.DefaultTbNotificationEntityService.edgeTypeByActionType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Service
 | 
					@Service
 | 
				
			||||||
@TbCoreComponent
 | 
					@TbCoreComponent
 | 
				
			||||||
@AllArgsConstructor
 | 
					@AllArgsConstructor
 | 
				
			||||||
@ -47,7 +48,7 @@ public class DefaultTbAssetService extends AbstractTbEntityService implements Tb
 | 
				
			|||||||
        try {
 | 
					        try {
 | 
				
			||||||
            Asset savedAsset = checkNotNull(assetService.saveAsset(asset));
 | 
					            Asset savedAsset = checkNotNull(assetService.saveAsset(asset));
 | 
				
			||||||
            vcService.autoCommit(user, savedAsset.getId());
 | 
					            vcService.autoCommit(user, savedAsset.getId());
 | 
				
			||||||
            notificationEntityService.notifyCreateOrUpdateEntity(tenantId, savedAsset.getId(), asset, savedAsset.getCustomerId(), actionType, user);
 | 
					            notificationEntityService.notifyCreateOrUpdateEntity(tenantId, savedAsset.getId(), savedAsset, savedAsset.getCustomerId(), actionType, user);
 | 
				
			||||||
            return savedAsset;
 | 
					            return savedAsset;
 | 
				
			||||||
        } catch (Exception e) {
 | 
					        } catch (Exception e) {
 | 
				
			||||||
            notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.ASSET), asset, null, actionType, user, e);
 | 
					            notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.ASSET), asset, null, actionType, user, e);
 | 
				
			||||||
@ -80,7 +81,7 @@ public class DefaultTbAssetService extends AbstractTbEntityService implements Tb
 | 
				
			|||||||
        try {
 | 
					        try {
 | 
				
			||||||
            Asset savedAsset = checkNotNull(assetService.assignAssetToCustomer(tenantId, assetId, customerId));
 | 
					            Asset savedAsset = checkNotNull(assetService.assignAssetToCustomer(tenantId, assetId, customerId));
 | 
				
			||||||
            notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, assetId, customerId, savedAsset,
 | 
					            notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, assetId, customerId, savedAsset,
 | 
				
			||||||
                    actionType, EdgeEventActionType.ASSIGNED_TO_CUSTOMER, user, true, customerId.toString(), customer.getName());
 | 
					                    actionType, edgeTypeByActionType(actionType), user, true, customerId.toString(), customer.getName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return savedAsset;
 | 
					            return savedAsset;
 | 
				
			||||||
        } catch (Exception e) {
 | 
					        } catch (Exception e) {
 | 
				
			||||||
@ -99,7 +100,7 @@ public class DefaultTbAssetService extends AbstractTbEntityService implements Tb
 | 
				
			|||||||
            CustomerId customerId = customer.getId();
 | 
					            CustomerId customerId = customer.getId();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, assetId, customerId, savedAsset,
 | 
					            notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, assetId, customerId, savedAsset,
 | 
				
			||||||
                    actionType, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER, user,
 | 
					                    actionType, edgeTypeByActionType(actionType), user,
 | 
				
			||||||
                    true, customerId.toString(), customer.getName());
 | 
					                    true, customerId.toString(), customer.getName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return savedAsset;
 | 
					            return savedAsset;
 | 
				
			||||||
 | 
				
			|||||||
@ -16,6 +16,7 @@
 | 
				
			|||||||
package org.thingsboard.server.controller;
 | 
					package org.thingsboard.server.controller;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import lombok.extern.slf4j.Slf4j;
 | 
					import lombok.extern.slf4j.Slf4j;
 | 
				
			||||||
 | 
					import org.mockito.ArgumentMatcher;
 | 
				
			||||||
import org.mockito.Mockito;
 | 
					import org.mockito.Mockito;
 | 
				
			||||||
import org.springframework.boot.test.mock.mockito.SpyBean;
 | 
					import org.springframework.boot.test.mock.mockito.SpyBean;
 | 
				
			||||||
import org.thingsboard.server.cluster.TbClusterService;
 | 
					import org.thingsboard.server.cluster.TbClusterService;
 | 
				
			||||||
@ -33,6 +34,7 @@ import org.thingsboard.server.dao.audit.AuditLogService;
 | 
				
			|||||||
import org.thingsboard.server.dao.model.ModelConstants;
 | 
					import org.thingsboard.server.dao.model.ModelConstants;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.Locale;
 | 
					import java.util.Locale;
 | 
				
			||||||
 | 
					import java.util.Objects;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import static org.mockito.Mockito.never;
 | 
					import static org.mockito.Mockito.never;
 | 
				
			||||||
import static org.mockito.Mockito.times;
 | 
					import static org.mockito.Mockito.times;
 | 
				
			||||||
@ -50,73 +52,86 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest {
 | 
				
			|||||||
    protected void testNotifyEntityAllOneTime(HasName entity, EntityId entityId, EntityId originatorId,
 | 
					    protected void testNotifyEntityAllOneTime(HasName entity, EntityId entityId, EntityId originatorId,
 | 
				
			||||||
                                              TenantId tenantId, CustomerId customerId, UserId userId, String userName,
 | 
					                                              TenantId tenantId, CustomerId customerId, UserId userId, String userName,
 | 
				
			||||||
                                              ActionType actionType, Object... additionalInfo) {
 | 
					                                              ActionType actionType, Object... additionalInfo) {
 | 
				
			||||||
        testSendNotificationMsgToEdgeServiceOneTime(entityId, tenantId, actionType);
 | 
					        int cntTime = 1;
 | 
				
			||||||
        testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo);
 | 
					        testSendNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, cntTime);
 | 
				
			||||||
        testPushMsgToRuleEngineOneTime(originatorId, tenantId);
 | 
					        testLogEntityAction(entity, originatorId, tenantId, customerId, userId, userName, actionType, cntTime, additionalInfo);
 | 
				
			||||||
 | 
					        testPushMsgToRuleEngineTime(originatorId, tenantId, cntTime);
 | 
				
			||||||
        Mockito.reset(tbClusterService, auditLogService);
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected void testNotifyEntityDeleteOneTimeMsgToEdgeServiceNever(HasName entity, EntityId entityId, EntityId originatorId,
 | 
					    protected void testNotifyEntityNeverMsgToEdgeServiceOneTime(HasName entity, EntityId entityId, TenantId tenantId,
 | 
				
			||||||
                                                                      TenantId tenantId, CustomerId customerId, UserId userId, String userName,
 | 
					                                                                ActionType actionType) {
 | 
				
			||||||
                                                                      ActionType actionType, Object... additionalInfo) {
 | 
					        testSendNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, 1);
 | 
				
			||||||
        testNotificationMsgToEdgeServiceNever(entityId);
 | 
					 | 
				
			||||||
        testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo);
 | 
					 | 
				
			||||||
        testPushMsgToRuleEngineOneTime(entityId, tenantId);
 | 
					 | 
				
			||||||
        testBroadcastEntityStateChangeEventOneTime(entityId, tenantId);
 | 
					 | 
				
			||||||
        Mockito.reset(tbClusterService, auditLogService);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    protected void testNotifyEntityNeverMsgToEdgeServiceOneTime(HasName entity, EntityId entityId, TenantId tenantId, ActionType actionType) {
 | 
					 | 
				
			||||||
        testSendNotificationMsgToEdgeServiceOneTime(entityId, tenantId, actionType);
 | 
					 | 
				
			||||||
        testLogEntityActionNever(entityId, entity);
 | 
					        testLogEntityActionNever(entityId, entity);
 | 
				
			||||||
        testPushMsgToRuleEngineNever(entityId);
 | 
					        testPushMsgToRuleEngineNever(entityId);
 | 
				
			||||||
        Mockito.reset(tbClusterService, auditLogService);
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected void testNotifyEntityOneTimeMsgToEdgeServiceNever(HasName entity, EntityId entityId, EntityId originatorId,
 | 
					    protected void testNotifyEntityOneTimeMsgToEdgeServiceNever(HasName entity, EntityId entityId, EntityId originatorId,
 | 
				
			||||||
                                                                TenantId tenantId, CustomerId customerId, UserId userId, String userName,
 | 
					                                                                TenantId tenantId, CustomerId customerId, UserId userId,
 | 
				
			||||||
                                                                ActionType actionType, Object... additionalInfo) {
 | 
					                                                                String userName, ActionType actionType, Object... additionalInfo) {
 | 
				
			||||||
 | 
					        int cntTime = 1;
 | 
				
			||||||
        testNotificationMsgToEdgeServiceNever(entityId);
 | 
					        testNotificationMsgToEdgeServiceNever(entityId);
 | 
				
			||||||
        testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo);
 | 
					        testLogEntityAction(entity, originatorId, tenantId, customerId, userId, userName, actionType, cntTime, additionalInfo);
 | 
				
			||||||
        testPushMsgToRuleEngineOneTime(originatorId, tenantId);
 | 
					        testPushMsgToRuleEngineTime(originatorId, tenantId, cntTime);
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected void testNotifyManyEntityManyTimeMsgToEdgeServiceNever(HasName entity, HasName originator,
 | 
				
			||||||
 | 
					                                                                     TenantId tenantId, CustomerId customerId, UserId userId, String userName,
 | 
				
			||||||
 | 
					                                                                     ActionType actionType, int cntTime, Object... additionalInfo) {
 | 
				
			||||||
 | 
					        EntityId entityId = createEntityId_NULL_UUID(entity);
 | 
				
			||||||
 | 
					        EntityId originatorId = createEntityId_NULL_UUID(originator);
 | 
				
			||||||
 | 
					        testNotificationMsgToEdgeServiceNever(entityId);
 | 
				
			||||||
 | 
					        ArgumentMatcher<HasName> matcherEntityClassEquals = argument -> argument.getClass().equals(entity.getClass());
 | 
				
			||||||
 | 
					        ArgumentMatcher<EntityId> matcherOriginatorId = argument -> argument.getClass().equals(originatorId.getClass());
 | 
				
			||||||
 | 
					        testLogEntityActionAdditionalInfo(matcherEntityClassEquals, matcherOriginatorId, tenantId, customerId, userId, userName, actionType, cntTime,
 | 
				
			||||||
 | 
					                additionalInfo);
 | 
				
			||||||
 | 
					        testPushMsgToRuleEngineTime(originatorId, tenantId, cntTime);
 | 
				
			||||||
        Mockito.reset(tbClusterService, auditLogService);
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected void testNotifyEntityBroadcastEntityStateChangeEventOneTimeMsgToEdgeServiceNever(HasName entity, EntityId entityId, EntityId originatorId,
 | 
					    protected void testNotifyEntityBroadcastEntityStateChangeEventOneTimeMsgToEdgeServiceNever(HasName entity, EntityId entityId, EntityId originatorId,
 | 
				
			||||||
                                                                                               TenantId tenantId, CustomerId customerId, UserId userId, String userName,
 | 
					                                                                                               TenantId tenantId, CustomerId customerId, UserId userId, String userName,
 | 
				
			||||||
                                                                                               ActionType actionType, Object... additionalInfo) {
 | 
					                                                                                               ActionType actionType, Object... additionalInfo) {
 | 
				
			||||||
 | 
					        int cntTime = 1;
 | 
				
			||||||
        testNotificationMsgToEdgeServiceNever(entityId);
 | 
					        testNotificationMsgToEdgeServiceNever(entityId);
 | 
				
			||||||
        testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo);
 | 
					        testLogEntityAction(entity, originatorId, tenantId, customerId, userId, userName, actionType, cntTime, additionalInfo);
 | 
				
			||||||
        testPushMsgToRuleEngineOneTime(originatorId, tenantId);
 | 
					        testPushMsgToRuleEngineTime(originatorId, tenantId, cntTime);
 | 
				
			||||||
        testBroadcastEntityStateChangeEventOneTime(entityId, tenantId);
 | 
					        testBroadcastEntityStateChangeEventTime(entityId, tenantId, cntTime);
 | 
				
			||||||
        Mockito.reset(tbClusterService, auditLogService);
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected void testNotifyEntityError(HasName entity, TenantId tenantId,
 | 
					    protected void testNotifyEntityEqualsOneTimeError(HasName entity, TenantId tenantId,
 | 
				
			||||||
                                         UserId userId, String userName, ActionType actionType, Exception exp,
 | 
					                                                      UserId userId, String userName, ActionType actionType, Exception exp,
 | 
				
			||||||
                                         Object... additionalInfo) {
 | 
					                                                      Object... additionalInfo) {
 | 
				
			||||||
        CustomerId customer_NULL_UUID = (CustomerId) EntityIdFactory.getByTypeAndUuid(EntityType.CUSTOMER, ModelConstants.NULL_UUID);
 | 
					        CustomerId customer_NULL_UUID = (CustomerId) EntityIdFactory.getByTypeAndUuid(EntityType.CUSTOMER, ModelConstants.NULL_UUID);
 | 
				
			||||||
        EntityId entity_NULL_UUID = EntityIdFactory.getByTypeAndUuid(EntityType.valueOf(entity.getClass().toString()
 | 
					        EntityId entity_originator_NULL_UUID = createEntityId_NULL_UUID(entity);
 | 
				
			||||||
                        .substring(entity.getClass().toString().lastIndexOf(".") + 1).toUpperCase(Locale.ENGLISH)),
 | 
					        testNotificationMsgToEdgeServiceNever(entity_originator_NULL_UUID);
 | 
				
			||||||
                ModelConstants.NULL_UUID);
 | 
					        ArgumentMatcher<HasName> matcherEntityEquals = argument -> argument.getClass().equals(entity.getClass());
 | 
				
			||||||
        testNotificationMsgToEdgeServiceNever(entity_NULL_UUID);
 | 
					        ArgumentMatcher<Exception> matcherError = argument -> argument.getMessage().contains(exp.getMessage())
 | 
				
			||||||
        if (additionalInfo.length > 0) {
 | 
					                & argument.getClass().equals(exp.getClass());
 | 
				
			||||||
            Mockito.verify(auditLogService, times(1)).logEntityAction(Mockito.eq(tenantId),
 | 
					        testLogEntityActionErrorAdditionalInfo(matcherEntityEquals, entity_originator_NULL_UUID, tenantId, customer_NULL_UUID, userId,
 | 
				
			||||||
                    Mockito.eq(customer_NULL_UUID), Mockito.eq(userId), Mockito.eq(userName),
 | 
					                userName, actionType, 1, matcherError, additionalInfo);
 | 
				
			||||||
                    Mockito.eq(entity_NULL_UUID), Mockito.any(entity.getClass()), Mockito.eq(actionType),
 | 
					        testPushMsgToRuleEngineNever(entity_originator_NULL_UUID);
 | 
				
			||||||
                    Mockito.argThat(argument ->
 | 
					    }
 | 
				
			||||||
                            argument.getMessage().equals(exp.getMessage())), Mockito.eq(additionalInfo));
 | 
					
 | 
				
			||||||
        } else {
 | 
					    protected void testNotifyEntityIsNullOneTimeError(HasName entity, TenantId tenantId,
 | 
				
			||||||
            Mockito.verify(auditLogService, times(1)).logEntityAction(Mockito.eq(tenantId),
 | 
					                                                      UserId userId, String userName, ActionType actionType, Exception exp,
 | 
				
			||||||
                    Mockito.eq(customer_NULL_UUID), Mockito.eq(userId), Mockito.eq(userName),
 | 
					                                                      Object... additionalInfo) {
 | 
				
			||||||
                    Mockito.eq(entity_NULL_UUID), Mockito.any(entity.getClass()), Mockito.eq(actionType),
 | 
					        CustomerId customer_NULL_UUID = (CustomerId) EntityIdFactory.getByTypeAndUuid(EntityType.CUSTOMER, ModelConstants.NULL_UUID);
 | 
				
			||||||
                    Mockito.argThat(argument ->
 | 
					        EntityId entity_originator_NULL_UUID = createEntityId_NULL_UUID(entity);
 | 
				
			||||||
                        argument.getMessage().equals(exp.getMessage())));
 | 
					        testNotificationMsgToEdgeServiceNever(entity_originator_NULL_UUID);
 | 
				
			||||||
        }
 | 
					        ArgumentMatcher<HasName> matcherEntityIsNull = Objects::isNull;
 | 
				
			||||||
        testPushMsgToRuleEngineNever(entity_NULL_UUID);
 | 
					        ArgumentMatcher<Exception> matcherError = argument -> argument.getMessage().contains(exp.getMessage()) &
 | 
				
			||||||
        Mockito.reset(tbClusterService, auditLogService);
 | 
					                argument.getClass().equals(exp.getClass());
 | 
				
			||||||
 | 
					        testLogEntityActionErrorAdditionalInfo(matcherEntityIsNull, entity_originator_NULL_UUID, tenantId, customer_NULL_UUID,
 | 
				
			||||||
 | 
					                userId, userName, actionType, 1, matcherError, additionalInfo);
 | 
				
			||||||
 | 
					        testPushMsgToRuleEngineNever(entity_originator_NULL_UUID);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected void testNotifyEntityNever(EntityId entityId, HasName entity) {
 | 
					    protected void testNotifyEntityNever(EntityId entityId, HasName entity) {
 | 
				
			||||||
 | 
					        entityId = entityId == null ? createEntityId_NULL_UUID(entity) : entityId;
 | 
				
			||||||
        testNotificationMsgToEdgeServiceNever(entityId);
 | 
					        testNotificationMsgToEdgeServiceNever(entityId);
 | 
				
			||||||
        testLogEntityActionNever(entityId, entity);
 | 
					        testLogEntityActionNever(entityId, entity);
 | 
				
			||||||
        testPushMsgToRuleEngineNever(entityId);
 | 
					        testPushMsgToRuleEngineNever(entityId);
 | 
				
			||||||
@ -139,36 +154,144 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest {
 | 
				
			|||||||
                Mockito.any(entityId.getClass()), Mockito.any(), Mockito.any());
 | 
					                Mockito.any(entityId.getClass()), Mockito.any(), Mockito.any());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void testLogEntityActionOneTime(HasName entity, EntityId originatorId, TenantId tenantId, CustomerId customerId,
 | 
					    private void testPushMsgToRuleEngineTime(EntityId originatorId, TenantId tenantId, int cntTime) {
 | 
				
			||||||
                                            UserId userId, String userName, ActionType actionType, Object... additionalInfo) {
 | 
					        ArgumentMatcher<EntityId> matcherOriginatorId = cntTime == 1 ? argument -> argument.equals(originatorId) :
 | 
				
			||||||
        if (additionalInfo.length == 0) {
 | 
					                argument -> argument.getClass().equals(originatorId.getClass());
 | 
				
			||||||
            Mockito.verify(auditLogService, times(1)).logEntityAction(Mockito.eq(tenantId),
 | 
					        Mockito.verify(tbClusterService, times(cntTime)).pushMsgToRuleEngine(Mockito.eq(tenantId),
 | 
				
			||||||
                    Mockito.eq(customerId), Mockito.eq(userId), Mockito.eq(userName), Mockito.eq(originatorId),
 | 
					                Mockito.argThat(matcherOriginatorId), Mockito.any(TbMsg.class), Mockito.isNull());
 | 
				
			||||||
                    Mockito.eq(entity), Mockito.eq(actionType), Mockito.isNull());
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            String additionalInfoStr = extractParameter(String.class, 0, additionalInfo);
 | 
					 | 
				
			||||||
            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(), Mockito.eq(additionalInfoStr));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void testPushMsgToRuleEngineOneTime(EntityId originatorId, TenantId tenantId) {
 | 
					    private void testSendNotificationMsgToEdgeServiceTime(EntityId entityId, TenantId tenantId, ActionType actionType, int cntTime) {
 | 
				
			||||||
        Mockito.verify(tbClusterService, times(1)).pushMsgToRuleEngine(Mockito.eq(tenantId),
 | 
					        Mockito.verify(tbClusterService, times(cntTime)).sendNotificationMsgToEdge(Mockito.eq(tenantId),
 | 
				
			||||||
                Mockito.eq(originatorId), Mockito.any(TbMsg.class), Mockito.isNull());
 | 
					                Mockito.any(), Mockito.eq(entityId), Mockito.any(), Mockito.isNull(),
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private void testSendNotificationMsgToEdgeServiceOneTime(EntityId entityId, TenantId tenantId, ActionType actionType) {
 | 
					 | 
				
			||||||
        Mockito.verify(tbClusterService, times(1)).sendNotificationMsgToEdge(Mockito.eq(tenantId),
 | 
					 | 
				
			||||||
                Mockito.isNull(), Mockito.eq(entityId), Mockito.isNull(), Mockito.isNull(),
 | 
					 | 
				
			||||||
                Mockito.eq(edgeTypeByActionType(actionType)));
 | 
					                Mockito.eq(edgeTypeByActionType(actionType)));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void testBroadcastEntityStateChangeEventOneTime(EntityId entityId, TenantId tenantId) {
 | 
					    private void testBroadcastEntityStateChangeEventTime(EntityId entityId, TenantId tenantId, int cntTime) {
 | 
				
			||||||
        Mockito.verify(tbClusterService, times(1)).broadcastEntityStateChangeEvent(Mockito.eq(tenantId),
 | 
					        Mockito.verify(tbClusterService, times(cntTime)).broadcastEntityStateChangeEvent(Mockito.eq(tenantId),
 | 
				
			||||||
                Mockito.any(entityId.getClass()), Mockito.any(ComponentLifecycleEvent.class));
 | 
					                Mockito.any(entityId.getClass()), Mockito.any(ComponentLifecycleEvent.class));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void testLogEntityAction(HasName entity, EntityId originatorId, TenantId tenantId,
 | 
				
			||||||
 | 
					                                     CustomerId customerId, UserId userId, String userName,
 | 
				
			||||||
 | 
					                                     ActionType actionType, int cntTime, Object... additionalInfo) {
 | 
				
			||||||
 | 
					        ArgumentMatcher<HasName> matcherEntityEquals = argument -> argument.equals(entity);
 | 
				
			||||||
 | 
					        ArgumentMatcher<EntityId> matcherOriginatorId = argument -> argument.equals(originatorId);
 | 
				
			||||||
 | 
					        testLogEntityActionAdditionalInfo(matcherEntityEquals, matcherOriginatorId, tenantId, customerId, userId, userName,
 | 
				
			||||||
 | 
					                actionType, cntTime, additionalInfo);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void testLogEntityActionAdditionalInfo(ArgumentMatcher<HasName> matcherEntity, ArgumentMatcher<EntityId> matcherOriginatorId,
 | 
				
			||||||
 | 
					                                                   TenantId tenantId, CustomerId customerId, UserId userId, String userName,
 | 
				
			||||||
 | 
					                                                   ActionType actionType, int cntTime, Object... additionalInfo) {
 | 
				
			||||||
 | 
					        switch (additionalInfo.length) {
 | 
				
			||||||
 | 
					            case 1:
 | 
				
			||||||
 | 
					                Mockito.verify(auditLogService, times(cntTime))
 | 
				
			||||||
 | 
					                        .logEntityAction(Mockito.eq(tenantId),
 | 
				
			||||||
 | 
					                                Mockito.eq(customerId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userName),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherOriginatorId),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherEntity),
 | 
				
			||||||
 | 
					                                Mockito.eq(actionType),
 | 
				
			||||||
 | 
					                                Mockito.isNull(),
 | 
				
			||||||
 | 
					                                Mockito.eq(extractParameter(String.class, 0, additionalInfo)));
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            case 2:
 | 
				
			||||||
 | 
					                Mockito.verify(auditLogService, times(cntTime))
 | 
				
			||||||
 | 
					                        .logEntityAction(Mockito.eq(tenantId),
 | 
				
			||||||
 | 
					                                Mockito.eq(customerId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userName),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherOriginatorId),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherEntity),
 | 
				
			||||||
 | 
					                                Mockito.eq(actionType),
 | 
				
			||||||
 | 
					                                Mockito.isNull(),
 | 
				
			||||||
 | 
					                                Mockito.eq(extractParameter(String.class, 0, additionalInfo)),
 | 
				
			||||||
 | 
					                                Mockito.eq(extractParameter(String.class, 1, additionalInfo)));
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            case 3:
 | 
				
			||||||
 | 
					                Mockito.verify(auditLogService, times(cntTime))
 | 
				
			||||||
 | 
					                        .logEntityAction(Mockito.eq(tenantId),
 | 
				
			||||||
 | 
					                                Mockito.eq(customerId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userName),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherOriginatorId),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherEntity),
 | 
				
			||||||
 | 
					                                Mockito.eq(actionType),
 | 
				
			||||||
 | 
					                                Mockito.isNull(),
 | 
				
			||||||
 | 
					                                Mockito.eq(extractParameter(String.class, 0, additionalInfo)),
 | 
				
			||||||
 | 
					                                Mockito.eq(extractParameter(String.class, 1, additionalInfo)),
 | 
				
			||||||
 | 
					                                Mockito.eq(extractParameter(String.class, 2, additionalInfo)));
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            default:
 | 
				
			||||||
 | 
					                Mockito.verify(auditLogService, times(cntTime))
 | 
				
			||||||
 | 
					                        .logEntityAction(Mockito.eq(tenantId),
 | 
				
			||||||
 | 
					                                Mockito.eq(customerId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userName),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherOriginatorId),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherEntity),
 | 
				
			||||||
 | 
					                                Mockito.eq(actionType),
 | 
				
			||||||
 | 
					                                Mockito.isNull());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void testLogEntityActionErrorAdditionalInfo(ArgumentMatcher<HasName> matcherEntity, EntityId originatorId, TenantId tenantId,
 | 
				
			||||||
 | 
					                                                        CustomerId customerId, UserId userId, String userName, ActionType actionType,
 | 
				
			||||||
 | 
					                                                        int cntTime, ArgumentMatcher<Exception> matcherError, Object... additionalInfo) {
 | 
				
			||||||
 | 
					        switch (additionalInfo.length) {
 | 
				
			||||||
 | 
					            case 1:
 | 
				
			||||||
 | 
					                Mockito.verify(auditLogService, times(cntTime))
 | 
				
			||||||
 | 
					                        .logEntityAction(Mockito.eq(tenantId),
 | 
				
			||||||
 | 
					                                Mockito.eq(customerId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userName),
 | 
				
			||||||
 | 
					                                Mockito.eq(originatorId),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherEntity),
 | 
				
			||||||
 | 
					                                Mockito.eq(actionType),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherError),
 | 
				
			||||||
 | 
					                                Mockito.eq(extractParameter(String.class, 0, additionalInfo)));
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            case 2:
 | 
				
			||||||
 | 
					                Mockito.verify(auditLogService, times(cntTime))
 | 
				
			||||||
 | 
					                        .logEntityAction(Mockito.eq(tenantId),
 | 
				
			||||||
 | 
					                                Mockito.eq(customerId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userName),
 | 
				
			||||||
 | 
					                                Mockito.eq(originatorId),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherEntity),
 | 
				
			||||||
 | 
					                                Mockito.eq(actionType),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherError),
 | 
				
			||||||
 | 
					                                Mockito.eq(extractParameter(String.class, 0, additionalInfo)),
 | 
				
			||||||
 | 
					                                Mockito.eq(extractParameter(String.class, 1, additionalInfo)));
 | 
				
			||||||
 | 
					           case 3:
 | 
				
			||||||
 | 
					                Mockito.verify(auditLogService, times(cntTime))
 | 
				
			||||||
 | 
					                        .logEntityAction(Mockito.eq(tenantId),
 | 
				
			||||||
 | 
					                                Mockito.eq(customerId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userName),
 | 
				
			||||||
 | 
					                                Mockito.eq(originatorId),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherEntity),
 | 
				
			||||||
 | 
					                                Mockito.eq(actionType),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherError),
 | 
				
			||||||
 | 
					                                Mockito.eq(extractParameter(String.class, 0, additionalInfo)),
 | 
				
			||||||
 | 
					                                Mockito.eq(extractParameter(String.class, 1, additionalInfo)),
 | 
				
			||||||
 | 
					                                Mockito.eq(extractParameter(String.class, 3, additionalInfo)));
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            default:
 | 
				
			||||||
 | 
					                Mockito.verify(auditLogService, times(cntTime))
 | 
				
			||||||
 | 
					                        .logEntityAction(Mockito.eq(tenantId),
 | 
				
			||||||
 | 
					                                Mockito.eq(customerId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userId),
 | 
				
			||||||
 | 
					                                Mockito.eq(userName),
 | 
				
			||||||
 | 
					                                Mockito.eq(originatorId),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherEntity),
 | 
				
			||||||
 | 
					                                Mockito.eq(actionType),
 | 
				
			||||||
 | 
					                                Mockito.argThat(matcherError));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private <T> T extractParameter(Class<T> clazz, int index, Object... additionalInfo) {
 | 
					    private <T> T extractParameter(Class<T> clazz, int index, Object... additionalInfo) {
 | 
				
			||||||
        T result = null;
 | 
					        T result = null;
 | 
				
			||||||
        if (additionalInfo != null && additionalInfo.length > index) {
 | 
					        if (additionalInfo != null && additionalInfo.length > index) {
 | 
				
			||||||
@ -179,4 +302,10 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        return result;
 | 
					        return result;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private EntityId createEntityId_NULL_UUID(HasName entity) {
 | 
				
			||||||
 | 
					        return EntityIdFactory.getByTypeAndUuid(EntityType.valueOf(entity.getClass().toString()
 | 
				
			||||||
 | 
					                        .substring(entity.getClass().toString().lastIndexOf(".") + 1).toUpperCase(Locale.ENGLISH)),
 | 
				
			||||||
 | 
					                ModelConstants.NULL_UUID);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -22,17 +22,20 @@ import org.junit.After;
 | 
				
			|||||||
import org.junit.Assert;
 | 
					import org.junit.Assert;
 | 
				
			||||||
import org.junit.Before;
 | 
					import org.junit.Before;
 | 
				
			||||||
import org.junit.Test;
 | 
					import org.junit.Test;
 | 
				
			||||||
 | 
					import org.mockito.Mockito;
 | 
				
			||||||
import org.thingsboard.server.common.data.Customer;
 | 
					import org.thingsboard.server.common.data.Customer;
 | 
				
			||||||
import org.thingsboard.server.common.data.EntitySubtype;
 | 
					import org.thingsboard.server.common.data.EntitySubtype;
 | 
				
			||||||
import org.thingsboard.server.common.data.EntityView;
 | 
					import org.thingsboard.server.common.data.EntityView;
 | 
				
			||||||
import org.thingsboard.server.common.data.Tenant;
 | 
					import org.thingsboard.server.common.data.Tenant;
 | 
				
			||||||
import org.thingsboard.server.common.data.User;
 | 
					import org.thingsboard.server.common.data.User;
 | 
				
			||||||
import org.thingsboard.server.common.data.asset.Asset;
 | 
					import org.thingsboard.server.common.data.asset.Asset;
 | 
				
			||||||
 | 
					import org.thingsboard.server.common.data.audit.ActionType;
 | 
				
			||||||
import org.thingsboard.server.common.data.edge.Edge;
 | 
					import org.thingsboard.server.common.data.edge.Edge;
 | 
				
			||||||
import org.thingsboard.server.common.data.id.CustomerId;
 | 
					import org.thingsboard.server.common.data.id.CustomerId;
 | 
				
			||||||
import org.thingsboard.server.common.data.page.PageData;
 | 
					import org.thingsboard.server.common.data.page.PageData;
 | 
				
			||||||
import org.thingsboard.server.common.data.page.PageLink;
 | 
					import org.thingsboard.server.common.data.page.PageLink;
 | 
				
			||||||
import org.thingsboard.server.common.data.security.Authority;
 | 
					import org.thingsboard.server.common.data.security.Authority;
 | 
				
			||||||
 | 
					import org.thingsboard.server.dao.exception.DataValidationException;
 | 
				
			||||||
import org.thingsboard.server.dao.model.ModelConstants;
 | 
					import org.thingsboard.server.dao.model.ModelConstants;
 | 
				
			||||||
import org.thingsboard.server.service.stats.DefaultRuleEngineStatisticsService;
 | 
					import org.thingsboard.server.service.stats.DefaultRuleEngineStatisticsService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -83,8 +86,14 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
 | 
				
			|||||||
        Asset asset = new Asset();
 | 
					        Asset asset = new Asset();
 | 
				
			||||||
        asset.setName("My asset");
 | 
					        asset.setName("My asset");
 | 
				
			||||||
        asset.setType("default");
 | 
					        asset.setType("default");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Asset savedAsset = doPost("/api/asset", asset, Asset.class);
 | 
					        Asset savedAsset = doPost("/api/asset", asset, Asset.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityOneTimeMsgToEdgeServiceNever(savedAsset, savedAsset.getId(), savedAsset.getId(),
 | 
				
			||||||
 | 
					                savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Assert.assertNotNull(savedAsset);
 | 
					        Assert.assertNotNull(savedAsset);
 | 
				
			||||||
        Assert.assertNotNull(savedAsset.getId());
 | 
					        Assert.assertNotNull(savedAsset.getId());
 | 
				
			||||||
        Assert.assertTrue(savedAsset.getCreatedTime() > 0);
 | 
					        Assert.assertTrue(savedAsset.getCreatedTime() > 0);
 | 
				
			||||||
@ -93,9 +102,14 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
 | 
				
			|||||||
        Assert.assertEquals(NULL_UUID, savedAsset.getCustomerId().getId());
 | 
					        Assert.assertEquals(NULL_UUID, savedAsset.getCustomerId().getId());
 | 
				
			||||||
        Assert.assertEquals(asset.getName(), savedAsset.getName());
 | 
					        Assert.assertEquals(asset.getName(), savedAsset.getName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        savedAsset.setName("My new asset");
 | 
					        savedAsset.setName("My new asset");
 | 
				
			||||||
        doPost("/api/asset", savedAsset, Asset.class);
 | 
					        doPost("/api/asset", savedAsset, Asset.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityAllOneTime(savedAsset, savedAsset.getId(), savedAsset.getId(),
 | 
				
			||||||
 | 
					                savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.UPDATED);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Asset foundAsset = doGet("/api/asset/" + savedAsset.getId().getId().toString(), Asset.class);
 | 
					        Asset foundAsset = doGet("/api/asset/" + savedAsset.getId().getId().toString(), Asset.class);
 | 
				
			||||||
        Assert.assertEquals(foundAsset.getName(), savedAsset.getName());
 | 
					        Assert.assertEquals(foundAsset.getName(), savedAsset.getName());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -105,13 +119,33 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
 | 
				
			|||||||
        Asset asset = new Asset();
 | 
					        Asset asset = new Asset();
 | 
				
			||||||
        asset.setName(RandomStringUtils.randomAlphabetic(300));
 | 
					        asset.setName(RandomStringUtils.randomAlphabetic(300));
 | 
				
			||||||
        asset.setType("default");
 | 
					        asset.setType("default");
 | 
				
			||||||
        doPost("/api/asset", asset).andExpect(statusReason(containsString("length of name must be equal or less than 255")));
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        String msgError = "length of name must be equal or less than 255";
 | 
				
			||||||
 | 
					        doPost("/api/asset", asset).andExpect(statusReason(containsString(msgError)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityEqualsOneTimeError(asset, savedTenant.getId(),
 | 
				
			||||||
 | 
					                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        asset.setName("Normal name");
 | 
					        asset.setName("Normal name");
 | 
				
			||||||
        asset.setType(RandomStringUtils.randomAlphabetic(300));
 | 
					        asset.setType(RandomStringUtils.randomAlphabetic(300));
 | 
				
			||||||
        doPost("/api/asset", asset).andExpect(statusReason(containsString("length of type must be equal or less than 255")));
 | 
					        msgError = "length of type must be equal or less than 255";
 | 
				
			||||||
 | 
					        doPost("/api/asset", asset).andExpect(statusReason(containsString(msgError)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityEqualsOneTimeError(asset, savedTenant.getId(),
 | 
				
			||||||
 | 
					                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        asset.setType("default");
 | 
					        asset.setType("default");
 | 
				
			||||||
        asset.setLabel(RandomStringUtils.randomAlphabetic(300));
 | 
					        asset.setLabel(RandomStringUtils.randomAlphabetic(300));
 | 
				
			||||||
        doPost("/api/asset", asset).andExpect(statusReason(containsString("length of label must be equal or less than 255")));
 | 
					        msgError = "length of label must be equal or less than 255";
 | 
				
			||||||
 | 
					        doPost("/api/asset", asset).andExpect(statusReason(containsString(msgError)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityEqualsOneTimeError(asset, savedTenant.getId(),
 | 
				
			||||||
 | 
					                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
@ -122,7 +156,13 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
 | 
				
			|||||||
        Asset savedAsset = doPost("/api/asset", asset, Asset.class);
 | 
					        Asset savedAsset = doPost("/api/asset", asset, Asset.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        loginDifferentTenant();
 | 
					        loginDifferentTenant();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        doPost("/api/asset", savedAsset, Asset.class, status().isForbidden());
 | 
					        doPost("/api/asset", savedAsset, Asset.class, status().isForbidden());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityNever(savedAsset.getId(), savedAsset);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        deleteDifferentTenant();
 | 
					        deleteDifferentTenant();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -140,12 +180,21 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
 | 
				
			|||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void testFindAssetTypesByTenantId() throws Exception {
 | 
					    public void testFindAssetTypesByTenantId() throws Exception {
 | 
				
			||||||
        List<Asset> assets = new ArrayList<>();
 | 
					        List<Asset> assets = new ArrayList<>();
 | 
				
			||||||
        for (int i = 0; i < 3; i++) {
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        int cntTime = 3;
 | 
				
			||||||
 | 
					        for (int i = 0; i < cntTime; i++) {
 | 
				
			||||||
            Asset asset = new Asset();
 | 
					            Asset asset = new Asset();
 | 
				
			||||||
            asset.setName("My asset B" + i);
 | 
					            asset.setName("My asset B" + i);
 | 
				
			||||||
            asset.setType("typeB");
 | 
					            asset.setType("typeB");
 | 
				
			||||||
            assets.add(doPost("/api/asset", asset, Asset.class));
 | 
					            assets.add(doPost("/api/asset", asset, Asset.class));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyManyEntityManyTimeMsgToEdgeServiceNever(new Asset(), new Asset(),
 | 
				
			||||||
 | 
					                savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(),
 | 
				
			||||||
 | 
					                ActionType.ADDED, cntTime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (int i = 0; i < 7; i++) {
 | 
					        for (int i = 0; i < 7; i++) {
 | 
				
			||||||
            Asset asset = new Asset();
 | 
					            Asset asset = new Asset();
 | 
				
			||||||
            asset.setName("My asset C" + i);
 | 
					            asset.setName("My asset C" + i);
 | 
				
			||||||
@ -176,9 +225,15 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
 | 
				
			|||||||
        asset.setType("default");
 | 
					        asset.setType("default");
 | 
				
			||||||
        Asset savedAsset = doPost("/api/asset", asset, Asset.class);
 | 
					        Asset savedAsset = doPost("/api/asset", asset, Asset.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        doDelete("/api/asset/" + savedAsset.getId().getId().toString())
 | 
					        doDelete("/api/asset/" + savedAsset.getId().getId().toString())
 | 
				
			||||||
                .andExpect(status().isOk());
 | 
					                .andExpect(status().isOk());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityOneTimeMsgToEdgeServiceNever(savedAsset, savedAsset.getId(), savedAsset.getId(),
 | 
				
			||||||
 | 
					                savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(),
 | 
				
			||||||
 | 
					                ActionType.DELETED, savedAsset.getId().getId().toString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        doGet("/api/asset/" + savedAsset.getId().getId().toString())
 | 
					        doGet("/api/asset/" + savedAsset.getId().getId().toString())
 | 
				
			||||||
                .andExpect(status().isNotFound());
 | 
					                .andExpect(status().isNotFound());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -202,9 +257,16 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
 | 
				
			|||||||
        view.setType("default");
 | 
					        view.setType("default");
 | 
				
			||||||
        EntityView savedView = doPost("/api/entityView", view, EntityView.class);
 | 
					        EntityView savedView = doPost("/api/entityView", view, EntityView.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        doDelete("/api/asset/" + savedAsset1.getId().getId().toString())
 | 
					        doDelete("/api/asset/" + savedAsset1.getId().getId().toString())
 | 
				
			||||||
                .andExpect(status().isBadRequest());
 | 
					                .andExpect(status().isBadRequest());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        String msgError = "Can't delete asset that has entity views";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityIsNullOneTimeError(savedAsset1,  savedTenant.getId(), tenantAdmin.getId(), tenantAdmin.getEmail(),
 | 
				
			||||||
 | 
					                ActionType.DELETED, new DataValidationException(msgError), savedAsset1.getId().getId().toString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        savedView.setEntityId(savedAsset2.getId());
 | 
					        savedView.setEntityId(savedAsset2.getId());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        doPost("/api/entityView", savedView, EntityView.class);
 | 
					        doPost("/api/entityView", savedView, EntityView.class);
 | 
				
			||||||
@ -220,18 +282,32 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
 | 
				
			|||||||
    public void testSaveAssetWithEmptyType() throws Exception {
 | 
					    public void testSaveAssetWithEmptyType() throws Exception {
 | 
				
			||||||
        Asset asset = new Asset();
 | 
					        Asset asset = new Asset();
 | 
				
			||||||
        asset.setName("My asset");
 | 
					        asset.setName("My asset");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        String msgError = "Asset type should be specified";
 | 
				
			||||||
        doPost("/api/asset", asset)
 | 
					        doPost("/api/asset", asset)
 | 
				
			||||||
                .andExpect(status().isBadRequest())
 | 
					                .andExpect(status().isBadRequest())
 | 
				
			||||||
                .andExpect(statusReason(containsString("Asset type should be specified")));
 | 
					                .andExpect(statusReason(containsString(msgError)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityEqualsOneTimeError(asset, savedTenant.getId(),
 | 
				
			||||||
 | 
					                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void testSaveAssetWithEmptyName() throws Exception {
 | 
					    public void testSaveAssetWithEmptyName() throws Exception {
 | 
				
			||||||
        Asset asset = new Asset();
 | 
					        Asset asset = new Asset();
 | 
				
			||||||
        asset.setType("default");
 | 
					        asset.setType("default");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        String msgError = "Asset name should be specified";
 | 
				
			||||||
        doPost("/api/asset", asset)
 | 
					        doPost("/api/asset", asset)
 | 
				
			||||||
                .andExpect(status().isBadRequest())
 | 
					                .andExpect(status().isBadRequest())
 | 
				
			||||||
                .andExpect(statusReason(containsString("Asset name should be specified")));
 | 
					                .andExpect(statusReason(containsString(msgError)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityEqualsOneTimeError(asset, savedTenant.getId(),
 | 
				
			||||||
 | 
					                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
@ -245,17 +321,29 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
 | 
				
			|||||||
        customer.setTitle("My customer");
 | 
					        customer.setTitle("My customer");
 | 
				
			||||||
        Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
 | 
					        Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Asset assignedAsset = doPost("/api/customer/" + savedCustomer.getId().getId().toString()
 | 
					        Asset assignedAsset = doPost("/api/customer/" + savedCustomer.getId().getId().toString()
 | 
				
			||||||
                + "/asset/" + savedAsset.getId().getId().toString(), Asset.class);
 | 
					                + "/asset/" + savedAsset.getId().getId().toString(), Asset.class);
 | 
				
			||||||
        Assert.assertEquals(savedCustomer.getId(), assignedAsset.getCustomerId());
 | 
					        Assert.assertEquals(savedCustomer.getId(), assignedAsset.getCustomerId());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityAllOneTime(assignedAsset, assignedAsset.getId(), assignedAsset.getId(),
 | 
				
			||||||
 | 
					                savedTenant.getId(), savedCustomer.getId(), tenantAdmin.getId(), tenantAdmin.getEmail(),
 | 
				
			||||||
 | 
					                ActionType.ASSIGNED_TO_CUSTOMER, savedCustomer.getId().toString(), savedCustomer.getTitle());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Asset foundAsset = doGet("/api/asset/" + savedAsset.getId().getId().toString(), Asset.class);
 | 
					        Asset foundAsset = doGet("/api/asset/" + savedAsset.getId().getId().toString(), Asset.class);
 | 
				
			||||||
        Assert.assertEquals(savedCustomer.getId(), foundAsset.getCustomerId());
 | 
					        Assert.assertEquals(savedCustomer.getId(), foundAsset.getCustomerId());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Asset unassignedAsset =
 | 
					        Asset unassignedAsset =
 | 
				
			||||||
                doDelete("/api/customer/asset/" + savedAsset.getId().getId().toString(), Asset.class);
 | 
					                doDelete("/api/customer/asset/" + savedAsset.getId().getId().toString(), Asset.class);
 | 
				
			||||||
        Assert.assertEquals(ModelConstants.NULL_UUID, unassignedAsset.getCustomerId().getId());
 | 
					        Assert.assertEquals(ModelConstants.NULL_UUID, unassignedAsset.getCustomerId().getId());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityAllOneTime(savedAsset, savedAsset.getId(), savedAsset.getId(),
 | 
				
			||||||
 | 
					                savedTenant.getId(), savedCustomer.getId(), tenantAdmin.getId(), tenantAdmin.getEmail(),
 | 
				
			||||||
 | 
					                ActionType.UNASSIGNED_FROM_CUSTOMER, savedCustomer.getId().toString(), savedCustomer.getTitle());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        foundAsset = doGet("/api/asset/" + savedAsset.getId().getId().toString(), Asset.class);
 | 
					        foundAsset = doGet("/api/asset/" + savedAsset.getId().getId().toString(), Asset.class);
 | 
				
			||||||
        Assert.assertEquals(ModelConstants.NULL_UUID, foundAsset.getCustomerId().getId());
 | 
					        Assert.assertEquals(ModelConstants.NULL_UUID, foundAsset.getCustomerId().getId());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -267,9 +355,14 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
 | 
				
			|||||||
        asset.setType("default");
 | 
					        asset.setType("default");
 | 
				
			||||||
        Asset savedAsset = doPost("/api/asset", asset, Asset.class);
 | 
					        Asset savedAsset = doPost("/api/asset", asset, Asset.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        String msgError = "Asset name should be specified";
 | 
				
			||||||
        doPost("/api/customer/" + Uuids.timeBased().toString()
 | 
					        doPost("/api/customer/" + Uuids.timeBased().toString()
 | 
				
			||||||
                + "/asset/" + savedAsset.getId().getId().toString())
 | 
					                + "/asset/" + savedAsset.getId().getId().toString())
 | 
				
			||||||
                .andExpect(status().isNotFound());
 | 
					                .andExpect(status().isNotFound());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityNever(asset.getId(), asset);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
@ -301,10 +394,14 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
 | 
				
			|||||||
        asset.setType("default");
 | 
					        asset.setType("default");
 | 
				
			||||||
        Asset savedAsset = doPost("/api/asset", asset, Asset.class);
 | 
					        Asset savedAsset = doPost("/api/asset", asset, Asset.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        doPost("/api/customer/" + savedCustomer.getId().getId().toString()
 | 
					        doPost("/api/customer/" + savedCustomer.getId().getId().toString()
 | 
				
			||||||
                + "/asset/" + savedAsset.getId().getId().toString())
 | 
					                + "/asset/" + savedAsset.getId().getId().toString())
 | 
				
			||||||
                .andExpect(status().isForbidden());
 | 
					                .andExpect(status().isForbidden());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityNever(savedAsset.getId(), savedAsset);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        loginSysAdmin();
 | 
					        loginSysAdmin();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        doDelete("/api/tenant/" + savedTenant2.getId().getId().toString())
 | 
					        doDelete("/api/tenant/" + savedTenant2.getId().getId().toString())
 | 
				
			||||||
@ -314,7 +411,11 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
 | 
				
			|||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void testFindTenantAssets() throws Exception {
 | 
					    public void testFindTenantAssets() throws Exception {
 | 
				
			||||||
        List<Asset> assets = new ArrayList<>();
 | 
					        List<Asset> assets = new ArrayList<>();
 | 
				
			||||||
        for (int i = 0; i < 178; i++) {
 | 
					        int cntEntity = 178;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (int i = 0; i < cntEntity; i++) {
 | 
				
			||||||
            Asset asset = new Asset();
 | 
					            Asset asset = new Asset();
 | 
				
			||||||
            asset.setName("Asset" + i);
 | 
					            asset.setName("Asset" + i);
 | 
				
			||||||
            asset.setType("default");
 | 
					            asset.setType("default");
 | 
				
			||||||
@ -332,6 +433,10 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        } while (pageData.hasNext());
 | 
					        } while (pageData.hasNext());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyManyEntityManyTimeMsgToEdgeServiceNever(new Asset(), new Asset(),
 | 
				
			||||||
 | 
					                savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(),
 | 
				
			||||||
 | 
					                ActionType.ADDED, cntEntity);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        loadedAssets.removeIf(asset -> asset.getType().equals(DefaultRuleEngineStatisticsService.TB_SERVICE_QUEUE));
 | 
					        loadedAssets.removeIf(asset -> asset.getType().equals(DefaultRuleEngineStatisticsService.TB_SERVICE_QUEUE));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Collections.sort(assets, idComparator);
 | 
					        Collections.sort(assets, idComparator);
 | 
				
			||||||
@ -731,17 +836,31 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
 | 
				
			|||||||
        asset.setType("default");
 | 
					        asset.setType("default");
 | 
				
			||||||
        Asset savedAsset = doPost("/api/asset", asset, Asset.class);
 | 
					        Asset savedAsset = doPost("/api/asset", asset, Asset.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        doPost("/api/edge/" + savedEdge.getId().getId().toString()
 | 
					        doPost("/api/edge/" + savedEdge.getId().getId().toString()
 | 
				
			||||||
                + "/asset/" + savedAsset.getId().getId().toString(), Asset.class);
 | 
					                + "/asset/" + savedAsset.getId().getId().toString(), Asset.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityAllOneTime(savedAsset, savedAsset.getId(), savedAsset.getId(),
 | 
				
			||||||
 | 
					                savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ASSIGNED_TO_EDGE,
 | 
				
			||||||
 | 
					                savedAsset.getId().getId().toString(), savedEdge.getId().getId().toString(), edge.getName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PageData<Asset> pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId().toString() + "/assets?",
 | 
					        PageData<Asset> pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId().toString() + "/assets?",
 | 
				
			||||||
                new TypeReference<PageData<Asset>>() {}, new PageLink(100));
 | 
					                new TypeReference<PageData<Asset>>() {}, new PageLink(100));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Assert.assertEquals(1, pageData.getData().size());
 | 
					        Assert.assertEquals(1, pageData.getData().size());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        doDelete("/api/edge/" + savedEdge.getId().getId().toString()
 | 
					        doDelete("/api/edge/" + savedEdge.getId().getId().toString()
 | 
				
			||||||
                + "/asset/" + savedAsset.getId().getId().toString(), Asset.class);
 | 
					                + "/asset/" + savedAsset.getId().getId().toString(), Asset.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyEntityAllOneTime(savedAsset, savedAsset.getId(), savedAsset.getId(),
 | 
				
			||||||
 | 
					                savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(),
 | 
				
			||||||
 | 
					                ActionType.UNASSIGNED_FROM_EDGE, savedAsset.getId().getId().toString(), savedEdge.getId().getId().toString(), savedEdge.getName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId().toString() + "/assets?",
 | 
					        pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId().toString() + "/assets?",
 | 
				
			||||||
                new TypeReference<PageData<Asset>>() {}, new PageLink(100));
 | 
					                new TypeReference<PageData<Asset>>() {}, new PageLink(100));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -122,7 +122,6 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
 | 
				
			|||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void testSaveCustomerWithViolationOfValidation() throws Exception {
 | 
					    public void testSaveCustomerWithViolationOfValidation() throws Exception {
 | 
				
			||||||
        Customer customer = new Customer();
 | 
					        Customer customer = new Customer();
 | 
				
			||||||
        String validationError = "Validation error: ";
 | 
					 | 
				
			||||||
        customer.setTitle(RandomStringUtils.randomAlphabetic(300));
 | 
					        customer.setTitle(RandomStringUtils.randomAlphabetic(300));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Mockito.reset(tbClusterService, auditLogService);
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
@ -130,49 +129,54 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
 | 
				
			|||||||
        String msgError = "length of title must be equal or less than 255";
 | 
					        String msgError = "length of title must be equal or less than 255";
 | 
				
			||||||
        doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
 | 
					        doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        testNotifyEntityError(customer, savedTenant.getId(),
 | 
					        customer.setTenantId(savedTenant.getId());
 | 
				
			||||||
                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(validationError + msgError));
 | 
					        testNotifyEntityEqualsOneTimeError(customer,savedTenant.getId(),
 | 
				
			||||||
 | 
					                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        customer.setTitle("Normal title");
 | 
					        customer.setTitle("Normal title");
 | 
				
			||||||
        customer.setCity(RandomStringUtils.randomAlphabetic(300));
 | 
					        customer.setCity(RandomStringUtils.randomAlphabetic(300));
 | 
				
			||||||
        msgError = "length of city must be equal or less than 255";
 | 
					        msgError = "length of city must be equal or less than 255";
 | 
				
			||||||
        doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
 | 
					        doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        testNotifyEntityError(customer, savedTenant.getId(),
 | 
					        testNotifyEntityEqualsOneTimeError(customer,savedTenant.getId(),
 | 
				
			||||||
                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(validationError + msgError));
 | 
					                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        customer.setCity("Normal city");
 | 
					        customer.setCity("Normal city");
 | 
				
			||||||
        customer.setCountry(RandomStringUtils.randomAlphabetic(300));
 | 
					        customer.setCountry(RandomStringUtils.randomAlphabetic(300));
 | 
				
			||||||
        msgError = "length of country must be equal or less than 255";
 | 
					        msgError = "length of country must be equal or less than 255";
 | 
				
			||||||
        doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
 | 
					        doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        testNotifyEntityError(customer, savedTenant.getId(),
 | 
					        testNotifyEntityEqualsOneTimeError(customer,savedTenant.getId(),
 | 
				
			||||||
                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(validationError + msgError));
 | 
					                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        customer.setCountry("Ukraine");
 | 
					        customer.setCountry("Ukraine");
 | 
				
			||||||
        customer.setPhone(RandomStringUtils.randomAlphabetic(300));
 | 
					        customer.setPhone(RandomStringUtils.randomAlphabetic(300));
 | 
				
			||||||
        msgError = "length of phone must be equal or less than 255";
 | 
					        msgError = "length of phone must be equal or less than 255";
 | 
				
			||||||
        doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
 | 
					        doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        testNotifyEntityError(customer, savedTenant.getId(),
 | 
					        testNotifyEntityEqualsOneTimeError(customer,savedTenant.getId(),
 | 
				
			||||||
                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(validationError + msgError));
 | 
					                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        customer.setPhone("+3892555554512");
 | 
					        customer.setPhone("+3892555554512");
 | 
				
			||||||
        customer.setState(RandomStringUtils.randomAlphabetic(300));
 | 
					        customer.setState(RandomStringUtils.randomAlphabetic(300));
 | 
				
			||||||
        msgError = "length of state must be equal or less than 255";
 | 
					        msgError = "length of state must be equal or less than 255";
 | 
				
			||||||
        doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
 | 
					        doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        testNotifyEntityError(customer, savedTenant.getId(),
 | 
					        testNotifyEntityEqualsOneTimeError(customer,savedTenant.getId(),
 | 
				
			||||||
                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(validationError + msgError));
 | 
					                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        customer.setState("Normal state");
 | 
					        customer.setState("Normal state");
 | 
				
			||||||
        customer.setZip(RandomStringUtils.randomAlphabetic(300));
 | 
					        customer.setZip(RandomStringUtils.randomAlphabetic(300));
 | 
				
			||||||
        msgError = "length of zip or postal code must be equal or less than 255";
 | 
					        msgError = "length of zip or postal code must be equal or less than 255";
 | 
				
			||||||
        doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
 | 
					        doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        testNotifyEntityError(customer, savedTenant.getId(),
 | 
					        testNotifyEntityEqualsOneTimeError(customer,savedTenant.getId(),
 | 
				
			||||||
                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(validationError + msgError));
 | 
					                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
@ -211,8 +215,6 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
 | 
				
			|||||||
        Assert.assertNotNull(foundCustomer);
 | 
					        Assert.assertNotNull(foundCustomer);
 | 
				
			||||||
        Assert.assertEquals(savedCustomer, foundCustomer);
 | 
					        Assert.assertEquals(savedCustomer, foundCustomer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Mockito.reset(tbClusterService, auditLogService);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        doDelete("/api/customer/" + savedCustomer.getId().getId().toString())
 | 
					        doDelete("/api/customer/" + savedCustomer.getId().getId().toString())
 | 
				
			||||||
                .andExpect(status().isOk());
 | 
					                .andExpect(status().isOk());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -247,8 +249,8 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
 | 
				
			|||||||
                .andExpect(status().isBadRequest())
 | 
					                .andExpect(status().isBadRequest())
 | 
				
			||||||
                .andExpect(statusReason(containsString(msgError)));
 | 
					                .andExpect(statusReason(containsString(msgError)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        testNotifyEntityError(customer, savedTenant.getId(),
 | 
					        testNotifyEntityEqualsOneTimeError(customer,savedTenant.getId(),
 | 
				
			||||||
                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError + "!"));
 | 
					                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
@ -264,16 +266,20 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
 | 
				
			|||||||
                .andExpect(status().isBadRequest())
 | 
					                .andExpect(status().isBadRequest())
 | 
				
			||||||
                .andExpect(statusReason(containsString(msgError)));
 | 
					                .andExpect(statusReason(containsString(msgError)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        testNotifyEntityError(customer, savedTenant.getId(),
 | 
					        testNotifyEntityEqualsOneTimeError(customer, savedTenant.getId(),
 | 
				
			||||||
                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError + "!"));
 | 
					                tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void testFindCustomers() throws Exception {
 | 
					    public void testFindCustomers() throws Exception {
 | 
				
			||||||
        TenantId tenantId = savedTenant.getId();
 | 
					        TenantId tenantId = savedTenant.getId();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        List<ListenableFuture<Customer>> futures = new ArrayList<>(135);
 | 
					        int cntEntity = 135;
 | 
				
			||||||
        for (int i = 0; i < 135; i++) {
 | 
					
 | 
				
			||||||
 | 
					        Mockito.reset(tbClusterService, auditLogService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        List<ListenableFuture<Customer>> futures = new ArrayList<>(cntEntity);
 | 
				
			||||||
 | 
					        for (int i = 0; i < cntEntity; i++) {
 | 
				
			||||||
            Customer customer = new Customer();
 | 
					            Customer customer = new Customer();
 | 
				
			||||||
            customer.setTenantId(tenantId);
 | 
					            customer.setTenantId(tenantId);
 | 
				
			||||||
            customer.setTitle("Customer" + i);
 | 
					            customer.setTitle("Customer" + i);
 | 
				
			||||||
@ -282,6 +288,10 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        List<Customer> customers = Futures.allAsList(futures).get(TIMEOUT, TimeUnit.SECONDS);
 | 
					        List<Customer> customers = Futures.allAsList(futures).get(TIMEOUT, TimeUnit.SECONDS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        testNotifyManyEntityManyTimeMsgToEdgeServiceNever(new Customer(), new Customer(),
 | 
				
			||||||
 | 
					                tenantId, tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(),
 | 
				
			||||||
 | 
					                ActionType.ADDED, cntEntity);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        List<Customer> loadedCustomers = new ArrayList<>(135);
 | 
					        List<Customer> loadedCustomers = new ArrayList<>(135);
 | 
				
			||||||
        PageLink pageLink = new PageLink(23);
 | 
					        PageLink pageLink = new PageLink(23);
 | 
				
			||||||
        PageData<Customer> pageData = null;
 | 
					        PageData<Customer> pageData = null;
 | 
				
			||||||
@ -370,5 +380,4 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
 | 
				
			|||||||
        Assert.assertFalse(pageData.hasNext());
 | 
					        Assert.assertFalse(pageData.hasNext());
 | 
				
			||||||
        Assert.assertEquals(0, pageData.getData().size());
 | 
					        Assert.assertEquals(0, pageData.getData().size());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -49,7 +49,6 @@ import org.thingsboard.server.common.data.device.profile.RepeatingAlarmCondition
 | 
				
			|||||||
import org.thingsboard.server.common.data.id.CustomerId;
 | 
					import org.thingsboard.server.common.data.id.CustomerId;
 | 
				
			||||||
import org.thingsboard.server.common.data.id.DeviceId;
 | 
					import org.thingsboard.server.common.data.id.DeviceId;
 | 
				
			||||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
 | 
					import org.thingsboard.server.common.data.id.DeviceProfileId;
 | 
				
			||||||
import org.thingsboard.server.common.data.id.QueueId;
 | 
					 | 
				
			||||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
					import org.thingsboard.server.common.data.id.TenantId;
 | 
				
			||||||
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
 | 
					import org.thingsboard.server.common.data.kv.AttributeKvEntry;
 | 
				
			||||||
import org.thingsboard.server.common.data.query.BooleanFilterPredicate;
 | 
					import org.thingsboard.server.common.data.query.BooleanFilterPredicate;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user