Browse Source

refactoring: commit1

pull/6695/head
nickAS21 4 years ago
parent
commit
6d2d876d64
  1. 4
      application/src/test/java/org/thingsboard/server/controller/AbstractNotifyEntityTest.java
  2. 75
      application/src/test/java/org/thingsboard/server/controller/BaseAlarmControllerTest.java
  3. 105
      application/src/test/java/org/thingsboard/server/controller/BaseCustomerControllerTest.java

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

@ -56,7 +56,6 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest {
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);
} }
protected void testNotifyEntityDeleteOneMsgToEdgeServiceNever(HasName entity, EntityId entityId, EntityId originatorId, protected void testNotifyEntityDeleteOneMsgToEdgeServiceNever(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) {
@ -64,7 +63,6 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest {
testLogEntityActionOne(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo); testLogEntityActionOne(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo);
testPushMsgToRuleEngineOne(entityId, tenantId); testPushMsgToRuleEngineOne(entityId, tenantId);
testBroadcastEntityStateChangeEventOne(entityId, tenantId); testBroadcastEntityStateChangeEventOne(entityId, tenantId);
} }
protected void testNotifyEntityOneMsgToEdgeServiceNever(HasName entity, EntityId entityId, EntityId originatorId, protected void testNotifyEntityOneMsgToEdgeServiceNever(HasName entity, EntityId entityId, EntityId originatorId,
@ -172,6 +170,4 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest {
} }
return result; return result;
} }
} }

75
application/src/test/java/org/thingsboard/server/controller/BaseAlarmControllerTest.java

@ -87,12 +87,9 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
public void testUpdateAlarmViaCustomer() throws Exception { public void testUpdateAlarmViaCustomer() throws Exception {
loginCustomerUser(); loginCustomerUser();
Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE); Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(), Mockito.reset(tbClusterService, auditLogService);
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ADDED);
alarm.setSeverity(AlarmSeverity.MAJOR); alarm.setSeverity(AlarmSeverity.MAJOR);
Alarm updatedAlarm = doPost("/api/alarm", alarm, Alarm.class); Alarm updatedAlarm = doPost("/api/alarm", alarm, Alarm.class);
@ -108,12 +105,9 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
public void testUpdateAlarmViaTenant() throws Exception { public void testUpdateAlarmViaTenant() throws Exception {
loginTenantAdmin(); loginTenantAdmin();
Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE); Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(), Mockito.reset(tbClusterService, auditLogService);
tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.ADDED);
alarm.setSeverity(AlarmSeverity.MAJOR); alarm.setSeverity(AlarmSeverity.MAJOR);
Alarm updatedAlarm = doPost("/api/alarm", alarm, Alarm.class); Alarm updatedAlarm = doPost("/api/alarm", alarm, Alarm.class);
@ -129,13 +123,8 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
public void testUpdateAlarmViaDifferentTenant() throws Exception { public void testUpdateAlarmViaDifferentTenant() throws Exception {
loginTenantAdmin(); loginTenantAdmin();
Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE); Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(),
tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.ADDED);
alarm.setSeverity(AlarmSeverity.MAJOR); alarm.setSeverity(AlarmSeverity.MAJOR);
loginDifferentTenant(); loginDifferentTenant();
@ -151,13 +140,8 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
public void testUpdateAlarmViaDifferentCustomer() throws Exception { public void testUpdateAlarmViaDifferentCustomer() throws Exception {
loginCustomerUser(); loginCustomerUser();
Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE); Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(),
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ADDED);
loginDifferentCustomer(); loginDifferentCustomer();
alarm.setSeverity(AlarmSeverity.MAJOR); alarm.setSeverity(AlarmSeverity.MAJOR);
@ -173,12 +157,9 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
public void testDeleteAlarmViaCustomer() throws Exception { public void testDeleteAlarmViaCustomer() throws Exception {
loginCustomerUser(); loginCustomerUser();
Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE); Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(), Mockito.reset(tbClusterService, auditLogService);
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ADDED);
doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isOk()); doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isOk());
@ -191,12 +172,9 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
public void testDeleteAlarmViaTenant() throws Exception { public void testDeleteAlarmViaTenant() throws Exception {
loginTenantAdmin(); loginTenantAdmin();
Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE); Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(), Mockito.reset(tbClusterService, auditLogService);
tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.ADDED);
doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isOk()); doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isOk());
@ -209,13 +187,8 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
public void testDeleteAlarmViaDifferentTenant() throws Exception { public void testDeleteAlarmViaDifferentTenant() throws Exception {
loginTenantAdmin(); loginTenantAdmin();
Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE); Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(),
tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.ADDED);
loginDifferentTenant(); loginDifferentTenant();
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);
@ -231,13 +204,8 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
public void testDeleteAlarmViaAnotherCustomer() throws Exception { public void testDeleteAlarmViaAnotherCustomer() throws Exception {
loginCustomerUser(); loginCustomerUser();
Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE); Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(),
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ADDED);
loginDifferentCustomer(); loginDifferentCustomer();
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);
@ -253,12 +221,9 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
public void testClearAlarmViaCustomer() throws Exception { public void testClearAlarmViaCustomer() throws Exception {
loginCustomerUser(); loginCustomerUser();
Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE); Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(), Mockito.reset(tbClusterService, auditLogService);
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ADDED);
doPost("/api/alarm/" + alarm.getId() + "/clear").andExpect(status().isOk()); doPost("/api/alarm/" + alarm.getId() + "/clear").andExpect(status().isOk());
@ -275,13 +240,8 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
public void testClearAlarmViaTenant() throws Exception { public void testClearAlarmViaTenant() throws Exception {
loginTenantAdmin(); loginTenantAdmin();
Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE); Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(),
tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.ADDED);
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);
doPost("/api/alarm/" + alarm.getId() + "/clear").andExpect(status().isOk()); doPost("/api/alarm/" + alarm.getId() + "/clear").andExpect(status().isOk());
@ -298,12 +258,9 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
public void testAcknowledgeAlarmViaCustomer() throws Exception { public void testAcknowledgeAlarmViaCustomer() throws Exception {
loginCustomerUser(); loginCustomerUser();
Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE); Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(), Mockito.reset(tbClusterService, auditLogService);
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ADDED);
doPost("/api/alarm/" + alarm.getId() + "/ack").andExpect(status().isOk()); doPost("/api/alarm/" + alarm.getId() + "/ack").andExpect(status().isOk());
@ -320,13 +277,8 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
public void testClearAlarmViaDifferentCustomer() throws Exception { public void testClearAlarmViaDifferentCustomer() throws Exception {
loginCustomerUser(); loginCustomerUser();
Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE); Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(),
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ADDED);
loginDifferentCustomer(); loginDifferentCustomer();
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);
@ -341,13 +293,8 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
public void testClearAlarmViaDifferentTenant() throws Exception { public void testClearAlarmViaDifferentTenant() throws Exception {
loginTenantAdmin(); loginTenantAdmin();
Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE); Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(),
tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.ADDED);
loginDifferentTenant(); loginDifferentTenant();
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);
@ -362,13 +309,8 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
public void testAcknowledgeAlarmViaDifferentCustomer() throws Exception { public void testAcknowledgeAlarmViaDifferentCustomer() throws Exception {
loginCustomerUser(); loginCustomerUser();
Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE); Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(),
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ADDED);
loginDifferentCustomer(); loginDifferentCustomer();
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);
@ -383,13 +325,8 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
public void testAcknowledgeAlarmViaDifferentTenant() throws Exception { public void testAcknowledgeAlarmViaDifferentTenant() throws Exception {
loginTenantAdmin(); loginTenantAdmin();
Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE); Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(),
tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.ADDED);
loginDifferentTenant(); loginDifferentTenant();
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);

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

@ -93,14 +93,16 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);
Customer savedCustomer = doPost("/api/customer", customer, Customer.class); Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
testNotifyEntityOneMsgToEdgeServiceNever(savedCustomer, savedCustomer.getId(), savedCustomer.getId(),
savedCustomer.getTenantId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(),
ActionType.ADDED);
Assert.assertNotNull(savedCustomer); Assert.assertNotNull(savedCustomer);
Assert.assertNotNull(savedCustomer.getId()); Assert.assertNotNull(savedCustomer.getId());
Assert.assertTrue(savedCustomer.getCreatedTime() > 0); Assert.assertTrue(savedCustomer.getCreatedTime() > 0);
Assert.assertEquals(customer.getTitle(), savedCustomer.getTitle()); Assert.assertEquals(customer.getTitle(), savedCustomer.getTitle());
testNotifyEntityOneMsgToEdgeServiceNever(savedCustomer, savedCustomer.getId(), savedCustomer.getId(),
savedCustomer.getTenantId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(),
tenantAdmin.getEmail(), ActionType.ADDED);
savedCustomer.setTitle("My new customer"); savedCustomer.setTitle("My new customer");
@ -108,8 +110,9 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
doPost("/api/customer", savedCustomer, Customer.class); doPost("/api/customer", savedCustomer, Customer.class);
testNotifyEntityOne(savedCustomer, savedCustomer.getId(), savedCustomer.getId(), testNotifyEntityOne(savedCustomer, savedCustomer.getId(), savedCustomer.getId(), savedCustomer.getTenantId(),
savedCustomer.getTenantId(), savedCustomer.getId(), tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.UPDATED); savedCustomer.getId(), tenantAdmin.getId(), tenantAdmin.getEmail(),
ActionType.UPDATED);
Customer foundCustomer = doGet("/api/customer/" + savedCustomer.getId().getId().toString(), Customer.class); Customer foundCustomer = doGet("/api/customer/" + savedCustomer.getId().getId().toString(), Customer.class);
Assert.assertEquals(foundCustomer.getTitle(), savedCustomer.getTitle()); Assert.assertEquals(foundCustomer.getTitle(), savedCustomer.getTitle());
@ -117,89 +120,65 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
doDelete("/api/customer/" + savedCustomer.getId().getId().toString()) doDelete("/api/customer/" + savedCustomer.getId().getId().toString())
.andExpect(status().isOk()); .andExpect(status().isOk());
testNotifyEntityBroadcastEntityStateChangeEventOneMsgToEdgeServiceNever(savedCustomer, savedCustomer.getId(), savedCustomer.getId(), testNotifyEntityBroadcastEntityStateChangeEventOneMsgToEdgeServiceNever(savedCustomer, savedCustomer.getId(),
savedCustomer.getTenantId(), savedCustomer.getId(), tenantAdmin.getId(), tenantAdmin.getEmail(), savedCustomer.getId(), savedCustomer.getTenantId(), savedCustomer.getId(), tenantAdmin.getId(),
ActionType.DELETED, savedCustomer.getId().getId().toString()); tenantAdmin.getEmail(), ActionType.DELETED, savedCustomer.getId().getId().toString());
} }
@Test @Test
public void testSaveCustomerWithViolationOfValidation() throws Exception { public void testSaveCustomerWithViolationOfValidation() throws Exception {
Customer customer = new Customer(); Customer customer = new Customer();
customer.setTitle(RandomStringUtils.randomAlphabetic(300));
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);
doPost("/api/customer", customer)
.andExpect(status().isBadRequest())
.andExpect(statusReason(containsString("Customer title should be specified")));
testNotifyEntityError(customer, savedTenant.getId(),
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException("Test: empty title"));
customer.setTitle(RandomStringUtils.randomAlphabetic(300));
doPost("/api/customer", customer).andExpect(statusReason(containsString("length of title must be equal or less than 255"))); doPost("/api/customer", customer).andExpect(statusReason(containsString("length of title must be equal or less than 255")));
testNotifyEntityError(customer, savedTenant.getId(), testNotifyEntityError(customer, savedTenant.getId(),
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException("Test: bad title")); tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(""));
customer.setTitle("Normal title"); customer.setTitle("Normal title");
customer.setEmail("invalid@mail");
doPost("/api/customer", customer)
.andExpect(status().isBadRequest())
.andExpect(statusReason(containsString("Invalid email address format 'invalid@mail'")));
testNotifyEntityError(customer, savedTenant.getId(),
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException("Test: invalid email"));
customer.setEmail("normal@mail.com.ua");
customer.setCity(RandomStringUtils.randomAlphabetic(300)); customer.setCity(RandomStringUtils.randomAlphabetic(300));
doPost("/api/customer", customer).andExpect(statusReason(containsString("length of city must be equal or less than 255"))); doPost("/api/customer", customer).andExpect(statusReason(containsString("length of city must be equal or less than 255")));
testNotifyEntityError(customer, savedTenant.getId(), testNotifyEntityError(customer, savedTenant.getId(),
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException("Test: bad City")); tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(""));
customer.setCity("Normal city"); customer.setCity("Normal city");
customer.setCountry(RandomStringUtils.randomAlphabetic(300)); customer.setCountry(RandomStringUtils.randomAlphabetic(300));
doPost("/api/customer", customer).andExpect(statusReason(containsString("length of country must be equal or less than 255"))); doPost("/api/customer", customer).andExpect(statusReason(containsString("length of country must be equal or less than 255")));
testNotifyEntityError(customer, savedTenant.getId(), testNotifyEntityError(customer, savedTenant.getId(),
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException("Test: bad Country")); tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(""));
customer.setCountry("Ukraine"); customer.setCountry("Ukraine");
customer.setPhone(RandomStringUtils.randomAlphabetic(300)); customer.setPhone(RandomStringUtils.randomAlphabetic(300));
doPost("/api/customer", customer).andExpect(statusReason(containsString("length of phone must be equal or less than 255"))); doPost("/api/customer", customer).andExpect(statusReason(containsString("length of phone must be equal or less than 255")));
testNotifyEntityError(customer, savedTenant.getId(), testNotifyEntityError(customer, savedTenant.getId(),
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException("Test: bad Phone")); tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(""));
customer.setPhone("+3892555554512"); customer.setPhone("+3892555554512");
customer.setState(RandomStringUtils.randomAlphabetic(300)); customer.setState(RandomStringUtils.randomAlphabetic(300));
doPost("/api/customer", customer).andExpect(statusReason(containsString("length of state must be equal or less than 255"))); doPost("/api/customer", customer).andExpect(statusReason(containsString("length of state must be equal or less than 255")));
testNotifyEntityError(customer, savedTenant.getId(), testNotifyEntityError(customer, savedTenant.getId(),
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException("Test: bad state")); tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(""));
customer.setState("Normal state"); customer.setState("Normal state");
customer.setZip(RandomStringUtils.randomAlphabetic(300)); customer.setZip(RandomStringUtils.randomAlphabetic(300));
doPost("/api/customer", customer).andExpect(statusReason(containsString("length of zip or postal code must be equal or less than 255"))); doPost("/api/customer", customer).andExpect(statusReason(containsString("length of zip or postal code must be equal or less than 255")));
testNotifyEntityError(customer, savedTenant.getId(), testNotifyEntityError(customer, savedTenant.getId(),
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException("Test: bad Zip")); tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(""));
} }
@Test @Test
public void testUpdateCustomerFromDifferentTenant() throws Exception { public void testUpdateCustomerFromDifferentTenant() throws Exception {
Customer customer = new Customer(); Customer customer = new Customer();
customer.setTitle("My customer"); customer.setTitle("My customer");
Mockito.reset(tbClusterService, auditLogService);
Customer savedCustomer = doPost("/api/customer", customer, Customer.class); Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
testNotifyEntityOneMsgToEdgeServiceNever(savedCustomer, savedCustomer.getId(), savedCustomer.getId(),
savedCustomer.getTenantId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED);
doPost("/api/customer", savedCustomer, Customer.class); doPost("/api/customer", savedCustomer, Customer.class);
loginDifferentTenant(); loginDifferentTenant();
@ -211,7 +190,6 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
testNotifyEntityNever(savedCustomer.getId(), savedCustomer); testNotifyEntityNever(savedCustomer.getId(), savedCustomer);
deleteDifferentTenant(); deleteDifferentTenant();
login(tenantAdmin.getName(), "testPassword1"); login(tenantAdmin.getName(), "testPassword1");
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);
@ -228,25 +206,20 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
public void testFindCustomerById() throws Exception { public void testFindCustomerById() throws Exception {
Customer customer = new Customer(); Customer customer = new Customer();
customer.setTitle("My customer"); customer.setTitle("My customer");
Mockito.reset(tbClusterService, auditLogService);
Customer savedCustomer = doPost("/api/customer", customer, Customer.class); Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
testNotifyEntityOneMsgToEdgeServiceNever(savedCustomer, savedCustomer.getId(), savedCustomer.getId(),
savedCustomer.getTenantId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(),
tenantAdmin.getEmail(), ActionType.ADDED);
Customer foundCustomer = doGet("/api/customer/" + savedCustomer.getId().getId().toString(), Customer.class); Customer foundCustomer = doGet("/api/customer/" + savedCustomer.getId().getId().toString(), Customer.class);
Assert.assertNotNull(foundCustomer); Assert.assertNotNull(foundCustomer);
Assert.assertEquals(savedCustomer, foundCustomer); Assert.assertEquals(savedCustomer, foundCustomer);
Mockito.reset(tbClusterService, auditLogService);
doDelete("/api/customer/" + savedCustomer.getId().getId().toString()) doDelete("/api/customer/" + savedCustomer.getId().getId().toString())
.andExpect(status().isOk()); .andExpect(status().isOk());
testNotifyEntityBroadcastEntityStateChangeEventOneMsgToEdgeServiceNever(savedCustomer, savedCustomer.getId(), savedCustomer.getId(), testNotifyEntityBroadcastEntityStateChangeEventOneMsgToEdgeServiceNever(savedCustomer, savedCustomer.getId(),
savedCustomer.getTenantId(), savedCustomer.getId(), tenantAdmin.getId(), tenantAdmin.getEmail(), savedCustomer.getId(), savedCustomer.getTenantId(), savedCustomer.getId(), tenantAdmin.getId(),
ActionType.DELETED, savedCustomer.getId().getId().toString()); tenantAdmin.getEmail(), ActionType.DELETED, savedCustomer.getId().getId().toString());
} }
@Test @Test
@ -260,14 +233,38 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
doDelete("/api/customer/" + savedCustomer.getId().getId().toString()) doDelete("/api/customer/" + savedCustomer.getId().getId().toString())
.andExpect(status().isOk()); .andExpect(status().isOk());
testNotifyEntityBroadcastEntityStateChangeEventOneMsgToEdgeServiceNever(savedCustomer, savedCustomer.getId(), savedCustomer.getId(), testNotifyEntityBroadcastEntityStateChangeEventOneMsgToEdgeServiceNever(savedCustomer, savedCustomer.getId(),
savedCustomer.getTenantId(), savedCustomer.getId(), tenantAdmin.getId(), tenantAdmin.getEmail(), savedCustomer.getId(), savedCustomer.getTenantId(), savedCustomer.getId(), tenantAdmin.getId(),
ActionType.DELETED, savedCustomer.getId().getId().toString()); tenantAdmin.getEmail(), ActionType.DELETED, savedCustomer.getId().getId().toString());
doGet("/api/customer/" + savedCustomer.getId().getId().toString()) doGet("/api/customer/" + savedCustomer.getId().getId().toString())
.andExpect(status().isNotFound()); .andExpect(status().isNotFound());
} }
@Test
public void testSaveCustomerWithEmptyTitle() throws Exception {
Customer customer = new Customer();
doPost("/api/customer", customer)
.andExpect(status().isBadRequest())
.andExpect(statusReason(containsString("Customer title should be specified")));
}
@Test
public void testSaveCustomerWithInvalidEmail() throws Exception {
Customer customer = new Customer();
customer.setTitle("My customer");
customer.setEmail("invalid@mail");
Mockito.reset(tbClusterService, auditLogService);
doPost("/api/customer", customer)
.andExpect(status().isBadRequest())
.andExpect(statusReason(containsString("Invalid email address format 'invalid@mail'")));
testNotifyEntityError(customer, savedTenant.getId(),
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(""));
}
@Test @Test
public void testFindCustomers() throws Exception { public void testFindCustomers() throws Exception {
TenantId tenantId = savedTenant.getId(); TenantId tenantId = savedTenant.getId();

Loading…
Cancel
Save