Search in sources :

Example 51 with Device

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

the class BaseAuditLogControllerTest method testAuditLogs_byTenantIdAndEntityId.

@Test
public void testAuditLogs_byTenantIdAndEntityId() throws Exception {
    Device device = new Device();
    device.setName("Device name");
    device.setType("default");
    Device savedDevice = doPost("/api/device", device, Device.class);
    for (int i = 0; i < 178; i++) {
        savedDevice.setName("Device name" + i);
        doPost("/api/device", savedDevice, Device.class);
    }
    List<AuditLog> loadedAuditLogs = new ArrayList<>();
    TimePageLink pageLink = new TimePageLink(23);
    TimePageData<AuditLog> pageData;
    do {
        pageData = doGetTypedWithTimePageLink("/api/audit/logs/entity/DEVICE/" + savedDevice.getId().getId() + "?", new TypeReference<TimePageData<AuditLog>>() {
        }, pageLink);
        loadedAuditLogs.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Assert.assertEquals(179, loadedAuditLogs.size());
}
Also used : Device(org.thingsboard.server.common.data.Device) ArrayList(java.util.ArrayList) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) TypeReference(com.fasterxml.jackson.core.type.TypeReference) AuditLog(org.thingsboard.server.common.data.audit.AuditLog) Test(org.junit.Test)

Example 52 with Device

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

the class AbstractMqttServerSideRpcIntegrationTest method testServerMqttOneWayRpcDeviceOffline.

@Test
public void testServerMqttOneWayRpcDeviceOffline() throws Exception {
    Device device = new Device();
    device.setName("Test One-Way Server-Side RPC Device Offline");
    device.setType("default");
    Device savedDevice = getSavedDevice(device);
    DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice);
    assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
    String accessToken = deviceCredentials.getCredentialsId();
    assertNotNull(accessToken);
    String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}";
    String deviceId = savedDevice.getId().getId().toString();
    doPostAsync("/api/plugins/rpc/oneway/" + deviceId, setGpioRequest, String.class, status().isRequestTimeout(), asyncContextTimeoutToUseRpcPlugin);
}
Also used : Device(org.thingsboard.server.common.data.Device) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest)

Example 53 with Device

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

the class AbstractMqttTelemetryIntegrationTest method beforeTest.

@Before
public void beforeTest() throws Exception {
    loginTenantAdmin();
    Device device = new Device();
    device.setName("Test device");
    device.setType("default");
    savedDevice = doPost("/api/device", device, Device.class);
    DeviceCredentials deviceCredentials = doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
    assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
    accessToken = deviceCredentials.getCredentialsId();
    assertNotNull(accessToken);
}
Also used : Device(org.thingsboard.server.common.data.Device) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) Before(org.junit.Before)

Aggregations

Device (org.thingsboard.server.common.data.Device)53 Test (org.junit.Test)31 DeviceCredentials (org.thingsboard.server.common.data.security.DeviceCredentials)18 ArrayList (java.util.ArrayList)11 DeviceId (org.thingsboard.server.common.data.id.DeviceId)11 CustomerId (org.thingsboard.server.common.data.id.CustomerId)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 Customer (org.thingsboard.server.common.data.Customer)7 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)7 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)7 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)7 TenantId (org.thingsboard.server.common.data.id.TenantId)6 UUID (java.util.UUID)5 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)4 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)4 Tenant (org.thingsboard.server.common.data.Tenant)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 List (java.util.List)2 Before (org.junit.Before)2