Browse Source

refactoring: customer tests error -> different type exception

pull/6731/head
nickAS21 4 years ago
parent
commit
feb957e261
  1. 39
      application/src/test/java/org/thingsboard/server/controller/AbstractNotifyEntityTest.java
  2. 20
      application/src/test/java/org/thingsboard/server/controller/BaseCustomerControllerTest.java

39
application/src/test/java/org/thingsboard/server/controller/AbstractNotifyEntityTest.java

@ -56,15 +56,6 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest {
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);
} }
protected void testNotifyEntityDeleteOneTimeMsgToEdgeServiceNever(HasName entity, EntityId entityId, EntityId originatorId,
TenantId tenantId, CustomerId customerId, UserId userId, String userName,
ActionType actionType, Object... additionalInfo) {
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) { protected void testNotifyEntityNeverMsgToEdgeServiceOneTime(HasName entity, EntityId entityId, TenantId tenantId, ActionType actionType) {
testSendNotificationMsgToEdgeServiceOneTime(entityId, tenantId, actionType); testSendNotificationMsgToEdgeServiceOneTime(entityId, tenantId, actionType);
testLogEntityActionNever(entityId, entity); testLogEntityActionNever(entityId, entity);
@ -95,25 +86,31 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest {
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_NULL_UUID = EntityIdFactory.getByTypeAndUuid(
EntityType
.valueOf(entity.getClass()
.toString()
.substring(entity.getClass().toString().lastIndexOf(".") + 1).toUpperCase(Locale.ENGLISH)), .substring(entity.getClass().toString().lastIndexOf(".") + 1).toUpperCase(Locale.ENGLISH)),
ModelConstants.NULL_UUID); ModelConstants.NULL_UUID);
testNotificationMsgToEdgeServiceNever(entity_NULL_UUID); testNotificationMsgToEdgeServiceNever(entity_NULL_UUID);
if (additionalInfo.length > 0) { if (additionalInfo.length > 0) {
Mockito.verify(auditLogService, times(1)).logEntityAction(Mockito.eq(tenantId), Mockito.verify(auditLogService, times(1))
Mockito.eq(customer_NULL_UUID), Mockito.eq(userId), Mockito.eq(userName), .logEntityAction(Mockito.eq(tenantId),
Mockito.eq(entity_NULL_UUID), Mockito.any(entity.getClass()), Mockito.eq(actionType), Mockito.eq(customer_NULL_UUID), Mockito.eq(userId), Mockito.eq(userName),
Mockito.argThat(argument -> Mockito.eq(entity_NULL_UUID), Mockito.any(entity.getClass()), Mockito.eq(actionType),
argument.getMessage().equals(exp.getMessage())), Mockito.eq(additionalInfo)); Mockito.argThat(argument ->
argument.getMessage().contains(exp.getMessage())),
Mockito.eq(additionalInfo)
);
} else { } else {
Mockito.verify(auditLogService, times(1)).logEntityAction(Mockito.eq(tenantId), Mockito.verify(auditLogService, times(1))
Mockito.eq(customer_NULL_UUID), Mockito.eq(userId), Mockito.eq(userName), .logEntityAction(Mockito.eq(tenantId),
Mockito.eq(entity_NULL_UUID), Mockito.any(entity.getClass()), Mockito.eq(actionType), Mockito.eq(customer_NULL_UUID), Mockito.eq(userId), Mockito.eq(userName),
Mockito.argThat(argument -> Mockito.eq(entity_NULL_UUID), Mockito.any(entity.getClass()), Mockito.eq(actionType),
argument.getMessage().equals(exp.getMessage()))); Mockito.argThat((argument -> argument.getMessage().contains(exp.getMessage()) & argument.getClass().equals(exp.getClass())))
);
} }
testPushMsgToRuleEngineNever(entity_NULL_UUID); testPushMsgToRuleEngineNever(entity_NULL_UUID);
Mockito.reset(tbClusterService, auditLogService);
} }
protected void testNotifyEntityNever(EntityId entityId, HasName entity) { protected void testNotifyEntityNever(EntityId entityId, HasName entity) {

20
application/src/test/java/org/thingsboard/server/controller/BaseCustomerControllerTest.java

@ -121,7 +121,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,7 +129,8 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError))); doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
testNotifyEntityError(customer, savedTenant.getId(), testNotifyEntityError(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.setTitle("Normal title"); customer.setTitle("Normal title");
customer.setCity(RandomStringUtils.randomAlphabetic(300)); customer.setCity(RandomStringUtils.randomAlphabetic(300));
@ -138,7 +138,8 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError))); doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
testNotifyEntityError(customer, savedTenant.getId(), testNotifyEntityError(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));
@ -146,7 +147,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError))); doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
testNotifyEntityError(customer, savedTenant.getId(), testNotifyEntityError(customer, savedTenant.getId(),
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(validationError + msgError)); tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
customer.setCountry("Ukraine"); customer.setCountry("Ukraine");
customer.setPhone(RandomStringUtils.randomAlphabetic(300)); customer.setPhone(RandomStringUtils.randomAlphabetic(300));
@ -154,7 +155,8 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError))); doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
testNotifyEntityError(customer, savedTenant.getId(), testNotifyEntityError(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));
@ -162,7 +164,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError))); doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
testNotifyEntityError(customer, savedTenant.getId(), testNotifyEntityError(customer, savedTenant.getId(),
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(validationError + msgError)); tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
customer.setState("Normal state"); customer.setState("Normal state");
customer.setZip(RandomStringUtils.randomAlphabetic(300)); customer.setZip(RandomStringUtils.randomAlphabetic(300));
@ -170,7 +172,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError))); doPost("/api/customer", customer).andExpect(statusReason(containsString(msgError)));
testNotifyEntityError(customer, savedTenant.getId(), testNotifyEntityError(customer, savedTenant.getId(),
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(validationError + msgError)); tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
} }
@ -247,7 +249,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
.andExpect(statusReason(containsString(msgError))); .andExpect(statusReason(containsString(msgError)));
testNotifyEntityError(customer, savedTenant.getId(), testNotifyEntityError(customer, savedTenant.getId(),
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError + "!")); tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
} }
@Test @Test
@ -264,7 +266,7 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
.andExpect(statusReason(containsString(msgError))); .andExpect(statusReason(containsString(msgError)));
testNotifyEntityError(customer, savedTenant.getId(), testNotifyEntityError(customer, savedTenant.getId(),
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError + "!")); tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
} }
@Test @Test

Loading…
Cancel
Save