|
|
|
@ -15,6 +15,7 @@ |
|
|
|
*/ |
|
|
|
package org.thingsboard.server.controller; |
|
|
|
|
|
|
|
import org.junit.After; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
@ -27,6 +28,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. |
|
|
|
|
|
|
|
public abstract class BaseAlarmControllerTest extends AbstractControllerTest { |
|
|
|
|
|
|
|
public static final String TEST_ALARM_TYPE = "Test"; |
|
|
|
|
|
|
|
protected Device customerDevice; |
|
|
|
|
|
|
|
@Before |
|
|
|
@ -44,17 +47,30 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest { |
|
|
|
logout(); |
|
|
|
} |
|
|
|
|
|
|
|
@After |
|
|
|
public void teardown() throws Exception { |
|
|
|
loginSysAdmin(); |
|
|
|
deleteDifferentTenant(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testCreateAlarm() throws Exception { |
|
|
|
public void testCreateAlarmViaCustomer() throws Exception { |
|
|
|
loginCustomerUser(); |
|
|
|
createAlarm(); |
|
|
|
createAlarm(TEST_ALARM_TYPE); |
|
|
|
logout(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testCreateAlarmViaTenant() throws Exception { |
|
|
|
loginTenantAdmin(); |
|
|
|
createAlarm(TEST_ALARM_TYPE); |
|
|
|
logout(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testUpdateAlarm() throws Exception { |
|
|
|
public void testUpdateAlarmViaCustomer() throws Exception { |
|
|
|
loginCustomerUser(); |
|
|
|
Alarm alarm = createAlarm(); |
|
|
|
Alarm alarm = createAlarm(TEST_ALARM_TYPE); |
|
|
|
alarm.setSeverity(AlarmSeverity.MAJOR); |
|
|
|
Alarm updatedAlarm = doPost("/api/alarm", alarm, Alarm.class); |
|
|
|
Assert.assertNotNull(updatedAlarm); |
|
|
|
@ -63,9 +79,30 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest { |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testUpdateAlarmViaAnotherCustomer() throws Exception { |
|
|
|
public void testUpdateAlarmViaTenant() throws Exception { |
|
|
|
loginTenantAdmin(); |
|
|
|
Alarm alarm = createAlarm(TEST_ALARM_TYPE); |
|
|
|
alarm.setSeverity(AlarmSeverity.MAJOR); |
|
|
|
Alarm updatedAlarm = doPost("/api/alarm", alarm, Alarm.class); |
|
|
|
Assert.assertNotNull(updatedAlarm); |
|
|
|
Assert.assertEquals(AlarmSeverity.MAJOR, updatedAlarm.getSeverity()); |
|
|
|
logout(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testUpdateAlarmViaDifferentTenant() throws Exception { |
|
|
|
loginTenantAdmin(); |
|
|
|
Alarm alarm = createAlarm(TEST_ALARM_TYPE); |
|
|
|
alarm.setSeverity(AlarmSeverity.MAJOR); |
|
|
|
loginDifferentTenant(); |
|
|
|
doPost("/api/alarm", alarm).andExpect(status().isForbidden()); |
|
|
|
logout(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testUpdateAlarmViaDifferentCustomer() throws Exception { |
|
|
|
loginCustomerUser(); |
|
|
|
Alarm alarm = createAlarm(); |
|
|
|
Alarm alarm = createAlarm(TEST_ALARM_TYPE); |
|
|
|
loginDifferentCustomer(); |
|
|
|
alarm.setSeverity(AlarmSeverity.MAJOR); |
|
|
|
doPost("/api/alarm", alarm).andExpect(status().isForbidden()); |
|
|
|
@ -73,27 +110,43 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest { |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDeleteAlarm() throws Exception { |
|
|
|
public void testDeleteAlarmViaCustomer() throws Exception { |
|
|
|
loginCustomerUser(); |
|
|
|
Alarm alarm = createAlarm(); |
|
|
|
Alarm alarm = createAlarm(TEST_ALARM_TYPE); |
|
|
|
doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isOk()); |
|
|
|
logout(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDeleteAlarmViaTenant() throws Exception { |
|
|
|
loginTenantAdmin(); |
|
|
|
Alarm alarm = createAlarm(TEST_ALARM_TYPE); |
|
|
|
doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isOk()); |
|
|
|
logout(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDeleteAlarmVieAnotherCustomer() throws Exception { |
|
|
|
public void testDeleteAlarmViaDifferentTenant() throws Exception { |
|
|
|
loginTenantAdmin(); |
|
|
|
Alarm alarm = createAlarm(TEST_ALARM_TYPE); |
|
|
|
loginDifferentTenant(); |
|
|
|
doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isForbidden()); |
|
|
|
logout(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDeleteAlarmViaAnotherCustomer() throws Exception { |
|
|
|
loginCustomerUser(); |
|
|
|
Alarm alarm = createAlarm(); |
|
|
|
Alarm alarm = createAlarm(TEST_ALARM_TYPE); |
|
|
|
loginDifferentCustomer(); |
|
|
|
alarm.setSeverity(AlarmSeverity.MAJOR); |
|
|
|
doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isForbidden()); |
|
|
|
logout(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testClearAlarm() throws Exception { |
|
|
|
public void testClearAlarmViaCustomer() throws Exception { |
|
|
|
loginCustomerUser(); |
|
|
|
Alarm alarm = createAlarm(); |
|
|
|
Alarm alarm = createAlarm(TEST_ALARM_TYPE); |
|
|
|
doPost("/api/alarm/" + alarm.getId() + "/clear").andExpect(status().isOk()); |
|
|
|
Alarm foundAlarm = doGet("/api/alarm/" + alarm.getId(), Alarm.class); |
|
|
|
Assert.assertNotNull(foundAlarm); |
|
|
|
@ -102,9 +155,20 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest { |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testAcknowledgeAlarm() throws Exception { |
|
|
|
public void testClearAlarmViaTenant() throws Exception { |
|
|
|
loginTenantAdmin(); |
|
|
|
Alarm alarm = createAlarm(TEST_ALARM_TYPE); |
|
|
|
doPost("/api/alarm/" + alarm.getId() + "/clear").andExpect(status().isOk()); |
|
|
|
Alarm foundAlarm = doGet("/api/alarm/" + alarm.getId(), Alarm.class); |
|
|
|
Assert.assertNotNull(foundAlarm); |
|
|
|
Assert.assertEquals(AlarmStatus.CLEARED_UNACK, foundAlarm.getStatus()); |
|
|
|
logout(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testAcknowledgeAlarmViaCustomer() throws Exception { |
|
|
|
loginCustomerUser(); |
|
|
|
Alarm alarm = createAlarm(); |
|
|
|
Alarm alarm = createAlarm(TEST_ALARM_TYPE); |
|
|
|
doPost("/api/alarm/" + alarm.getId() + "/ack").andExpect(status().isOk()); |
|
|
|
Alarm foundAlarm = doGet("/api/alarm/" + alarm.getId(), Alarm.class); |
|
|
|
Assert.assertNotNull(foundAlarm); |
|
|
|
@ -113,31 +177,49 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest { |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testClearAlarmViaAnotherCustomer() throws Exception { |
|
|
|
public void testClearAlarmViaDifferentCustomer() throws Exception { |
|
|
|
loginCustomerUser(); |
|
|
|
Alarm alarm = createAlarm(); |
|
|
|
Alarm alarm = createAlarm(TEST_ALARM_TYPE); |
|
|
|
loginDifferentCustomer(); |
|
|
|
doPost("/api/alarm/" + alarm.getId() + "/clear").andExpect(status().isForbidden()); |
|
|
|
logout(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testAcknowledgeAlarmViaAnotherCustomer() throws Exception { |
|
|
|
public void testClearAlarmViaDifferentTenant() throws Exception { |
|
|
|
loginTenantAdmin(); |
|
|
|
Alarm alarm = createAlarm(TEST_ALARM_TYPE); |
|
|
|
loginDifferentTenant(); |
|
|
|
doPost("/api/alarm/" + alarm.getId() + "/clear").andExpect(status().isForbidden()); |
|
|
|
logout(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testAcknowledgeAlarmViaDifferentCustomer() throws Exception { |
|
|
|
loginCustomerUser(); |
|
|
|
Alarm alarm = createAlarm(); |
|
|
|
Alarm alarm = createAlarm(TEST_ALARM_TYPE); |
|
|
|
loginDifferentCustomer(); |
|
|
|
doPost("/api/alarm/" + alarm.getId() + "/ack").andExpect(status().isForbidden()); |
|
|
|
logout(); |
|
|
|
} |
|
|
|
|
|
|
|
private Alarm createAlarm() throws Exception { |
|
|
|
@Test |
|
|
|
public void testAcknowledgeAlarmViaDifferentTenant() throws Exception { |
|
|
|
loginTenantAdmin(); |
|
|
|
Alarm alarm = createAlarm(TEST_ALARM_TYPE); |
|
|
|
loginDifferentTenant(); |
|
|
|
doPost("/api/alarm/" + alarm.getId() + "/ack").andExpect(status().isForbidden()); |
|
|
|
logout(); |
|
|
|
} |
|
|
|
|
|
|
|
private Alarm createAlarm(String type) throws Exception { |
|
|
|
Alarm alarm = Alarm.builder() |
|
|
|
.tenantId(tenantId) |
|
|
|
.customerId(customerId) |
|
|
|
.originator(customerDevice.getId()) |
|
|
|
.status(AlarmStatus.ACTIVE_UNACK) |
|
|
|
.severity(AlarmSeverity.CRITICAL) |
|
|
|
.type("Test") |
|
|
|
.type(type) |
|
|
|
.build(); |
|
|
|
|
|
|
|
alarm = doPost("/api/alarm", alarm, Alarm.class); |
|
|
|
|