refactoring: alarm - add Mockito to create

This commit is contained in:
nickAS21 2022-06-14 12:03:05 +03:00
parent 258417346f
commit eab4e333a9

View File

@ -128,8 +128,14 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
@Test @Test
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();
@ -144,8 +150,14 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
@Test @Test
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);
@ -160,10 +172,14 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
@Test @Test
public void testDeleteAlarmViaCustomer() throws Exception { public void testDeleteAlarmViaCustomer() throws Exception {
loginCustomerUser(); loginCustomerUser();
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(),
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ADDED);
doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isOk()); doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isOk());
testNotifyEntityOneMsgToEdgeServiceNever(alarm, alarm.getId(), alarm.getOriginator(), testNotifyEntityOneMsgToEdgeServiceNever(alarm, alarm.getId(), alarm.getOriginator(),
@ -174,10 +190,14 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
@Test @Test
public void testDeleteAlarmViaTenant() throws Exception { public void testDeleteAlarmViaTenant() throws Exception {
loginTenantAdmin(); loginTenantAdmin();
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(),
tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.ADDED);
doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isOk()); doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isOk());
testNotifyEntityOneMsgToEdgeServiceNever(alarm, alarm.getId(), alarm.getOriginator(), testNotifyEntityOneMsgToEdgeServiceNever(alarm, alarm.getId(), alarm.getOriginator(),
@ -188,8 +208,14 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
@Test @Test
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);
@ -204,7 +230,14 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
@Test @Test
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);
@ -219,10 +252,14 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
@Test @Test
public void testClearAlarmViaCustomer() throws Exception { public void testClearAlarmViaCustomer() throws Exception {
loginCustomerUser(); loginCustomerUser();
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(),
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());
Alarm foundAlarm = doGet("/api/alarm/" + alarm.getId(), Alarm.class); Alarm foundAlarm = doGet("/api/alarm/" + alarm.getId(), Alarm.class);
@ -237,8 +274,14 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
@Test @Test
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());
@ -254,10 +297,14 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
@Test @Test
public void testAcknowledgeAlarmViaCustomer() throws Exception { public void testAcknowledgeAlarmViaCustomer() throws Exception {
loginCustomerUser(); loginCustomerUser();
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
Mockito.reset(tbClusterService, auditLogService); Mockito.reset(tbClusterService, auditLogService);
Alarm alarm = createAlarm(TEST_ALARM_TYPE);
testNotifyEntityOne(alarm, alarm.getId(), alarm.getOriginator(),
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());
Alarm foundAlarm = doGet("/api/alarm/" + alarm.getId(), Alarm.class); Alarm foundAlarm = doGet("/api/alarm/" + alarm.getId(), Alarm.class);
@ -272,7 +319,14 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
@Test @Test
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);
@ -286,7 +340,14 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
@Test @Test
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);
@ -300,7 +361,14 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
@Test @Test
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);
@ -314,7 +382,14 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
@Test @Test
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);