use of org.thingsboard.server.common.data.security.DeviceCredentials 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.security.DeviceCredentials 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.security.DeviceCredentials in project thingsboard by thingsboard.
the class JpaDeviceCredentialsDaoTest method findByCredentialsId.
@Test
@DatabaseSetup("classpath:dbunit/device_credentials.xml")
public void findByCredentialsId() {
String credentialsId = "ID_2";
DeviceCredentials deviceCredentials = deviceCredentialsDao.findByCredentialsId(credentialsId);
assertNotNull(deviceCredentials);
assertEquals("958e3c74-3215-11e7-93ae-92361f002671", deviceCredentials.getId().getId().toString());
}
use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.
the class JpaDeviceCredentialsDaoTest method testFindByDeviceId.
@Test
@DatabaseSetup("classpath:dbunit/device_credentials.xml")
public void testFindByDeviceId() {
UUID deviceId = UUID.fromString("958e3a30-3215-11e7-93ae-92361f002671");
DeviceCredentials deviceCredentials = deviceCredentialsDao.findByDeviceId(deviceId);
assertNotNull(deviceCredentials);
assertEquals("958e3314-3215-11e7-93ae-92361f002671", deviceCredentials.getId().getId().toString());
assertEquals("ID_1", deviceCredentials.getCredentialsId());
}
use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.
the class DefaultSystemDataLoaderService method createDevice.
private Device createDevice(TenantId tenantId, CustomerId customerId, String type, String name, String accessToken, String description) {
Device device = new Device();
device.setTenantId(tenantId);
device.setCustomerId(customerId);
device.setType(type);
device.setName(name);
if (description != null) {
ObjectNode additionalInfo = objectMapper.createObjectNode();
additionalInfo.put("description", description);
device.setAdditionalInfo(additionalInfo);
}
device = deviceService.saveDevice(device);
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(device.getId());
deviceCredentials.setCredentialsId(accessToken);
deviceCredentialsService.updateDeviceCredentials(deviceCredentials);
return device;
}
Aggregations