|
|
|
@ -63,13 +63,14 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
|
|
|
|
protected final String msgErrorPermission = "You don't have permission to perform this operation!"; |
|
|
|
protected final String msgErrorShouldBeSpecified = "should be specified"; |
|
|
|
protected final String msgErrorNotFound = "Requested item wasn't found!"; |
|
|
|
|
|
|
|
|
|
|
|
protected void testNotifyEntityAllOneTime(HasName entity, EntityId entityId, EntityId originatorId, |
|
|
|
TenantId tenantId, CustomerId customerId, UserId userId, String userName, |
|
|
|
ActionType actionType, Object... additionalInfo) { |
|
|
|
int cntTime = 1; |
|
|
|
testSendNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, cntTime); |
|
|
|
testNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, cntTime); |
|
|
|
testLogEntityAction(entity, originatorId, tenantId, customerId, userId, userName, actionType, cntTime, additionalInfo); |
|
|
|
ArgumentMatcher<EntityId> matcherOriginatorId = argument -> argument.equals(originatorId); |
|
|
|
testPushMsgToRuleEngineTime(matcherOriginatorId, tenantId, cntTime); |
|
|
|
@ -85,25 +86,33 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
Mockito.eq(edgeTypeByActionType(actionType))); |
|
|
|
ArgumentMatcher<EntityId> matcherOriginatorId = argument -> argument.equals(relation.getTo()); |
|
|
|
ArgumentMatcher<HasName> matcherEntityClassEquals = Objects::isNull; |
|
|
|
testLogEntityActionAdditionalInfo(matcherEntityClassEquals, matcherOriginatorId, tenantId, customerId, userId, userName, actionType, cntTime, |
|
|
|
ArgumentMatcher<CustomerId> matcherCustomerId = customerId == null ? |
|
|
|
argument -> argument.getClass().equals(CustomerId.class) : argument -> argument.equals(customerId); |
|
|
|
ArgumentMatcher<UserId> matcherUserId = userId == null ? |
|
|
|
argument -> argument.getClass().equals(UserId.class) : argument -> argument.equals(userId); |
|
|
|
testLogEntityActionAdditionalInfo(matcherEntityClassEquals, matcherOriginatorId, tenantId, matcherCustomerId, matcherUserId, userName, actionType, cntTime, |
|
|
|
extractMatcherAdditionalInfo(additionalInfo)); |
|
|
|
testPushMsgToRuleEngineNever(relation.getTo()); |
|
|
|
matcherOriginatorId = argument -> argument.equals(relation.getFrom()); |
|
|
|
testLogEntityActionAdditionalInfo(matcherEntityClassEquals, matcherOriginatorId, tenantId, customerId, userId, userName, actionType, cntTime, |
|
|
|
testLogEntityActionAdditionalInfo(matcherEntityClassEquals, matcherOriginatorId, tenantId, matcherCustomerId, matcherUserId, userName, actionType, cntTime, |
|
|
|
extractMatcherAdditionalInfo(additionalInfo)); |
|
|
|
testPushMsgToRuleEngineNever(relation.getFrom()); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
} |
|
|
|
|
|
|
|
protected void testNotifyEntityAllManyRelation(EntityRelation relation, |
|
|
|
TenantId tenantId, CustomerId customerId, UserId userId, String userName, |
|
|
|
ActionType actionType, int cntTime) { |
|
|
|
TenantId tenantId, CustomerId customerId, UserId userId, String userName, |
|
|
|
ActionType actionType, int cntTime) { |
|
|
|
Mockito.verify(tbClusterService, times(cntTime)).sendNotificationMsgToEdge(Mockito.eq(tenantId), |
|
|
|
Mockito.isNull(), Mockito.isNull(), Mockito.any(), Mockito.eq(EdgeEventType.RELATION), |
|
|
|
Mockito.eq(edgeTypeByActionType(actionType))); |
|
|
|
ArgumentMatcher<EntityId> matcherOriginatorId = argument -> argument.getClass().equals(relation.getFrom().getClass()); |
|
|
|
ArgumentMatcher<HasName> matcherEntityClassEquals = Objects::isNull; |
|
|
|
testLogEntityActionAdditionalInfoAny(matcherEntityClassEquals, matcherOriginatorId, tenantId, customerId, userId, |
|
|
|
ArgumentMatcher<CustomerId> matcherCustomerId = customerId == null ? |
|
|
|
argument -> argument.getClass().equals(CustomerId.class) : argument -> argument.equals(customerId); |
|
|
|
ArgumentMatcher<UserId> matcherUserId = userId == null ? |
|
|
|
argument -> argument.getClass().equals(UserId.class) : argument -> argument.equals(userId); |
|
|
|
testLogEntityActionAdditionalInfoAny(matcherEntityClassEquals, matcherOriginatorId, tenantId, matcherCustomerId, matcherUserId, |
|
|
|
userName, actionType, cntTime * 2, 1); |
|
|
|
testPushMsgToRuleEngineTime(matcherOriginatorId, tenantId, cntTime); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
@ -113,7 +122,7 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
TenantId tenantId, CustomerId customerId, UserId userId, String userName, |
|
|
|
ActionType actionType, Object... additionalInfo) { |
|
|
|
int cntTime = 1; |
|
|
|
testSendNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, cntTime); |
|
|
|
testNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, cntTime); |
|
|
|
testLogEntityActionEntityEqClass(entity, originatorId, tenantId, customerId, userId, userName, actionType, cntTime, additionalInfo); |
|
|
|
ArgumentMatcher<EntityId> matcherOriginatorId = argument -> argument.equals(originatorId); |
|
|
|
testPushMsgToRuleEngineTime(matcherOriginatorId, tenantId, cntTime); |
|
|
|
@ -122,7 +131,7 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
|
|
|
|
protected void testNotifyEntityNeverMsgToEdgeServiceOneTime(HasName entity, EntityId entityId, TenantId tenantId, |
|
|
|
ActionType actionType) { |
|
|
|
testSendNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, 1); |
|
|
|
testNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, 1); |
|
|
|
testLogEntityActionNever(entityId, entity); |
|
|
|
testPushMsgToRuleEngineNever(entityId); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
@ -132,7 +141,7 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
TenantId tenantId, CustomerId customerId, UserId userId, |
|
|
|
String userName, ActionType actionType, Object... additionalInfo) { |
|
|
|
int cntTime = 1; |
|
|
|
testNotificationMsgToEdgeServiceNever(entityId); |
|
|
|
testNotificationMsgToEdgeServiceNeverWithActionType(entityId, actionType); |
|
|
|
testLogEntityAction(entity, originatorId, tenantId, customerId, userId, userName, actionType, cntTime, additionalInfo); |
|
|
|
ArgumentMatcher<EntityId> matcherOriginatorId = argument -> argument.equals(originatorId); |
|
|
|
if (ActionType.RELATIONS_DELETED.equals(actionType)) { |
|
|
|
@ -148,10 +157,14 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
ActionType actionType, int cntTime, Object... additionalInfo) { |
|
|
|
EntityId entityId = createEntityId_NULL_UUID(entity); |
|
|
|
EntityId originatorId = createEntityId_NULL_UUID(originator); |
|
|
|
testNotificationMsgToEdgeServiceNever(entityId); |
|
|
|
testNotificationMsgToEdgeServiceNeverWithActionType(entityId, actionType); |
|
|
|
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, |
|
|
|
ArgumentMatcher<CustomerId> matcherCustomerId = customerId == null ? |
|
|
|
argument -> argument.getClass().equals(CustomerId.class) : argument -> argument.equals(customerId); |
|
|
|
ArgumentMatcher<UserId> matcherUserId = userId == null ? |
|
|
|
argument -> argument.getClass().equals(UserId.class) : argument -> argument.equals(userId); |
|
|
|
testLogEntityActionAdditionalInfo(matcherEntityClassEquals, matcherOriginatorId, tenantId, matcherCustomerId, matcherUserId, userName, actionType, cntTime, |
|
|
|
extractMatcherAdditionalInfo(additionalInfo)); |
|
|
|
testPushMsgToRuleEngineTime(matcherOriginatorId, tenantId, cntTime); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
@ -165,10 +178,13 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
testSendNotificationMsgToEdgeServiceTimeEntityEqAny(tenantId, actionTypeEdge, cntTimeEdge); |
|
|
|
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, |
|
|
|
ArgumentMatcher<CustomerId> matcherCustomerId = customerId == null ? |
|
|
|
argument -> argument.getClass().equals(CustomerId.class) : argument -> argument.equals(customerId); |
|
|
|
ArgumentMatcher<UserId> matcherUserId = userId == null ? |
|
|
|
argument -> argument.getClass().equals(UserId.class) : argument -> argument.equals(userId); |
|
|
|
testLogEntityActionAdditionalInfo(matcherEntityClassEquals, matcherOriginatorId, tenantId, matcherCustomerId, matcherUserId, userName, actionType, cntTime, |
|
|
|
extractMatcherAdditionalInfoClass(additionalInfo)); |
|
|
|
testPushMsgToRuleEngineTime(matcherOriginatorId, tenantId, cntTimeRuleEngine); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
} |
|
|
|
|
|
|
|
protected void testNotifyManyEntityManyTimeMsgToEdgeServiceEntityEqAnyAdditionalInfoAny(HasName entity, HasName originator, |
|
|
|
@ -178,7 +194,11 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
testSendNotificationMsgToEdgeServiceTimeEntityEqAny(tenantId, actionTypeEdge, cntTimeEdge); |
|
|
|
ArgumentMatcher<HasName> matcherEntityClassEquals = argument -> argument.getClass().equals(entity.getClass()); |
|
|
|
ArgumentMatcher<EntityId> matcherOriginatorId = argument -> argument.getClass().equals(originatorId.getClass()); |
|
|
|
testLogEntityActionAdditionalInfoAny(matcherEntityClassEquals, matcherOriginatorId, tenantId, customerId, userId, userName, actionType, cntTime, |
|
|
|
ArgumentMatcher<CustomerId> matcherCustomerId = customerId == null ? |
|
|
|
argument -> argument.getClass().equals(CustomerId.class) : argument -> argument.equals(customerId); |
|
|
|
ArgumentMatcher<UserId> matcherUserId = userId == null ? |
|
|
|
argument -> argument.getClass().equals(UserId.class) : argument -> argument.equals(userId); |
|
|
|
testLogEntityActionAdditionalInfoAny(matcherEntityClassEquals, matcherOriginatorId, tenantId, matcherCustomerId, matcherUserId, userName, actionType, cntTime, |
|
|
|
cntAdditionalInfo); |
|
|
|
testPushMsgToRuleEngineTime(matcherOriginatorId, tenantId, cntTimeEdge); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
@ -189,10 +209,14 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
ActionType actionType, int cntTime, int cntAdditionalInfo) { |
|
|
|
EntityId entityId = createEntityId_NULL_UUID(entity); |
|
|
|
EntityId originatorId = createEntityId_NULL_UUID(originator); |
|
|
|
testNotificationMsgToEdgeServiceNever(entityId); |
|
|
|
testNotificationMsgToEdgeServiceNeverWithActionType(entityId, actionType); |
|
|
|
ArgumentMatcher<HasName> matcherEntityClassEquals = argument -> argument.getClass().equals(entity.getClass()); |
|
|
|
ArgumentMatcher<EntityId> matcherOriginatorId = argument -> argument.getClass().equals(originatorId.getClass()); |
|
|
|
testLogEntityActionAdditionalInfoAny(matcherEntityClassEquals, matcherOriginatorId, tenantId, customerId, userId, userName, actionType, cntTime, |
|
|
|
ArgumentMatcher<CustomerId> matcherCustomerId = customerId == null ? |
|
|
|
argument -> argument.getClass().equals(CustomerId.class) : argument -> argument.equals(customerId); |
|
|
|
ArgumentMatcher<UserId> matcherUserId = userId == null ? |
|
|
|
argument -> argument.getClass().equals(UserId.class) : argument -> argument.equals(userId); |
|
|
|
testLogEntityActionAdditionalInfoAny(matcherEntityClassEquals, matcherOriginatorId, tenantId, matcherCustomerId, matcherUserId, userName, actionType, cntTime, |
|
|
|
cntAdditionalInfo); |
|
|
|
testPushMsgToRuleEngineTime(matcherOriginatorId, tenantId, cntTime); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
@ -202,7 +226,7 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
TenantId tenantId, CustomerId customerId, UserId userId, String userName, |
|
|
|
ActionType actionType, Object... additionalInfo) { |
|
|
|
int cntTime = 1; |
|
|
|
testSendNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, cntTime); |
|
|
|
testNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, cntTime); |
|
|
|
testLogEntityAction(entity, originatorId, tenantId, customerId, userId, userName, actionType, cntTime, additionalInfo); |
|
|
|
ArgumentMatcher<EntityId> matcherOriginatorId = argument -> argument.equals(originatorId); |
|
|
|
testPushMsgToRuleEngineTime(matcherOriginatorId, tenantId, cntTime); |
|
|
|
@ -214,7 +238,7 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
TenantId tenantId, CustomerId customerId, UserId userId, String userName, |
|
|
|
ActionType actionType, Object... additionalInfo) { |
|
|
|
int cntTime = 1; |
|
|
|
testNotificationMsgToEdgeServiceNever(entityId); |
|
|
|
testNotificationMsgToEdgeServiceNeverWithActionType(entityId, actionType); |
|
|
|
testLogEntityAction(entity, originatorId, tenantId, customerId, userId, userName, actionType, cntTime, additionalInfo); |
|
|
|
ArgumentMatcher<EntityId> matcherOriginatorId = argument -> argument.equals(originatorId); |
|
|
|
testPushMsgToRuleEngineTime(matcherOriginatorId, tenantId, cntTime); |
|
|
|
@ -222,26 +246,32 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
} |
|
|
|
|
|
|
|
protected void testNotifyEntityBroadcastEntityStateChangeEventManyMsgToEdgeServiceNever(HasName entity, HasName originator, |
|
|
|
TenantId tenantId, CustomerId customerId, UserId userId, String userName, |
|
|
|
ActionType actionType, int cntTime, int cntAdditionalInfo) { |
|
|
|
protected void testNotifyEntityBroadcastEntityStateChangeEventMany(HasName entity, HasName originator, |
|
|
|
TenantId tenantId, CustomerId customerId, |
|
|
|
UserId userId, String userName, ActionType actionType, |
|
|
|
ActionType actionTypeEdge, |
|
|
|
int cntTime, int cntTimeEdge, int cntTimeRuleEngine, |
|
|
|
int cntAdditionalInfo) { |
|
|
|
EntityId entityId = createEntityId_NULL_UUID(entity); |
|
|
|
EntityId originatorId = createEntityId_NULL_UUID(originator); |
|
|
|
testNotificationMsgToEdgeServiceNever(entityId); |
|
|
|
testNotificationMsgToEdgeServiceTime(entityId, tenantId, actionTypeEdge, cntTimeEdge); |
|
|
|
ArgumentMatcher<HasName> matcherEntityClassEquals = argument -> argument.getClass().equals(entity.getClass()); |
|
|
|
ArgumentMatcher<EntityId> matcherOriginatorId = argument -> argument.getClass().equals(originatorId.getClass()); |
|
|
|
testLogEntityActionAdditionalInfoAny(matcherEntityClassEquals, matcherOriginatorId, tenantId, customerId, userId, userName, actionType, cntTime, |
|
|
|
ArgumentMatcher<CustomerId> matcherCustomerId = customerId == null ? |
|
|
|
argument -> argument.getClass().equals(CustomerId.class) : argument -> argument.equals(customerId); |
|
|
|
ArgumentMatcher<UserId> matcherUserId = userId == null ? |
|
|
|
argument -> argument.getClass().equals(UserId.class) : argument -> argument.equals(userId); |
|
|
|
testLogEntityActionAdditionalInfoAny(matcherEntityClassEquals, matcherOriginatorId, tenantId, matcherCustomerId, matcherUserId, userName, actionType, cntTime, |
|
|
|
cntAdditionalInfo); |
|
|
|
testPushMsgToRuleEngineTime(matcherOriginatorId, tenantId, cntTime); |
|
|
|
testPushMsgToRuleEngineTime(matcherOriginatorId, tenantId, cntTimeRuleEngine); |
|
|
|
testBroadcastEntityStateChangeEventTime(entityId, tenantId, cntTime); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
} |
|
|
|
|
|
|
|
protected void testNotifyEntityMsgToEdgePushMsgToCoreOneTime(HasName entity, EntityId entityId, EntityId originatorId, |
|
|
|
TenantId tenantId, CustomerId customerId, UserId userId, String userName, |
|
|
|
ActionType actionType, Object... additionalInfo) { |
|
|
|
int cntTime = 1; |
|
|
|
testSendNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, cntTime); |
|
|
|
testNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, cntTime); |
|
|
|
testLogEntityAction(entity, originatorId, tenantId, customerId, userId, userName, actionType, cntTime, additionalInfo); |
|
|
|
tesPushMsgToCoreTime(cntTime); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
@ -252,7 +282,7 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
Object... additionalInfo) { |
|
|
|
CustomerId customer_NULL_UUID = (CustomerId) EntityIdFactory.getByTypeAndUuid(EntityType.CUSTOMER, ModelConstants.NULL_UUID); |
|
|
|
EntityId entity_originator_NULL_UUID = createEntityId_NULL_UUID(entity); |
|
|
|
testNotificationMsgToEdgeServiceNever(entity_originator_NULL_UUID); |
|
|
|
testNotificationMsgToEdgeServiceNeverWithActionType(entity_originator_NULL_UUID, actionType); |
|
|
|
ArgumentMatcher<HasName> matcherEntityEquals = argument -> argument.getClass().equals(entity.getClass()); |
|
|
|
ArgumentMatcher<Exception> matcherError = argument -> argument.getMessage().contains(exp.getMessage()) |
|
|
|
& argument.getClass().equals(exp.getClass()); |
|
|
|
@ -266,7 +296,7 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
Object... additionalInfo) { |
|
|
|
CustomerId customer_NULL_UUID = (CustomerId) EntityIdFactory.getByTypeAndUuid(EntityType.CUSTOMER, ModelConstants.NULL_UUID); |
|
|
|
EntityId entity_originator_NULL_UUID = createEntityId_NULL_UUID(entity); |
|
|
|
testNotificationMsgToEdgeServiceNever(entity_originator_NULL_UUID); |
|
|
|
testNotificationMsgToEdgeServiceNeverWithActionType(entity_originator_NULL_UUID, actionType); |
|
|
|
ArgumentMatcher<HasName> matcherEntityIsNull = Objects::isNull; |
|
|
|
ArgumentMatcher<Exception> matcherError = argument -> argument.getMessage().contains(exp.getMessage()) & |
|
|
|
argument.getClass().equals(exp.getClass()); |
|
|
|
@ -299,6 +329,13 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
Mockito.verify(gatewayNotificationsService, never()).onDeviceDeleted(Mockito.any(Device.class)); |
|
|
|
} |
|
|
|
|
|
|
|
private void testNotificationMsgToEdgeServiceNeverWithActionType(EntityId entityId, ActionType actionType) { |
|
|
|
EdgeEventActionType edgeEventActionType = ActionType.CREDENTIALS_UPDATED.equals(actionType) ? |
|
|
|
EdgeEventActionType.CREDENTIALS_UPDATED : edgeTypeByActionType(actionType); |
|
|
|
Mockito.verify(tbClusterService, never()).sendNotificationMsgToEdge(Mockito.any(), |
|
|
|
Mockito.any(), Mockito.any(entityId.getClass()), Mockito.any(), Mockito.any(), Mockito.eq(edgeEventActionType)); |
|
|
|
} |
|
|
|
|
|
|
|
private void testNotificationMsgToEdgeServiceNever(EntityId entityId) { |
|
|
|
Mockito.verify(tbClusterService, never()).sendNotificationMsgToEdge(Mockito.any(), |
|
|
|
Mockito.any(), Mockito.any(entityId.getClass()), Mockito.any(), Mockito.any(), Mockito.any()); |
|
|
|
@ -317,16 +354,23 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
Mockito.any(entityId.getClass()), Mockito.any(), Mockito.any()); |
|
|
|
} |
|
|
|
|
|
|
|
protected void testBroadcastEntityStateChangeEventNever(EntityId entityId) { |
|
|
|
Mockito.verify(tbClusterService, never()).broadcastEntityStateChangeEvent(Mockito.any(), |
|
|
|
Mockito.any(entityId.getClass()), Mockito.any(ComponentLifecycleEvent.class)); |
|
|
|
} |
|
|
|
|
|
|
|
private void testPushMsgToRuleEngineTime(ArgumentMatcher<EntityId> matcherOriginatorId, TenantId tenantId, int cntTime) { |
|
|
|
Mockito.verify(tbClusterService, times(cntTime)).pushMsgToRuleEngine(Mockito.eq(tenantId), |
|
|
|
Mockito.argThat(matcherOriginatorId), Mockito.any(TbMsg.class), Mockito.isNull()); |
|
|
|
} |
|
|
|
|
|
|
|
private void testSendNotificationMsgToEdgeServiceTime(EntityId entityId, TenantId tenantId, ActionType actionType, int cntTime) { |
|
|
|
private void testNotificationMsgToEdgeServiceTime(EntityId entityId, TenantId tenantId, ActionType actionType, int cntTime) { |
|
|
|
EdgeEventActionType edgeEventActionType = ActionType.CREDENTIALS_UPDATED.equals(actionType) ? |
|
|
|
EdgeEventActionType.CREDENTIALS_UPDATED : edgeTypeByActionType(actionType); |
|
|
|
ArgumentMatcher<EntityId> matcherEntityId = cntTime == 1 ? argument -> argument.equals(entityId) : |
|
|
|
argument -> argument.getClass().equals(entityId.getClass()); |
|
|
|
Mockito.verify(tbClusterService, times(cntTime)).sendNotificationMsgToEdge(Mockito.eq(tenantId), |
|
|
|
Mockito.any(), Mockito.eq(entityId), Mockito.any(), Mockito.isNull(), |
|
|
|
Mockito.any(), Mockito.argThat(matcherEntityId), Mockito.any(), Mockito.isNull(), |
|
|
|
Mockito.eq(edgeEventActionType)); |
|
|
|
} |
|
|
|
|
|
|
|
@ -336,8 +380,10 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
Mockito.eq(edgeTypeByActionType(actionType))); |
|
|
|
} |
|
|
|
|
|
|
|
private void testBroadcastEntityStateChangeEventTime(EntityId entityId, TenantId tenantId, int cntTime) { |
|
|
|
Mockito.verify(tbClusterService, times(cntTime)).broadcastEntityStateChangeEvent(Mockito.eq(tenantId), |
|
|
|
protected void testBroadcastEntityStateChangeEventTime(EntityId entityId, TenantId tenantId, int cntTime) { |
|
|
|
ArgumentMatcher<TenantId> matcherTenantIdId = cntTime == 1 ? argument -> argument.equals(tenantId) : |
|
|
|
argument -> argument.getClass().equals(TenantId.class); |
|
|
|
Mockito.verify(tbClusterService, times(cntTime)).broadcastEntityStateChangeEvent(Mockito.argThat(matcherTenantIdId), |
|
|
|
Mockito.any(entityId.getClass()), Mockito.any(ComponentLifecycleEvent.class)); |
|
|
|
} |
|
|
|
|
|
|
|
@ -348,9 +394,13 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
private void testLogEntityAction(HasName entity, EntityId originatorId, TenantId tenantId, |
|
|
|
CustomerId customerId, UserId userId, String userName, |
|
|
|
ActionType actionType, int cntTime, Object... additionalInfo) { |
|
|
|
ArgumentMatcher<HasName> matcherEntityEquals = entity == null ? Objects::isNull : argument -> argument.equals(entity); |
|
|
|
ArgumentMatcher<HasName> matcherEntityEquals = entity == null ? Objects::isNull : argument -> argument.toString().equals(entity.toString()); |
|
|
|
ArgumentMatcher<EntityId> matcherOriginatorId = argument -> argument.equals(originatorId); |
|
|
|
testLogEntityActionAdditionalInfo(matcherEntityEquals, matcherOriginatorId, tenantId, customerId, userId, userName, |
|
|
|
ArgumentMatcher<CustomerId> matcherCustomerId = customerId == null ? |
|
|
|
argument -> argument.getClass().equals(CustomerId.class) : argument -> argument.equals(customerId); |
|
|
|
ArgumentMatcher<UserId> matcherUserId = userId == null ? |
|
|
|
argument -> argument.getClass().equals(UserId.class) : argument -> argument.equals(userId); |
|
|
|
testLogEntityActionAdditionalInfo(matcherEntityEquals, matcherOriginatorId, tenantId, matcherCustomerId, matcherUserId, userName, |
|
|
|
actionType, cntTime, extractMatcherAdditionalInfo(additionalInfo)); |
|
|
|
} |
|
|
|
|
|
|
|
@ -359,19 +409,24 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
ActionType actionType, int cntTime, Object... additionalInfo) { |
|
|
|
ArgumentMatcher<HasName> matcherEntityEquals = argument -> argument.getClass().equals(entity.getClass()); |
|
|
|
ArgumentMatcher<EntityId> matcherOriginatorId = argument -> argument.equals(originatorId); |
|
|
|
testLogEntityActionAdditionalInfo(matcherEntityEquals, matcherOriginatorId, tenantId, customerId, userId, userName, |
|
|
|
ArgumentMatcher<CustomerId> matcherCustomerId = customerId == null ? |
|
|
|
argument -> argument.getClass().equals(CustomerId.class) : argument -> argument.equals(customerId); |
|
|
|
ArgumentMatcher<UserId> matcherUserId = userId == null ? |
|
|
|
argument -> argument.getClass().equals(UserId.class) : argument -> argument.equals(userId); |
|
|
|
testLogEntityActionAdditionalInfo(matcherEntityEquals, matcherOriginatorId, tenantId, matcherCustomerId, matcherUserId, userName, |
|
|
|
actionType, cntTime, extractMatcherAdditionalInfo(additionalInfo)); |
|
|
|
} |
|
|
|
|
|
|
|
private void testLogEntityActionAdditionalInfo(ArgumentMatcher<HasName> matcherEntity, ArgumentMatcher<EntityId> matcherOriginatorId, |
|
|
|
TenantId tenantId, CustomerId customerId, UserId userId, String userName, |
|
|
|
ActionType actionType, int cntTime, List<ArgumentMatcher<Object>> matcherAdditionalInfos) { |
|
|
|
TenantId tenantId, ArgumentMatcher<CustomerId> matcherCustomerId, |
|
|
|
ArgumentMatcher<UserId> matcherUserId, String userName, ActionType actionType, |
|
|
|
int cntTime, List<ArgumentMatcher<Object>> matcherAdditionalInfos) { |
|
|
|
switch (matcherAdditionalInfos.size()) { |
|
|
|
case 1: |
|
|
|
Mockito.verify(auditLogService, times(cntTime)) |
|
|
|
.logEntityAction(Mockito.eq(tenantId), |
|
|
|
Mockito.eq(customerId), |
|
|
|
Mockito.eq(userId), |
|
|
|
Mockito.argThat(matcherCustomerId), |
|
|
|
Mockito.argThat(matcherUserId), |
|
|
|
Mockito.eq(userName), |
|
|
|
Mockito.argThat(matcherOriginatorId), |
|
|
|
Mockito.argThat(matcherEntity), |
|
|
|
@ -382,8 +437,8 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
case 2: |
|
|
|
Mockito.verify(auditLogService, times(cntTime)) |
|
|
|
.logEntityAction(Mockito.eq(tenantId), |
|
|
|
Mockito.eq(customerId), |
|
|
|
Mockito.eq(userId), |
|
|
|
Mockito.argThat(matcherCustomerId), |
|
|
|
Mockito.argThat(matcherUserId), |
|
|
|
Mockito.eq(userName), |
|
|
|
Mockito.argThat(matcherOriginatorId), |
|
|
|
Mockito.argThat(matcherEntity), |
|
|
|
@ -395,8 +450,8 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
case 3: |
|
|
|
Mockito.verify(auditLogService, times(cntTime)) |
|
|
|
.logEntityAction(Mockito.eq(tenantId), |
|
|
|
Mockito.eq(customerId), |
|
|
|
Mockito.eq(userId), |
|
|
|
Mockito.argThat(matcherCustomerId), |
|
|
|
Mockito.argThat(matcherUserId), |
|
|
|
Mockito.eq(userName), |
|
|
|
Mockito.argThat(matcherOriginatorId), |
|
|
|
Mockito.argThat(matcherEntity), |
|
|
|
@ -409,8 +464,8 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
default: |
|
|
|
Mockito.verify(auditLogService, times(cntTime)) |
|
|
|
.logEntityAction(Mockito.eq(tenantId), |
|
|
|
Mockito.eq(customerId), |
|
|
|
Mockito.eq(userId), |
|
|
|
Mockito.argThat(matcherCustomerId), |
|
|
|
Mockito.argThat(matcherUserId), |
|
|
|
Mockito.eq(userName), |
|
|
|
Mockito.argThat(matcherOriginatorId), |
|
|
|
Mockito.argThat(matcherEntity), |
|
|
|
@ -420,14 +475,15 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
} |
|
|
|
|
|
|
|
private void testLogEntityActionAdditionalInfoAny(ArgumentMatcher<HasName> matcherEntity, ArgumentMatcher<EntityId> matcherOriginatorId, |
|
|
|
TenantId tenantId, CustomerId customerId, UserId userId, String userName, |
|
|
|
TenantId tenantId, ArgumentMatcher<CustomerId> matcherCustomerId, |
|
|
|
ArgumentMatcher<UserId> matcherUserId, String userName, |
|
|
|
ActionType actionType, int cntTime, int cntAdditionalInfo) { |
|
|
|
switch (cntAdditionalInfo) { |
|
|
|
case 1: |
|
|
|
Mockito.verify(auditLogService, times(cntTime)) |
|
|
|
.logEntityAction(Mockito.eq(tenantId), |
|
|
|
Mockito.eq(customerId), |
|
|
|
Mockito.eq(userId), |
|
|
|
Mockito.argThat(matcherCustomerId), |
|
|
|
Mockito.argThat(matcherUserId), |
|
|
|
Mockito.eq(userName), |
|
|
|
Mockito.argThat(matcherOriginatorId), |
|
|
|
Mockito.argThat(matcherEntity), |
|
|
|
@ -438,8 +494,8 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
case 2: |
|
|
|
Mockito.verify(auditLogService, times(cntTime)) |
|
|
|
.logEntityAction(Mockito.eq(tenantId), |
|
|
|
Mockito.eq(customerId), |
|
|
|
Mockito.eq(userId), |
|
|
|
Mockito.argThat(matcherCustomerId), |
|
|
|
Mockito.argThat(matcherUserId), |
|
|
|
Mockito.eq(userName), |
|
|
|
Mockito.argThat(matcherOriginatorId), |
|
|
|
Mockito.argThat(matcherEntity), |
|
|
|
@ -451,8 +507,8 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
case 3: |
|
|
|
Mockito.verify(auditLogService, times(cntTime)) |
|
|
|
.logEntityAction(Mockito.eq(tenantId), |
|
|
|
Mockito.eq(customerId), |
|
|
|
Mockito.eq(userId), |
|
|
|
Mockito.argThat(matcherCustomerId), |
|
|
|
Mockito.argThat(matcherUserId), |
|
|
|
Mockito.eq(userName), |
|
|
|
Mockito.argThat(matcherOriginatorId), |
|
|
|
Mockito.argThat(matcherEntity), |
|
|
|
@ -465,8 +521,8 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
default: |
|
|
|
Mockito.verify(auditLogService, times(cntTime)) |
|
|
|
.logEntityAction(Mockito.eq(tenantId), |
|
|
|
Mockito.eq(customerId), |
|
|
|
Mockito.eq(userId), |
|
|
|
Mockito.argThat(matcherCustomerId), |
|
|
|
Mockito.argThat(matcherUserId), |
|
|
|
Mockito.eq(userName), |
|
|
|
Mockito.argThat(matcherOriginatorId), |
|
|
|
Mockito.argThat(matcherEntity), |
|
|
|
@ -558,7 +614,7 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private EntityId createEntityId_NULL_UUID(HasName entity) { |
|
|
|
protected EntityId createEntityId_NULL_UUID(HasName entity) { |
|
|
|
return EntityIdFactory.getByTypeAndUuid(entityClassToEntityTypeName(entity), ModelConstants.NULL_UUID); |
|
|
|
} |
|
|
|
|
|
|
|
@ -571,6 +627,12 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
|
|
|
} |
|
|
|
|
|
|
|
private String entityClassToEntityTypeName(HasName entity) { |
|
|
|
String entityType = entityClassToString(entity); |
|
|
|
return "SAVE_OTA_PACKAGE_INFO_REQUEST".equals(entityType) || "OTA_PACKAGE_INFO".equals(entityType)? |
|
|
|
EntityType.OTA_PACKAGE.name().toUpperCase(Locale.ENGLISH) : entityType; |
|
|
|
} |
|
|
|
|
|
|
|
private String entityClassToString(HasName entity) { |
|
|
|
String className = entity.getClass().toString() |
|
|
|
.substring(entity.getClass().toString().lastIndexOf(".") + 1); |
|
|
|
List str = className.chars() |
|
|
|
|