use of org.thingsboard.server.common.data.Device in project thingsboard by thingsboard.
the class AbstractMqttServerSideRpcIntegrationTest method testServerMqttTwoWayRpcDeviceOffline.
@Test
public void testServerMqttTwoWayRpcDeviceOffline() throws Exception {
Device device = new Device();
device.setName("Test Two-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/twoway/" + deviceId, setGpioRequest, String.class, status().isRequestTimeout(), asyncContextTimeoutToUseRpcPlugin);
}
use of org.thingsboard.server.common.data.Device in project thingsboard by thingsboard.
the class AbstractMqttServerSideRpcIntegrationTest method testServerMqttOneWayRpc.
@Test
public void testServerMqttOneWayRpc() throws Exception {
Device device = new Device();
device.setName("Test One-Way Server-Side RPC");
device.setType("default");
Device savedDevice = getSavedDevice(device);
DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice);
assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
String accessToken = deviceCredentials.getCredentialsId();
assertNotNull(accessToken);
String clientId = MqttAsyncClient.generateClientId();
MqttAsyncClient client = new MqttAsyncClient(MQTT_URL, clientId);
MqttConnectOptions options = new MqttConnectOptions();
options.setUserName(accessToken);
client.connect(options).waitForCompletion();
client.subscribe("v1/devices/me/rpc/request/+", 1);
client.setCallback(new TestMqttCallback(client));
String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}";
String deviceId = savedDevice.getId().getId().toString();
String result = doPostAsync("/api/plugins/rpc/oneway/" + deviceId, setGpioRequest, String.class, status().isOk());
Assert.assertTrue(StringUtils.isEmpty(result));
}
use of org.thingsboard.server.common.data.Device in project thingsboard by thingsboard.
the class AbstractMqttServerSideRpcIntegrationTest method testServerMqttTwoWayRpc.
@Test
public void testServerMqttTwoWayRpc() throws Exception {
Device device = new Device();
device.setName("Test Two-Way Server-Side RPC");
device.setType("default");
Device savedDevice = getSavedDevice(device);
DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice);
assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
String accessToken = deviceCredentials.getCredentialsId();
assertNotNull(accessToken);
String clientId = MqttAsyncClient.generateClientId();
MqttAsyncClient client = new MqttAsyncClient(MQTT_URL, clientId);
MqttConnectOptions options = new MqttConnectOptions();
options.setUserName(accessToken);
client.connect(options).waitForCompletion();
client.subscribe("v1/devices/me/rpc/request/+", 1);
client.setCallback(new TestMqttCallback(client));
String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}";
String deviceId = savedDevice.getId().getId().toString();
String result = doPostAsync("/api/plugins/rpc/twoway/" + deviceId, setGpioRequest, String.class, status().isOk());
Assert.assertEquals("{\"value1\":\"A\",\"value2\":\"B\"}", result);
}
use of org.thingsboard.server.common.data.Device in project thingsboard by thingsboard.
the class BaseHttpDeviceApiTest method before.
@Before
public void before() throws Exception {
loginTenantAdmin();
device = new Device();
device.setName("My device");
device.setType("default");
device = doPost("/api/device", device, Device.class);
deviceCredentials = doGet("/api/device/" + device.getId().getId().toString() + "/credentials", DeviceCredentials.class);
}
use of org.thingsboard.server.common.data.Device in project thingsboard by thingsboard.
the class JpaDeviceDaoTest method testFindAsync.
@Test
public void testFindAsync() throws ExecutionException, InterruptedException {
UUID tenantId = UUIDs.timeBased();
UUID customerId = UUIDs.timeBased();
Device device = getDevice(tenantId, customerId);
deviceDao.save(device);
UUID uuid = device.getId().getId();
Device entity = deviceDao.findById(uuid);
assertNotNull(entity);
assertEquals(uuid, entity.getId().getId());
ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
ListenableFuture<Device> future = service.submit(() -> deviceDao.findById(uuid));
Device asyncDevice = future.get();
assertNotNull("Async device expected to be not null", asyncDevice);
}
Aggregations