|
|
|
@ -25,8 +25,13 @@ import org.junit.After; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
import org.mockito.AdditionalAnswers; |
|
|
|
import org.mockito.Mockito; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.boot.test.mock.mockito.SpyBean; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Primary; |
|
|
|
import org.springframework.test.context.ContextConfiguration; |
|
|
|
import org.thingsboard.common.util.ThingsBoardExecutors; |
|
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
|
import org.thingsboard.server.common.data.Device; |
|
|
|
@ -69,8 +74,10 @@ import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE; |
|
|
|
import static org.thingsboard.server.common.data.ota.OtaPackageType.SOFTWARE; |
|
|
|
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
|
|
|
|
|
|
|
@ContextConfiguration(classes = {BaseDeviceControllerTest.Config.class}) |
|
|
|
public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
|
|
|
static final TypeReference<PageData<Device>> PAGE_DATA_DEVICE_TYPE_REF = new TypeReference<>() {}; |
|
|
|
static final TypeReference<PageData<Device>> PAGE_DATA_DEVICE_TYPE_REF = new TypeReference<>() { |
|
|
|
}; |
|
|
|
|
|
|
|
ListeningExecutorService executor; |
|
|
|
|
|
|
|
@ -83,9 +90,16 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
|
|
|
@SpyBean |
|
|
|
private GatewayNotificationsService gatewayNotificationsService; |
|
|
|
|
|
|
|
@SpyBean |
|
|
|
@Autowired |
|
|
|
private DeviceDao deviceDao; |
|
|
|
|
|
|
|
static class Config { |
|
|
|
@Bean |
|
|
|
@Primary |
|
|
|
public DeviceDao deviceDao(DeviceDao deviceDao) { |
|
|
|
return Mockito.mock(DeviceDao.class, AdditionalAnswers.delegatesTo(deviceDao)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Before |
|
|
|
public void beforeTest() throws Exception { |
|
|
|
@ -114,8 +128,6 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
|
|
|
|
|
|
|
loginSysAdmin(); |
|
|
|
|
|
|
|
afterTestEntityDaoRemoveByIdWithException (deviceDao); |
|
|
|
|
|
|
|
doDelete("/api/tenant/" + savedTenant.getId().getId()) |
|
|
|
.andExpect(status().isOk()); |
|
|
|
} |
|
|
|
@ -464,9 +476,9 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
|
|
|
|
|
|
|
String customerIdStr = savedDevice.getId().toString(); |
|
|
|
doPost("/api/customer/" + customerIdStr |
|
|
|
+ "/device/" + savedDevice.getId().getId()) |
|
|
|
+ "/device/" + savedDevice.getId().getId()) |
|
|
|
.andExpect(status().isNotFound()) |
|
|
|
.andExpect(statusReason(containsString(msgErrorNoFound("Customer", customerIdStr)))); |
|
|
|
.andExpect(statusReason(containsString(msgErrorNoFound("Customer", customerIdStr)))); |
|
|
|
|
|
|
|
testNotifyEntityNever(savedDevice.getId(), savedDevice); |
|
|
|
testNotificationUpdateGatewayNever(); |
|
|
|
@ -657,7 +669,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
|
|
|
|
|
|
|
doPost("/api/device/credentials", deviceCredentials) |
|
|
|
.andExpect(status().isNotFound()) |
|
|
|
.andExpect(statusReason(containsString(msgErrorNoFound("Device", deviceTimeBasedId.toString())))); |
|
|
|
.andExpect(statusReason(containsString(msgErrorNoFound("Device", deviceTimeBasedId.toString())))); |
|
|
|
|
|
|
|
testNotifyEntityNever(savedDevice.getId(), savedDevice); |
|
|
|
testNotificationUpdateGatewayNever(); |
|
|
|
@ -1168,7 +1180,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
|
|
|
doPost("/api/edge/" + savedEdge.getId().getId() |
|
|
|
+ "/device/" + savedDevice.getId().getId(), Device.class); |
|
|
|
|
|
|
|
testNotifyEntityAllOneTime(savedDevice, savedDevice.getId(), savedDevice.getId(), |
|
|
|
testNotifyEntityAllOneTime(savedDevice, savedDevice.getId(), savedDevice.getId(), |
|
|
|
savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), |
|
|
|
ActionType.ASSIGNED_TO_EDGE, |
|
|
|
savedDevice.getId().getId().toString(), savedEdge.getId().getId().toString(), savedEdge.getName()); |
|
|
|
|