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,
|
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);
|
testSendNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, 1);
|
||||||
testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo);
|
testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo);
|
||||||
testPushMsgToRuleEngineOneTime(originatorId, tenantId);
|
testPushMsgToRuleEngineTime(originatorId, tenantId, 1);
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
Mockito.reset(tbClusterService, auditLogService);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void testNotifyEntityNeverMsgToEdgeServiceOneTime(HasName entity, EntityId entityId, TenantId tenantId, ActionType actionType) {
|
protected void testNotifyEntityNeverMsgToEdgeServiceOneTime(HasName entity, EntityId entityId, TenantId tenantId,
|
||||||
testSendNotificationMsgToEdgeServiceOneTime(entityId, tenantId, actionType);
|
ActionType actionType) {
|
||||||
|
testSendNotificationMsgToEdgeServiceTime(entityId, tenantId, actionType, 1);
|
||||||
testLogEntityActionNever(entityId, entity);
|
testLogEntityActionNever(entityId, entity);
|
||||||
testPushMsgToRuleEngineNever(entityId);
|
testPushMsgToRuleEngineNever(entityId);
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
Mockito.reset(tbClusterService, auditLogService);
|
||||||
@ -68,7 +69,19 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest {
|
|||||||
ActionType actionType, Object... additionalInfo) {
|
ActionType actionType, Object... additionalInfo) {
|
||||||
testNotificationMsgToEdgeServiceNever(entityId);
|
testNotificationMsgToEdgeServiceNever(entityId);
|
||||||
testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo);
|
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);
|
Mockito.reset(tbClusterService, auditLogService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,12 +90,12 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest {
|
|||||||
ActionType actionType, Object... additionalInfo) {
|
ActionType actionType, Object... additionalInfo) {
|
||||||
testNotificationMsgToEdgeServiceNever(entityId);
|
testNotificationMsgToEdgeServiceNever(entityId);
|
||||||
testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo);
|
testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo);
|
||||||
testPushMsgToRuleEngineOneTime(originatorId, tenantId);
|
testPushMsgToRuleEngineTime(originatorId, tenantId, 1);
|
||||||
testBroadcastEntityStateChangeEventOneTime(entityId, tenantId);
|
testBroadcastEntityStateChangeEventTime(entityId, tenantId, 1);
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
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,
|
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);
|
||||||
@ -146,19 +159,38 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testPushMsgToRuleEngineOneTime(EntityId originatorId, TenantId tenantId) {
|
private void testLogEntityActionManyTime(HasName entity, EntityId originatorId, TenantId tenantId, CustomerId customerId,
|
||||||
Mockito.verify(tbClusterService, times(1)).pushMsgToRuleEngine(Mockito.eq(tenantId),
|
UserId userId, String userName, ActionType actionType, int cntTime, Object... additionalInfo) {
|
||||||
Mockito.eq(originatorId), Mockito.any(TbMsg.class), Mockito.isNull());
|
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) {
|
private void testPushMsgToRuleEngineTime(EntityId originatorId, TenantId tenantId, int cntTime) {
|
||||||
Mockito.verify(tbClusterService, times(1)).sendNotificationMsgToEdgeService(Mockito.eq(tenantId),
|
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.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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -128,7 +128,7 @@ 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(),
|
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
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";
|
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(),
|
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
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";
|
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(),
|
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||||
|
|
||||||
customer.setCountry("Ukraine");
|
customer.setCountry("Ukraine");
|
||||||
@ -154,7 +154,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
|||||||
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(),
|
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
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";
|
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(),
|
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||||
|
|
||||||
customer.setState("Normal state");
|
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";
|
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(),
|
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -248,7 +248,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
|||||||
.andExpect(status().isBadRequest())
|
.andExpect(status().isBadRequest())
|
||||||
.andExpect(statusReason(containsString(msgError)));
|
.andExpect(statusReason(containsString(msgError)));
|
||||||
|
|
||||||
testNotifyEntityError(customer, savedTenant.getId(),
|
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,7 +265,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
|||||||
.andExpect(status().isBadRequest())
|
.andExpect(status().isBadRequest())
|
||||||
.andExpect(statusReason(containsString(msgError)));
|
.andExpect(statusReason(containsString(msgError)));
|
||||||
|
|
||||||
testNotifyEntityError(customer, savedTenant.getId(),
|
testNotifyEntityOneTimeError(customer, savedTenant.getId(),
|
||||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,8 +273,9 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
|||||||
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 cntTime = 135;
|
||||||
for (int i = 0; i < 135; i++) {
|
List<ListenableFuture<Customer>> futures = new ArrayList<>(cntTime);
|
||||||
|
for (int i = 0; i < cntTime; i++) {
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
customer.setTenantId(tenantId);
|
customer.setTenantId(tenantId);
|
||||||
customer.setTitle("Customer" + i);
|
customer.setTitle("Customer" + i);
|
||||||
@ -283,6 +284,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);
|
||||||
|
|
||||||
|
testNotifyEntityOneManyTimeMsgToEdgeServiceNever(new Customer(), new Customer(),
|
||||||
|
tenantId, tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(),
|
||||||
|
ActionType.ADDED, cntTime);
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user