use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.
the class BaseDeviceProfileControllerTest method testSaveDeviceProfileWithInvalidProtoSchema.
private void testSaveDeviceProfileWithInvalidProtoSchema(String schema, String errorMsg) throws Exception {
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = this.createProtoTransportPayloadConfiguration(schema, schema, null, null);
MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = this.createMqttDeviceProfileTransportConfiguration(protoTransportPayloadConfiguration);
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", mqttDeviceProfileTransportConfiguration);
doPost("/api/deviceProfile", deviceProfile).andExpect(status().isBadRequest()).andExpect(statusReason(containsString(errorMsg)));
}
use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.
the class BaseDeviceProfileControllerTest method testSaveDeviceProfileWithEmptyName.
@Test
public void testSaveDeviceProfileWithEmptyName() throws Exception {
DeviceProfile deviceProfile = new DeviceProfile();
doPost("/api/deviceProfile", deviceProfile).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("Device profile name should be specified")));
}
use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.
the class BaseDeviceProfileControllerTest method testChangeDeviceProfileTypeWithExistingDevices.
@Ignore
@Test
public void testChangeDeviceProfileTypeWithExistingDevices() throws Exception {
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", null);
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
Device device = new Device();
device.setName("Test device");
device.setType("default");
device.setDeviceProfileId(savedDeviceProfile.getId());
doPost("/api/device", device, Device.class);
// TODO uncomment once we have other device types;
// savedDeviceProfile.setType(DeviceProfileType.LWM2M);
doPost("/api/deviceProfile", savedDeviceProfile).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("Can't change device profile type because devices referenced it")));
}
use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.
the class BaseDeviceProfileControllerTest method testFindDeviceProfiles.
@Test
public void testFindDeviceProfiles() throws Exception {
List<DeviceProfile> deviceProfiles = new ArrayList<>();
PageLink pageLink = new PageLink(17);
PageData<DeviceProfile> pageData = doGetTypedWithPageLink("/api/deviceProfiles?", new TypeReference<PageData<DeviceProfile>>() {
}, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(1, pageData.getTotalElements());
deviceProfiles.addAll(pageData.getData());
for (int i = 0; i < 28; i++) {
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile" + i, null);
deviceProfiles.add(doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class));
}
List<DeviceProfile> loadedDeviceProfiles = new ArrayList<>();
pageLink = new PageLink(17);
do {
pageData = doGetTypedWithPageLink("/api/deviceProfiles?", new TypeReference<PageData<DeviceProfile>>() {
}, pageLink);
loadedDeviceProfiles.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(deviceProfiles, idComparator);
Collections.sort(loadedDeviceProfiles, idComparator);
Assert.assertEquals(deviceProfiles, loadedDeviceProfiles);
for (DeviceProfile deviceProfile : loadedDeviceProfiles) {
if (!deviceProfile.isDefault()) {
doDelete("/api/deviceProfile/" + deviceProfile.getId().getId().toString()).andExpect(status().isOk());
}
}
pageLink = new PageLink(17);
pageData = doGetTypedWithPageLink("/api/deviceProfiles?", new TypeReference<PageData<DeviceProfile>>() {
}, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(1, pageData.getTotalElements());
}
use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.
the class BaseDeviceProfileControllerTest method testDeleteDeviceProfileWithExistingDevice.
@Test
public void testDeleteDeviceProfileWithExistingDevice() throws Exception {
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", null);
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
Device device = new Device();
device.setName("Test device");
device.setType("default");
device.setDeviceProfileId(savedDeviceProfile.getId());
Device savedDevice = doPost("/api/device", device, Device.class);
doDelete("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString()).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("The device profile referenced by the devices cannot be deleted")));
}
Aggregations