|
|
|
@ -50,14 +50,15 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
protected void testNotifyEntityAllOneTime(HasName entity, EntityId entityId, EntityId originatorId, |
|
|
|
TenantId tenantId, CustomerId customerId, UserId userId, String userName, |
|
|
|
ActionType actionType, Object... additionalInfo) { |
|
|
|
testSendNotificationMsgToEdgeServiceOneTime(entityId, tenantId, actionType); |
|
|
|
testSendNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, 1); |
|
|
|
testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo); |
|
|
|
testPushMsgToRuleEngineOneTime(originatorId, tenantId); |
|
|
|
testPushMsgToRuleEngineTime(originatorId, tenantId, 1); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
} |
|
|
|
|
|
|
|
protected void testNotifyEntityNeverMsgToEdgeServiceOneTime(HasName entity, EntityId entityId, TenantId tenantId, ActionType actionType) { |
|
|
|
testSendNotificationMsgToEdgeServiceOneTime(entityId, tenantId, actionType); |
|
|
|
protected void testNotifyEntityNeverMsgToEdgeServiceOneTime(HasName entity, EntityId entityId, TenantId tenantId, |
|
|
|
ActionType actionType) { |
|
|
|
testSendNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, 1); |
|
|
|
testLogEntityActionNever(entityId, entity); |
|
|
|
testPushMsgToRuleEngineNever(entityId); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
@ -68,7 +69,19 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
ActionType actionType, Object... additionalInfo) { |
|
|
|
testNotificationMsgToEdgeServiceNever(entityId); |
|
|
|
testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo); |
|
|
|
testPushMsgToRuleEngineOneTime(originatorId, tenantId); |
|
|
|
testPushMsgToRuleEngineTime(originatorId, tenantId, 1); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
} |
|
|
|
|
|
|
|
protected void testNotifyEntityOneManyTimeMsgToEdgeServiceNever(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); |
|
|
|
testLogEntityActionManyTime(entity,originatorId, tenantId, customerId, |
|
|
|
userId, userName, actionType, cntTime, additionalInfo); |
|
|
|
testPushMsgToRuleEngineTime(originatorId, tenantId, cntTime); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
} |
|
|
|
|
|
|
|
@ -77,16 +90,16 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
ActionType actionType, Object... additionalInfo) { |
|
|
|
testNotificationMsgToEdgeServiceNever(entityId); |
|
|
|
testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo); |
|
|
|
testPushMsgToRuleEngineOneTime(originatorId, tenantId); |
|
|
|
testBroadcastEntityStateChangeEventOneTime(entityId, tenantId); |
|
|
|
testPushMsgToRuleEngineTime(originatorId, tenantId, 1); |
|
|
|
testBroadcastEntityStateChangeEventTime(entityId, tenantId, 1); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
} |
|
|
|
|
|
|
|
protected void testNotifyEntityError(HasName entity, TenantId tenantId, |
|
|
|
UserId userId, String userName, ActionType actionType, Exception exp, |
|
|
|
Object... additionalInfo) { |
|
|
|
protected void testNotifyEntityOneTimeError(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 = createEntityId_NULL_UUID (entity); |
|
|
|
EntityId entity_NULL_UUID = createEntityId_NULL_UUID(entity); |
|
|
|
testNotificationMsgToEdgeServiceNever(entity_NULL_UUID); |
|
|
|
if (additionalInfo.length > 0) { |
|
|
|
Mockito.verify(auditLogService, times(1)) |
|
|
|
@ -109,7 +122,7 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
} |
|
|
|
|
|
|
|
protected void testNotifyEntityNever(EntityId entityId, HasName entity) { |
|
|
|
entityId = entityId == null ? createEntityId_NULL_UUID (entity) : entityId; |
|
|
|
entityId = entityId == null ? createEntityId_NULL_UUID(entity) : entityId; |
|
|
|
testNotificationMsgToEdgeServiceNever(entityId); |
|
|
|
testLogEntityActionNever(entityId, entity); |
|
|
|
testPushMsgToRuleEngineNever(entityId); |
|
|
|
@ -146,19 +159,38 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void testPushMsgToRuleEngineOneTime(EntityId originatorId, TenantId tenantId) { |
|
|
|
Mockito.verify(tbClusterService, times(1)).pushMsgToRuleEngine(Mockito.eq(tenantId), |
|
|
|
Mockito.eq(originatorId), Mockito.any(TbMsg.class), Mockito.isNull()); |
|
|
|
private void testLogEntityActionManyTime(HasName entity, EntityId originatorId, TenantId tenantId, CustomerId customerId, |
|
|
|
UserId userId, String userName, ActionType actionType, int cntTime, Object... additionalInfo) { |
|
|
|
if (additionalInfo.length == 0) { |
|
|
|
Mockito.verify(auditLogService, times(cntTime)).logEntityAction(Mockito.eq(tenantId), Mockito.eq(customerId), |
|
|
|
Mockito.eq(userId), Mockito.eq(userName), Mockito.any(originatorId.getClass()), |
|
|
|
Mockito.any(entity.getClass()), Mockito.eq(actionType), Mockito.isNull()); |
|
|
|
} else { |
|
|
|
String additionalInfoStr = extractParameter(String.class, 0, additionalInfo); |
|
|
|
Mockito.verify(auditLogService, times(cntTime)).logEntityAction(Mockito.eq(tenantId), Mockito.eq(customerId), |
|
|
|
Mockito.eq(userId), Mockito.eq(userName), Mockito.any(originatorId.getClass()), |
|
|
|
Mockito.any(entity.getClass()), Mockito.eq(actionType), Mockito.isNull(), Mockito.eq(additionalInfoStr)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void testPushMsgToRuleEngineTime(EntityId originatorId, TenantId tenantId, int cntTime) { |
|
|
|
if (cntTime ==1) { |
|
|
|
Mockito.verify(tbClusterService, times(cntTime)).pushMsgToRuleEngine(Mockito.eq(tenantId), |
|
|
|
Mockito.eq(originatorId), Mockito.any(TbMsg.class), Mockito.isNull()); |
|
|
|
} else { |
|
|
|
Mockito.verify(tbClusterService, times(cntTime)).pushMsgToRuleEngine(Mockito.eq(tenantId), |
|
|
|
Mockito.any(originatorId.getClass()), Mockito.any(TbMsg.class), Mockito.isNull()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void testSendNotificationMsgToEdgeServiceOneTime(EntityId entityId, TenantId tenantId, ActionType actionType) { |
|
|
|
Mockito.verify(tbClusterService, times(1)).sendNotificationMsgToEdgeService(Mockito.eq(tenantId), |
|
|
|
private void testSendNotificationMsgToEdgeServiceTime(EntityId entityId, TenantId tenantId, ActionType actionType, int cntTime) { |
|
|
|
Mockito.verify(tbClusterService, times(cntTime)).sendNotificationMsgToEdgeService(Mockito.eq(tenantId), |
|
|
|
Mockito.isNull(), Mockito.eq(entityId), Mockito.isNull(), Mockito.isNull(), |
|
|
|
Mockito.eq(edgeTypeByActionType(actionType))); |
|
|
|
} |
|
|
|
|
|
|
|
private void testBroadcastEntityStateChangeEventOneTime(EntityId entityId, TenantId tenantId) { |
|
|
|
Mockito.verify(tbClusterService, times(1)).broadcastEntityStateChangeEvent(Mockito.eq(tenantId), |
|
|
|
private void testBroadcastEntityStateChangeEventTime(EntityId entityId, TenantId tenantId, int cntTime) { |
|
|
|
Mockito.verify(tbClusterService, times(cntTime)).broadcastEntityStateChangeEvent(Mockito.eq(tenantId), |
|
|
|
Mockito.any(entityId.getClass()), Mockito.any(ComponentLifecycleEvent.class)); |
|
|
|
} |
|
|
|
|
|
|
|
@ -173,7 +205,7 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private EntityId createEntityId_NULL_UUID (HasName entity) { |
|
|
|
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); |
|
|
|
|