Search in sources :

Example 1 with DeviceProfileInfo

use of org.thingsboard.server.common.data.DeviceProfileInfo in project thingsboard by thingsboard.

the class BaseDeviceProfileControllerTest method testSetDefaultDeviceProfile.

@Test
public void testSetDefaultDeviceProfile() throws Exception {
    DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile 1", null);
    DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
    DeviceProfile defaultDeviceProfile = doPost("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString() + "/default", null, DeviceProfile.class);
    Assert.assertNotNull(defaultDeviceProfile);
    DeviceProfileInfo foundDefaultDeviceProfile = doGet("/api/deviceProfileInfo/default", DeviceProfileInfo.class);
    Assert.assertNotNull(foundDefaultDeviceProfile);
    Assert.assertEquals(savedDeviceProfile.getName(), foundDefaultDeviceProfile.getName());
    Assert.assertEquals(savedDeviceProfile.getId(), foundDefaultDeviceProfile.getId());
    Assert.assertEquals(savedDeviceProfile.getType(), foundDefaultDeviceProfile.getType());
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DeviceProfileInfo(org.thingsboard.server.common.data.DeviceProfileInfo) Test(org.junit.Test)

Example 2 with DeviceProfileInfo

use of org.thingsboard.server.common.data.DeviceProfileInfo in project thingsboard by thingsboard.

the class BaseDeviceProfileControllerTest method testFindDefaultDeviceProfileInfo.

@Test
public void testFindDefaultDeviceProfileInfo() throws Exception {
    DeviceProfileInfo foundDefaultDeviceProfileInfo = doGet("/api/deviceProfileInfo/default", DeviceProfileInfo.class);
    Assert.assertNotNull(foundDefaultDeviceProfileInfo);
    Assert.assertNotNull(foundDefaultDeviceProfileInfo.getId());
    Assert.assertNotNull(foundDefaultDeviceProfileInfo.getName());
    Assert.assertNotNull(foundDefaultDeviceProfileInfo.getType());
    Assert.assertEquals(DeviceProfileType.DEFAULT, foundDefaultDeviceProfileInfo.getType());
    Assert.assertEquals("default", foundDefaultDeviceProfileInfo.getName());
}
Also used : DeviceProfileInfo(org.thingsboard.server.common.data.DeviceProfileInfo) Test(org.junit.Test)

Example 3 with DeviceProfileInfo

use of org.thingsboard.server.common.data.DeviceProfileInfo in project thingsboard by thingsboard.

the class BaseDeviceProfileServiceTest method testFindDeviceProfileInfoById.

@Test
public void testFindDeviceProfileInfoById() {
    DeviceProfile deviceProfile = this.createDeviceProfile(tenantId, "Device Profile");
    DeviceProfile savedDeviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile);
    DeviceProfileInfo foundDeviceProfileInfo = deviceProfileService.findDeviceProfileInfoById(tenantId, savedDeviceProfile.getId());
    Assert.assertNotNull(foundDeviceProfileInfo);
    Assert.assertEquals(savedDeviceProfile.getId(), foundDeviceProfileInfo.getId());
    Assert.assertEquals(savedDeviceProfile.getName(), foundDeviceProfileInfo.getName());
    Assert.assertEquals(savedDeviceProfile.getType(), foundDeviceProfileInfo.getType());
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DeviceProfileInfo(org.thingsboard.server.common.data.DeviceProfileInfo) Test(org.junit.Test)

Example 4 with DeviceProfileInfo

use of org.thingsboard.server.common.data.DeviceProfileInfo in project thingsboard by thingsboard.

the class BaseDeviceProfileControllerTest method testFindDeviceProfileInfoById.

@Test
public void testFindDeviceProfileInfoById() throws Exception {
    DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", null);
    DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
    DeviceProfileInfo foundDeviceProfileInfo = doGet("/api/deviceProfileInfo/" + savedDeviceProfile.getId().getId().toString(), DeviceProfileInfo.class);
    Assert.assertNotNull(foundDeviceProfileInfo);
    Assert.assertEquals(savedDeviceProfile.getId(), foundDeviceProfileInfo.getId());
    Assert.assertEquals(savedDeviceProfile.getName(), foundDeviceProfileInfo.getName());
    Assert.assertEquals(savedDeviceProfile.getType(), foundDeviceProfileInfo.getType());
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DeviceProfileInfo(org.thingsboard.server.common.data.DeviceProfileInfo) Test(org.junit.Test)

Example 5 with DeviceProfileInfo

use of org.thingsboard.server.common.data.DeviceProfileInfo in project thingsboard by thingsboard.

the class BaseDeviceProfileControllerTest method testFindDeviceProfileInfos.

@Test
public void testFindDeviceProfileInfos() throws Exception {
    List<DeviceProfile> deviceProfiles = new ArrayList<>();
    PageLink pageLink = new PageLink(17);
    PageData<DeviceProfile> deviceProfilePageData = doGetTypedWithPageLink("/api/deviceProfiles?", new TypeReference<PageData<DeviceProfile>>() {
    }, pageLink);
    Assert.assertFalse(deviceProfilePageData.hasNext());
    Assert.assertEquals(1, deviceProfilePageData.getTotalElements());
    deviceProfiles.addAll(deviceProfilePageData.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<DeviceProfileInfo> loadedDeviceProfileInfos = new ArrayList<>();
    pageLink = new PageLink(17);
    PageData<DeviceProfileInfo> pageData;
    do {
        pageData = doGetTypedWithPageLink("/api/deviceProfileInfos?", new TypeReference<PageData<DeviceProfileInfo>>() {
        }, pageLink);
        loadedDeviceProfileInfos.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(deviceProfiles, idComparator);
    Collections.sort(loadedDeviceProfileInfos, deviceProfileInfoIdComparator);
    List<DeviceProfileInfo> deviceProfileInfos = deviceProfiles.stream().map(deviceProfile -> new DeviceProfileInfo(deviceProfile.getId(), deviceProfile.getName(), deviceProfile.getImage(), deviceProfile.getDefaultDashboardId(), deviceProfile.getType(), deviceProfile.getTransportType())).collect(Collectors.toList());
    Assert.assertEquals(deviceProfileInfos, loadedDeviceProfileInfos);
    for (DeviceProfile deviceProfile : deviceProfiles) {
        if (!deviceProfile.isDefault()) {
            doDelete("/api/deviceProfile/" + deviceProfile.getId().getId().toString()).andExpect(status().isOk());
        }
    }
    pageLink = new PageLink(17);
    pageData = doGetTypedWithPageLink("/api/deviceProfileInfos?", new TypeReference<PageData<DeviceProfileInfo>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getTotalElements());
}
Also used : DeviceProfileType(org.thingsboard.server.common.data.DeviceProfileType) DynamicMessage(com.google.protobuf.DynamicMessage) Descriptors(com.google.protobuf.Descriptors) Device(org.thingsboard.server.common.data.Device) Tenant(org.thingsboard.server.common.data.Tenant) ArrayList(java.util.ArrayList) User(org.thingsboard.server.common.data.User) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) After(org.junit.After) DeviceTransportType(org.thingsboard.server.common.data.DeviceTransportType) TypeReference(com.fasterxml.jackson.core.type.TypeReference) DeviceProfileProvisionType(org.thingsboard.server.common.data.DeviceProfileProvisionType) Before(org.junit.Before) DeviceProfileInfo(org.thingsboard.server.common.data.DeviceProfileInfo) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) ProtoFileElement(com.squareup.wire.schema.internal.parser.ProtoFileElement) PageLink(org.thingsboard.server.common.data.page.PageLink) Assert.assertNotNull(org.junit.Assert.assertNotNull) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ProtoTransportPayloadConfiguration(org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration) Authority(org.thingsboard.server.common.data.security.Authority) Collectors(java.util.stream.Collectors) List(java.util.List) JsonFormat(com.google.protobuf.util.JsonFormat) Ignore(org.junit.Ignore) DynamicSchema(com.github.os72.protobuf.dynamic.DynamicSchema) PageData(org.thingsboard.server.common.data.page.PageData) DeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) Assert(org.junit.Assert) MqttDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration) TransportPayloadTypeConfiguration(org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) Assert.assertEquals(org.junit.Assert.assertEquals) DeviceProfileInfo(org.thingsboard.server.common.data.DeviceProfileInfo) ArrayList(java.util.ArrayList) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) PageData(org.thingsboard.server.common.data.page.PageData) PageLink(org.thingsboard.server.common.data.page.PageLink) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 DeviceProfileInfo (org.thingsboard.server.common.data.DeviceProfileInfo)7 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)5 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 After (org.junit.After)2 Assert (org.junit.Assert)2 Before (org.junit.Before)2 Ignore (org.junit.Ignore)2 Device (org.thingsboard.server.common.data.Device)2 DeviceTransportType (org.thingsboard.server.common.data.DeviceTransportType)2 Tenant (org.thingsboard.server.common.data.Tenant)2 PageData (org.thingsboard.server.common.data.page.PageData)2 PageLink (org.thingsboard.server.common.data.page.PageLink)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 DynamicSchema (com.github.os72.protobuf.dynamic.DynamicSchema)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1