|
|
@ -26,8 +26,8 @@ import org.apache.commons.lang3.RandomStringUtils; |
|
|
import org.junit.After; |
|
|
import org.junit.After; |
|
|
import org.junit.Assert; |
|
|
import org.junit.Assert; |
|
|
import org.junit.Before; |
|
|
import org.junit.Before; |
|
|
import org.junit.Ignore; |
|
|
|
|
|
import org.junit.Test; |
|
|
import org.junit.Test; |
|
|
|
|
|
import org.mockito.Mockito; |
|
|
import org.thingsboard.server.common.data.Device; |
|
|
import org.thingsboard.server.common.data.Device; |
|
|
import org.thingsboard.server.common.data.DeviceProfile; |
|
|
import org.thingsboard.server.common.data.DeviceProfile; |
|
|
import org.thingsboard.server.common.data.DeviceProfileInfo; |
|
|
import org.thingsboard.server.common.data.DeviceProfileInfo; |
|
|
@ -36,6 +36,7 @@ import org.thingsboard.server.common.data.DeviceProfileType; |
|
|
import org.thingsboard.server.common.data.DeviceTransportType; |
|
|
import org.thingsboard.server.common.data.DeviceTransportType; |
|
|
import org.thingsboard.server.common.data.Tenant; |
|
|
import org.thingsboard.server.common.data.Tenant; |
|
|
import org.thingsboard.server.common.data.User; |
|
|
import org.thingsboard.server.common.data.User; |
|
|
|
|
|
import org.thingsboard.server.common.data.audit.ActionType; |
|
|
import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration; |
|
|
import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration; |
|
|
import org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration; |
|
|
import org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration; |
|
|
import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration; |
|
|
import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration; |
|
|
@ -44,6 +45,7 @@ import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeCon |
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
import org.thingsboard.server.common.data.security.Authority; |
|
|
import org.thingsboard.server.common.data.security.Authority; |
|
|
|
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.Collections; |
|
|
import java.util.Collections; |
|
|
@ -95,6 +97,9 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
@Test |
|
|
@Test |
|
|
public void testSaveDeviceProfile() throws Exception { |
|
|
public void testSaveDeviceProfile() throws Exception { |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
Assert.assertNotNull(savedDeviceProfile); |
|
|
Assert.assertNotNull(savedDeviceProfile); |
|
|
Assert.assertNotNull(savedDeviceProfile.getId()); |
|
|
Assert.assertNotNull(savedDeviceProfile.getId()); |
|
|
@ -105,23 +110,41 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
Assert.assertEquals(deviceProfile.isDefault(), savedDeviceProfile.isDefault()); |
|
|
Assert.assertEquals(deviceProfile.isDefault(), savedDeviceProfile.isDefault()); |
|
|
Assert.assertEquals(deviceProfile.getDefaultRuleChainId(), savedDeviceProfile.getDefaultRuleChainId()); |
|
|
Assert.assertEquals(deviceProfile.getDefaultRuleChainId(), savedDeviceProfile.getDefaultRuleChainId()); |
|
|
Assert.assertEquals(DeviceProfileProvisionType.DISABLED, savedDeviceProfile.getProvisionType()); |
|
|
Assert.assertEquals(DeviceProfileProvisionType.DISABLED, savedDeviceProfile.getProvisionType()); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityBroadcastEntityStateChangeEventOneTime(savedDeviceProfile, savedDeviceProfile.getId(), savedDeviceProfile.getId(), |
|
|
|
|
|
savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), |
|
|
|
|
|
ActionType.ADDED); |
|
|
|
|
|
|
|
|
savedDeviceProfile.setName("New device profile"); |
|
|
savedDeviceProfile.setName("New device profile"); |
|
|
doPost("/api/deviceProfile", savedDeviceProfile, DeviceProfile.class); |
|
|
doPost("/api/deviceProfile", savedDeviceProfile, DeviceProfile.class); |
|
|
DeviceProfile foundDeviceProfile = doGet("/api/deviceProfile/"+savedDeviceProfile.getId().getId().toString(), DeviceProfile.class); |
|
|
DeviceProfile foundDeviceProfile = doGet("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString(), DeviceProfile.class); |
|
|
Assert.assertEquals(savedDeviceProfile.getName(), foundDeviceProfile.getName()); |
|
|
Assert.assertEquals(savedDeviceProfile.getName(), foundDeviceProfile.getName()); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityBroadcastEntityStateChangeEventOneTime(foundDeviceProfile, foundDeviceProfile.getId(), foundDeviceProfile.getId(), |
|
|
|
|
|
savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), |
|
|
|
|
|
ActionType.UPDATED); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void saveDeviceProfileWithViolationOfValidation() throws Exception { |
|
|
public void saveDeviceProfileWithViolationOfValidation() throws Exception { |
|
|
doPost("/api/deviceProfile", this.createDeviceProfile(RandomStringUtils.randomAlphabetic(300))) |
|
|
String msgError = msgErrorFieldLength("name"); |
|
|
.andExpect(statusReason(containsString("length of name must be equal or less than 255"))); |
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
|
|
|
DeviceProfile createDeviceProfile = this.createDeviceProfile(RandomStringUtils.randomAlphabetic(300)); |
|
|
|
|
|
doPost("/api/deviceProfile", createDeviceProfile) |
|
|
|
|
|
.andExpect(status().isBadRequest()) |
|
|
|
|
|
.andExpect(statusReason(containsString(msgError))); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityEqualsOneTimeServiceNeverError(createDeviceProfile, savedTenant.getId(), |
|
|
|
|
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testFindDeviceProfileById() throws Exception { |
|
|
public void testFindDeviceProfileById() throws Exception { |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|
|
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
DeviceProfile foundDeviceProfile = doGet("/api/deviceProfile/"+savedDeviceProfile.getId().getId().toString(), DeviceProfile.class); |
|
|
DeviceProfile foundDeviceProfile = doGet("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString(), DeviceProfile.class); |
|
|
Assert.assertNotNull(foundDeviceProfile); |
|
|
Assert.assertNotNull(foundDeviceProfile); |
|
|
Assert.assertEquals(savedDeviceProfile, foundDeviceProfile); |
|
|
Assert.assertEquals(savedDeviceProfile, foundDeviceProfile); |
|
|
} |
|
|
} |
|
|
@ -132,15 +155,17 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
deviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
deviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
|
|
|
|
|
|
loginDifferentTenant(); |
|
|
loginDifferentTenant(); |
|
|
|
|
|
|
|
|
doGet("/api/deviceProfile/" + deviceProfile.getId()) |
|
|
doGet("/api/deviceProfile/" + deviceProfile.getId()) |
|
|
.andExpect(status().isForbidden()); |
|
|
.andExpect(status().isForbidden()) |
|
|
|
|
|
.andExpect(statusReason(containsString(msgErrorPermission))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testFindDeviceProfileInfoById() throws Exception { |
|
|
public void testFindDeviceProfileInfoById() throws Exception { |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|
|
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
DeviceProfileInfo foundDeviceProfileInfo = doGet("/api/deviceProfileInfo/"+savedDeviceProfile.getId().getId().toString(), DeviceProfileInfo.class); |
|
|
DeviceProfileInfo foundDeviceProfileInfo = doGet("/api/deviceProfileInfo/" + savedDeviceProfile.getId().getId().toString(), DeviceProfileInfo.class); |
|
|
Assert.assertNotNull(foundDeviceProfileInfo); |
|
|
Assert.assertNotNull(foundDeviceProfileInfo); |
|
|
Assert.assertEquals(savedDeviceProfile.getId(), foundDeviceProfileInfo.getId()); |
|
|
Assert.assertEquals(savedDeviceProfile.getId(), foundDeviceProfileInfo.getId()); |
|
|
Assert.assertEquals(savedDeviceProfile.getName(), foundDeviceProfileInfo.getName()); |
|
|
Assert.assertEquals(savedDeviceProfile.getName(), foundDeviceProfileInfo.getName()); |
|
|
@ -154,7 +179,8 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
|
|
|
|
|
|
loginDifferentTenant(); |
|
|
loginDifferentTenant(); |
|
|
doGet("/api/deviceProfileInfo/" + deviceProfile.getId()) |
|
|
doGet("/api/deviceProfileInfo/" + deviceProfile.getId()) |
|
|
.andExpect(status().isForbidden()); |
|
|
.andExpect(status().isForbidden()) |
|
|
|
|
|
.andExpect(statusReason(containsString(msgErrorPermission))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
@ -172,20 +198,35 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
public void testSetDefaultDeviceProfile() throws Exception { |
|
|
public void testSetDefaultDeviceProfile() throws Exception { |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile 1"); |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile 1"); |
|
|
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
DeviceProfile defaultDeviceProfile = doPost("/api/deviceProfile/"+savedDeviceProfile.getId().getId().toString()+"/default", DeviceProfile.class); |
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
|
|
|
DeviceProfile defaultDeviceProfile = doPost("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString() + "/default", DeviceProfile.class); |
|
|
Assert.assertNotNull(defaultDeviceProfile); |
|
|
Assert.assertNotNull(defaultDeviceProfile); |
|
|
DeviceProfileInfo foundDefaultDeviceProfile = doGet("/api/deviceProfileInfo/default", DeviceProfileInfo.class); |
|
|
DeviceProfileInfo foundDefaultDeviceProfile = doGet("/api/deviceProfileInfo/default", DeviceProfileInfo.class); |
|
|
Assert.assertNotNull(foundDefaultDeviceProfile); |
|
|
Assert.assertNotNull(foundDefaultDeviceProfile); |
|
|
Assert.assertEquals(savedDeviceProfile.getName(), foundDefaultDeviceProfile.getName()); |
|
|
Assert.assertEquals(savedDeviceProfile.getName(), foundDefaultDeviceProfile.getName()); |
|
|
Assert.assertEquals(savedDeviceProfile.getId(), foundDefaultDeviceProfile.getId()); |
|
|
Assert.assertEquals(savedDeviceProfile.getId(), foundDefaultDeviceProfile.getId()); |
|
|
Assert.assertEquals(savedDeviceProfile.getType(), foundDefaultDeviceProfile.getType()); |
|
|
Assert.assertEquals(savedDeviceProfile.getType(), foundDefaultDeviceProfile.getType()); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityOneTimeMsgToEdgeServiceNever(defaultDeviceProfile, defaultDeviceProfile.getId(), defaultDeviceProfile.getId(), |
|
|
|
|
|
savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), |
|
|
|
|
|
ActionType.UPDATED); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testSaveDeviceProfileWithEmptyName() throws Exception { |
|
|
public void testSaveDeviceProfileWithEmptyName() throws Exception { |
|
|
DeviceProfile deviceProfile = new DeviceProfile(); |
|
|
DeviceProfile deviceProfile = new DeviceProfile(); |
|
|
doPost("/api/deviceProfile", deviceProfile).andExpect(status().isBadRequest()) |
|
|
|
|
|
.andExpect(statusReason(containsString("Device profile name should be specified"))); |
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
|
|
|
String msgError = "Device profile name " + msgErrorShouldBeSpecified; |
|
|
|
|
|
doPost("/api/deviceProfile", deviceProfile) |
|
|
|
|
|
.andExpect(status().isBadRequest()) |
|
|
|
|
|
.andExpect(statusReason(containsString(msgError))); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityEqualsOneTimeServiceNeverError(deviceProfile, savedTenant.getId(), |
|
|
|
|
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
@ -193,8 +234,16 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|
|
doPost("/api/deviceProfile", deviceProfile).andExpect(status().isOk()); |
|
|
doPost("/api/deviceProfile", deviceProfile).andExpect(status().isOk()); |
|
|
DeviceProfile deviceProfile2 = this.createDeviceProfile("Device Profile"); |
|
|
DeviceProfile deviceProfile2 = this.createDeviceProfile("Device Profile"); |
|
|
doPost("/api/deviceProfile", deviceProfile2).andExpect(status().isBadRequest()) |
|
|
|
|
|
.andExpect(statusReason(containsString("Device profile with such name already exists"))); |
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
|
|
|
String msgError = "Device profile with such name already exists"; |
|
|
|
|
|
doPost("/api/deviceProfile", deviceProfile2) |
|
|
|
|
|
.andExpect(status().isBadRequest()) |
|
|
|
|
|
.andExpect(statusReason(containsString(msgError))); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityEqualsOneTimeServiceNeverError(deviceProfile, savedTenant.getId(), |
|
|
|
|
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
@ -204,24 +253,33 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
doPost("/api/deviceProfile", deviceProfile).andExpect(status().isOk()); |
|
|
doPost("/api/deviceProfile", deviceProfile).andExpect(status().isOk()); |
|
|
DeviceProfile deviceProfile2 = this.createDeviceProfile("Device Profile 2"); |
|
|
DeviceProfile deviceProfile2 = this.createDeviceProfile("Device Profile 2"); |
|
|
deviceProfile2.setProvisionDeviceKey("testProvisionDeviceKey"); |
|
|
deviceProfile2.setProvisionDeviceKey("testProvisionDeviceKey"); |
|
|
doPost("/api/deviceProfile", deviceProfile2).andExpect(status().isBadRequest()) |
|
|
|
|
|
.andExpect(statusReason(containsString("Device profile with such provision device key already exists"))); |
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
|
|
|
String msgError = "Device profile with such provision device key already exists"; |
|
|
|
|
|
doPost("/api/deviceProfile", deviceProfile2) |
|
|
|
|
|
.andExpect(status().isBadRequest()) |
|
|
|
|
|
.andExpect(statusReason(containsString(msgError))); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityEqualsOneTimeServiceNeverError(deviceProfile, savedTenant.getId(), |
|
|
|
|
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testChangeDeviceProfileTypeWithExistingDevices() throws Exception { |
|
|
public void testChangeDeviceProfileTypeNull() throws Exception { |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|
|
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
Device device = new Device(); |
|
|
|
|
|
device.setName("Test device"); |
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
device.setType("default"); |
|
|
|
|
|
device.setDeviceProfileId(savedDeviceProfile.getId()); |
|
|
savedDeviceProfile.setType(null); |
|
|
doPost("/api/device", device, Device.class); |
|
|
String msgError = "Device profile type " + msgErrorShouldBeSpecified; |
|
|
//TODO uncomment once we have other device types;
|
|
|
doPost("/api/deviceProfile", savedDeviceProfile) |
|
|
//savedDeviceProfile.setType(DeviceProfileType.LWM2M);
|
|
|
.andExpect(status().isBadRequest()) |
|
|
doPost("/api/deviceProfile", savedDeviceProfile).andExpect(status().isBadRequest()) |
|
|
.andExpect(statusReason(containsString(msgError))); |
|
|
.andExpect(statusReason(containsString("Can't change device profile type because devices referenced it"))); |
|
|
|
|
|
|
|
|
testNotifyEntityEqualsOneTimeServiceNeverError(deviceProfile, savedTenant.getId(), |
|
|
|
|
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.UPDATED, new DataValidationException(msgError)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
@ -233,9 +291,17 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
device.setType("default"); |
|
|
device.setType("default"); |
|
|
device.setDeviceProfileId(savedDeviceProfile.getId()); |
|
|
device.setDeviceProfileId(savedDeviceProfile.getId()); |
|
|
doPost("/api/device", device, Device.class); |
|
|
doPost("/api/device", device, Device.class); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
|
|
|
String msgError = "Can't change device profile transport type because devices referenced it"; |
|
|
savedDeviceProfile.setTransportType(DeviceTransportType.MQTT); |
|
|
savedDeviceProfile.setTransportType(DeviceTransportType.MQTT); |
|
|
doPost("/api/deviceProfile", savedDeviceProfile).andExpect(status().isBadRequest()) |
|
|
doPost("/api/deviceProfile", savedDeviceProfile) |
|
|
.andExpect(statusReason(containsString("Can't change device profile transport type because devices referenced it"))); |
|
|
.andExpect(status().isBadRequest()) |
|
|
|
|
|
.andExpect(statusReason(containsString(msgError))); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityEqualsOneTimeServiceNeverError(deviceProfile, savedTenant.getId(), |
|
|
|
|
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.UPDATED, new DataValidationException(msgError)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
@ -248,11 +314,15 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
device.setType("default"); |
|
|
device.setType("default"); |
|
|
device.setDeviceProfileId(savedDeviceProfile.getId()); |
|
|
device.setDeviceProfileId(savedDeviceProfile.getId()); |
|
|
|
|
|
|
|
|
Device savedDevice = doPost("/api/device", device, Device.class); |
|
|
doPost("/api/device", device, Device.class); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
doDelete("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString()) |
|
|
doDelete("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString()) |
|
|
.andExpect(status().isBadRequest()) |
|
|
.andExpect(status().isBadRequest()) |
|
|
.andExpect(statusReason(containsString("The device profile referenced by the devices cannot be deleted"))); |
|
|
.andExpect(statusReason(containsString("The device profile referenced by the devices cannot be deleted"))); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityNever(savedDeviceProfile.getId(), savedDeviceProfile); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
@ -260,11 +330,19 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|
|
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
doDelete("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString()) |
|
|
doDelete("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString()) |
|
|
.andExpect(status().isOk()); |
|
|
.andExpect(status().isOk()); |
|
|
|
|
|
|
|
|
|
|
|
String savedDeviceProfileIdFtr = savedDeviceProfile.getId().getId().toString(); |
|
|
|
|
|
testNotifyEntityBroadcastEntityStateChangeEventOneTime(savedDeviceProfile, savedDeviceProfile.getId(), savedDeviceProfile.getId(), |
|
|
|
|
|
savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), |
|
|
|
|
|
ActionType.DELETED, savedDeviceProfileIdFtr); |
|
|
|
|
|
|
|
|
doGet("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString()) |
|
|
doGet("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString()) |
|
|
.andExpect(status().isNotFound()); |
|
|
.andExpect(status().isNotFound()) |
|
|
|
|
|
.andExpect(statusReason(containsString(msgErrorNoFound("Device profile", savedDeviceProfileIdFtr)))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
@ -272,21 +350,30 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
List<DeviceProfile> deviceProfiles = new ArrayList<>(); |
|
|
List<DeviceProfile> deviceProfiles = new ArrayList<>(); |
|
|
PageLink pageLink = new PageLink(17); |
|
|
PageLink pageLink = new PageLink(17); |
|
|
PageData<DeviceProfile> pageData = doGetTypedWithPageLink("/api/deviceProfiles?", |
|
|
PageData<DeviceProfile> pageData = doGetTypedWithPageLink("/api/deviceProfiles?", |
|
|
new TypeReference<PageData<DeviceProfile>>(){}, pageLink); |
|
|
new TypeReference<>() { |
|
|
|
|
|
}, pageLink); |
|
|
Assert.assertFalse(pageData.hasNext()); |
|
|
Assert.assertFalse(pageData.hasNext()); |
|
|
Assert.assertEquals(1, pageData.getTotalElements()); |
|
|
Assert.assertEquals(1, pageData.getTotalElements()); |
|
|
deviceProfiles.addAll(pageData.getData()); |
|
|
deviceProfiles.addAll(pageData.getData()); |
|
|
|
|
|
|
|
|
for (int i=0;i<28;i++) { |
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"+i); |
|
|
|
|
|
|
|
|
int cntEntity = 28; |
|
|
|
|
|
for (int i = 0; i < cntEntity; i++) { |
|
|
|
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile" + i); |
|
|
deviceProfiles.add(doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class)); |
|
|
deviceProfiles.add(doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
testNotifyManyEntityManyTimeMsgToEdgeServiceEntityEqAny(new DeviceProfile(), new DeviceProfile(), |
|
|
|
|
|
savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), |
|
|
|
|
|
ActionType.ADDED, ActionType.ADDED, cntEntity, cntEntity, cntEntity); |
|
|
|
|
|
|
|
|
List<DeviceProfile> loadedDeviceProfiles = new ArrayList<>(); |
|
|
List<DeviceProfile> loadedDeviceProfiles = new ArrayList<>(); |
|
|
pageLink = new PageLink(17); |
|
|
pageLink = new PageLink(17); |
|
|
do { |
|
|
do { |
|
|
pageData = doGetTypedWithPageLink("/api/deviceProfiles?", |
|
|
pageData = doGetTypedWithPageLink("/api/deviceProfiles?", |
|
|
new TypeReference<PageData<DeviceProfile>>(){}, pageLink); |
|
|
new TypeReference<>() { |
|
|
|
|
|
}, pageLink); |
|
|
loadedDeviceProfiles.addAll(pageData.getData()); |
|
|
loadedDeviceProfiles.addAll(pageData.getData()); |
|
|
if (pageData.hasNext()) { |
|
|
if (pageData.hasNext()) { |
|
|
pageLink = pageLink.nextPageLink(); |
|
|
pageLink = pageLink.nextPageLink(); |
|
|
@ -305,9 +392,14 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
testNotifyManyEntityManyTimeMsgToEdgeServiceEntityEqAny(loadedDeviceProfiles.get(0), loadedDeviceProfiles.get(0), |
|
|
|
|
|
savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), |
|
|
|
|
|
ActionType.DELETED, ActionType.DELETED, cntEntity, cntEntity, cntEntity, loadedDeviceProfiles.get(0).getId().getId().toString()); |
|
|
|
|
|
|
|
|
pageLink = new PageLink(17); |
|
|
pageLink = new PageLink(17); |
|
|
pageData = doGetTypedWithPageLink("/api/deviceProfiles?", |
|
|
pageData = doGetTypedWithPageLink("/api/deviceProfiles?", |
|
|
new TypeReference<PageData<DeviceProfile>>(){}, pageLink); |
|
|
new TypeReference<>() { |
|
|
|
|
|
}, pageLink); |
|
|
Assert.assertFalse(pageData.hasNext()); |
|
|
Assert.assertFalse(pageData.hasNext()); |
|
|
Assert.assertEquals(1, pageData.getTotalElements()); |
|
|
Assert.assertEquals(1, pageData.getTotalElements()); |
|
|
} |
|
|
} |
|
|
@ -317,13 +409,14 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
List<DeviceProfile> deviceProfiles = new ArrayList<>(); |
|
|
List<DeviceProfile> deviceProfiles = new ArrayList<>(); |
|
|
PageLink pageLink = new PageLink(17); |
|
|
PageLink pageLink = new PageLink(17); |
|
|
PageData<DeviceProfile> deviceProfilePageData = doGetTypedWithPageLink("/api/deviceProfiles?", |
|
|
PageData<DeviceProfile> deviceProfilePageData = doGetTypedWithPageLink("/api/deviceProfiles?", |
|
|
new TypeReference<PageData<DeviceProfile>>(){}, pageLink); |
|
|
new TypeReference<PageData<DeviceProfile>>() { |
|
|
|
|
|
}, pageLink); |
|
|
Assert.assertFalse(deviceProfilePageData.hasNext()); |
|
|
Assert.assertFalse(deviceProfilePageData.hasNext()); |
|
|
Assert.assertEquals(1, deviceProfilePageData.getTotalElements()); |
|
|
Assert.assertEquals(1, deviceProfilePageData.getTotalElements()); |
|
|
deviceProfiles.addAll(deviceProfilePageData.getData()); |
|
|
deviceProfiles.addAll(deviceProfilePageData.getData()); |
|
|
|
|
|
|
|
|
for (int i=0;i<28;i++) { |
|
|
for (int i = 0; i < 28; i++) { |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"+i); |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile" + i); |
|
|
deviceProfiles.add(doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class)); |
|
|
deviceProfiles.add(doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -332,7 +425,8 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
PageData<DeviceProfileInfo> pageData; |
|
|
PageData<DeviceProfileInfo> pageData; |
|
|
do { |
|
|
do { |
|
|
pageData = doGetTypedWithPageLink("/api/deviceProfileInfos?", |
|
|
pageData = doGetTypedWithPageLink("/api/deviceProfileInfos?", |
|
|
new TypeReference<PageData<DeviceProfileInfo>>(){}, pageLink); |
|
|
new TypeReference<>() { |
|
|
|
|
|
}, pageLink); |
|
|
loadedDeviceProfileInfos.addAll(pageData.getData()); |
|
|
loadedDeviceProfileInfos.addAll(pageData.getData()); |
|
|
if (pageData.hasNext()) { |
|
|
if (pageData.hasNext()) { |
|
|
pageLink = pageLink.nextPageLink(); |
|
|
pageLink = pageLink.nextPageLink(); |
|
|
@ -357,7 +451,8 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
|
|
|
|
|
|
pageLink = new PageLink(17); |
|
|
pageLink = new PageLink(17); |
|
|
pageData = doGetTypedWithPageLink("/api/deviceProfileInfos?", |
|
|
pageData = doGetTypedWithPageLink("/api/deviceProfileInfos?", |
|
|
new TypeReference<PageData<DeviceProfileInfo>>(){}, pageLink); |
|
|
new TypeReference<PageData<DeviceProfileInfo>>() { |
|
|
|
|
|
}, pageLink); |
|
|
Assert.assertFalse(pageData.hasNext()); |
|
|
Assert.assertFalse(pageData.hasNext()); |
|
|
Assert.assertEquals(1, pageData.getTotalElements()); |
|
|
Assert.assertEquals(1, pageData.getTotalElements()); |
|
|
} |
|
|
} |
|
|
@ -867,7 +962,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
Assert.assertTrue(savedDeviceProfile.getProfileData().getTransportConfiguration() instanceof MqttDeviceProfileTransportConfiguration); |
|
|
Assert.assertTrue(savedDeviceProfile.getProfileData().getTransportConfiguration() instanceof MqttDeviceProfileTransportConfiguration); |
|
|
MqttDeviceProfileTransportConfiguration transportConfiguration = (MqttDeviceProfileTransportConfiguration) savedDeviceProfile.getProfileData().getTransportConfiguration(); |
|
|
MqttDeviceProfileTransportConfiguration transportConfiguration = (MqttDeviceProfileTransportConfiguration) savedDeviceProfile.getProfileData().getTransportConfiguration(); |
|
|
Assert.assertTrue(transportConfiguration.isSendAckOnValidationException()); |
|
|
Assert.assertTrue(transportConfiguration.isSendAckOnValidationException()); |
|
|
DeviceProfile foundDeviceProfile = doGet("/api/deviceProfile/"+ savedDeviceProfile.getId().getId().toString(), DeviceProfile.class); |
|
|
DeviceProfile foundDeviceProfile = doGet("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString(), DeviceProfile.class); |
|
|
Assert.assertEquals(savedDeviceProfile, foundDeviceProfile); |
|
|
Assert.assertEquals(savedDeviceProfile, foundDeviceProfile); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -877,7 +972,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", mqttDeviceProfileTransportConfiguration); |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", mqttDeviceProfileTransportConfiguration); |
|
|
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
Assert.assertNotNull(savedDeviceProfile); |
|
|
Assert.assertNotNull(savedDeviceProfile); |
|
|
DeviceProfile foundDeviceProfile = doGet("/api/deviceProfile/"+ savedDeviceProfile.getId().getId().toString(), DeviceProfile.class); |
|
|
DeviceProfile foundDeviceProfile = doGet("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString(), DeviceProfile.class); |
|
|
Assert.assertEquals(savedDeviceProfile, foundDeviceProfile); |
|
|
Assert.assertEquals(savedDeviceProfile, foundDeviceProfile); |
|
|
return savedDeviceProfile; |
|
|
return savedDeviceProfile; |
|
|
} |
|
|
} |
|
|
@ -886,16 +981,30 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
|
|
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = this.createProtoTransportPayloadConfiguration(schema, schema, null, null); |
|
|
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = this.createProtoTransportPayloadConfiguration(schema, schema, null, null); |
|
|
MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = this.createMqttDeviceProfileTransportConfiguration(protoTransportPayloadConfiguration, false); |
|
|
MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = this.createMqttDeviceProfileTransportConfiguration(protoTransportPayloadConfiguration, false); |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", mqttDeviceProfileTransportConfiguration); |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", mqttDeviceProfileTransportConfiguration); |
|
|
doPost("/api/deviceProfile", deviceProfile).andExpect(status().isBadRequest()) |
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
|
|
|
doPost("/api/deviceProfile", deviceProfile) |
|
|
|
|
|
.andExpect(status().isBadRequest()) |
|
|
.andExpect(statusReason(containsString(errorMsg))); |
|
|
.andExpect(statusReason(containsString(errorMsg))); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityEqualsOneTimeServiceNeverError(deviceProfile,savedTenant.getId(), |
|
|
|
|
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(errorMsg)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void testSaveDeviceProfileWithInvalidRpcRequestProtoSchema(String schema, String errorMsg) throws Exception { |
|
|
private void testSaveDeviceProfileWithInvalidRpcRequestProtoSchema(String schema, String errorMsg) throws Exception { |
|
|
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = this.createProtoTransportPayloadConfiguration(schema, schema, schema, null); |
|
|
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = this.createProtoTransportPayloadConfiguration(schema, schema, schema, null); |
|
|
MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = this.createMqttDeviceProfileTransportConfiguration(protoTransportPayloadConfiguration, false); |
|
|
MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = this.createMqttDeviceProfileTransportConfiguration(protoTransportPayloadConfiguration, false); |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", mqttDeviceProfileTransportConfiguration); |
|
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", mqttDeviceProfileTransportConfiguration); |
|
|
doPost("/api/deviceProfile", deviceProfile).andExpect(status().isBadRequest()) |
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
|
|
|
doPost("/api/deviceProfile", deviceProfile) |
|
|
|
|
|
.andExpect(status().isBadRequest()) |
|
|
.andExpect(statusReason(containsString(errorMsg))); |
|
|
.andExpect(statusReason(containsString(errorMsg))); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityEqualsOneTimeServiceNeverError(deviceProfile,savedTenant.getId(), |
|
|
|
|
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(errorMsg)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private DynamicSchema getDynamicSchema(String schema) throws Exception { |
|
|
private DynamicSchema getDynamicSchema(String schema) throws Exception { |
|
|
|