refactoring: add method manyTime
This commit is contained in:
parent
1df23e2a9a
commit
f2695138ff
@ -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,
|
||||
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 testSendNotificationMsgToEdgeServiceOneTime(EntityId entityId, TenantId tenantId, ActionType actionType) {
|
||||
Mockito.verify(tbClusterService, times(1)).sendNotificationMsgToEdgeService(Mockito.eq(tenantId),
|
||||
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 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);
|
||||
|
||||
@ -128,7 +128,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
||||
String msgError = "length of title must be equal or less than 255";
|
||||
doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
|
||||
|
||||
testNotifyEntityError(customer, savedTenant.getId(),
|
||||
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
@ -137,7 +137,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
||||
msgError = "length of city must be equal or less than 255";
|
||||
doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
|
||||
|
||||
testNotifyEntityError(customer, savedTenant.getId(),
|
||||
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
@ -146,7 +146,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
||||
msgError = "length of country must be equal or less than 255";
|
||||
doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
|
||||
|
||||
testNotifyEntityError(customer, savedTenant.getId(),
|
||||
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||
|
||||
customer.setCountry("Ukraine");
|
||||
@ -154,7 +154,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
||||
msgError = "length of phone must be equal or less than 255";
|
||||
doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
|
||||
|
||||
testNotifyEntityError(customer, savedTenant.getId(),
|
||||
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||
Mockito.reset(tbClusterService, auditLogService);
|
||||
|
||||
@ -163,7 +163,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
||||
msgError = "length of state must be equal or less than 255";
|
||||
doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
|
||||
|
||||
testNotifyEntityError(customer, savedTenant.getId(),
|
||||
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||
|
||||
customer.setState("Normal state");
|
||||
@ -171,7 +171,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
||||
msgError = "length of zip or postal code must be equal or less than 255";
|
||||
doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
|
||||
|
||||
testNotifyEntityError(customer, savedTenant.getId(),
|
||||
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||
|
||||
}
|
||||
@ -248,7 +248,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(statusReason(containsString(msgError)));
|
||||
|
||||
testNotifyEntityError(customer, savedTenant.getId(),
|
||||
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||
}
|
||||
|
||||
@ -265,7 +265,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(statusReason(containsString(msgError)));
|
||||
|
||||
testNotifyEntityError(customer, savedTenant.getId(),
|
||||
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||
}
|
||||
|
||||
@ -273,8 +273,9 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
||||
public void testFindCustomers() throws Exception {
|
||||
TenantId tenantId = savedTenant.getId();
|
||||
|
||||
List<ListenableFuture<Customer>> futures = new ArrayList<>(135);
|
||||
for (int i = 0; i < 135; i++) {
|
||||
int cntTime = 135;
|
||||
List<ListenableFuture<Customer>> futures = new ArrayList<>(cntTime);
|
||||
for (int i = 0; i < cntTime; i++) {
|
||||
Customer customer = new Customer();
|
||||
customer.setTenantId(tenantId);
|
||||
customer.setTitle("Customer" + i);
|
||||
@ -283,6 +284,10 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
||||
}
|
||||
List<Customer> customers = Futures.allAsList(futures).get(TIMEOUT, TimeUnit.SECONDS);
|
||||
|
||||
testNotifyEntityOneManyTimeMsgToEdgeServiceNever(new Customer(), new Customer(),
|
||||
tenantId, tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(),
|
||||
ActionType.ADDED, cntTime);
|
||||
|
||||
List<Customer> loadedCustomers = new ArrayList<>(135);
|
||||
PageLink pageLink = new PageLink(23);
|
||||
PageData<Customer> pageData = null;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user