use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class BaseDeviceCredentialsServiceTest method testSaveDeviceCredentialsWithNonExistentDevice.
@Test(expected = DataValidationException.class)
public void testSaveDeviceCredentialsWithNonExistentDevice() {
Device device = new Device();
device.setName("My device");
device.setType("default");
device.setTenantId(tenantId);
device = deviceService.saveDevice(device);
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(device.getId());
deviceCredentials.setDeviceId(new DeviceId(UUIDs.timeBased()));
try {
deviceCredentialsService.updateDeviceCredentials(deviceCredentials);
} finally {
deviceService.deleteDevice(device.getId());
}
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class BaseRelationServiceTest method testRecursiveRelation.
@Test
public void testRecursiveRelation() throws ExecutionException, InterruptedException {
// A -> B -> [C,D]
AssetId assetA = new AssetId(UUIDs.timeBased());
AssetId assetB = new AssetId(UUIDs.timeBased());
AssetId assetC = new AssetId(UUIDs.timeBased());
DeviceId deviceD = new DeviceId(UUIDs.timeBased());
EntityRelation relationAB = new EntityRelation(assetA, assetB, EntityRelation.CONTAINS_TYPE);
EntityRelation relationBC = new EntityRelation(assetB, assetC, EntityRelation.CONTAINS_TYPE);
EntityRelation relationBD = new EntityRelation(assetB, deviceD, EntityRelation.CONTAINS_TYPE);
saveRelation(relationAB);
saveRelation(relationBC);
saveRelation(relationBD);
EntityRelationsQuery query = new EntityRelationsQuery();
query.setParameters(new RelationsSearchParameters(assetA, EntitySearchDirection.FROM, -1));
query.setFilters(Collections.singletonList(new EntityTypeFilter(EntityRelation.CONTAINS_TYPE, Collections.singletonList(EntityType.ASSET))));
List<EntityRelation> relations = relationService.findByQuery(query).get();
Assert.assertEquals(2, relations.size());
Assert.assertTrue(relations.contains(relationAB));
Assert.assertTrue(relations.contains(relationBC));
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class BaseAttributesServiceTest method saveAndFetch.
@Test
public void saveAndFetch() throws Exception {
DeviceId deviceId = new DeviceId(UUIDs.timeBased());
KvEntry attrValue = new StringDataEntry("attribute1", "value1");
AttributeKvEntry attr = new BaseAttributeKvEntry(attrValue, 42L);
attributesService.save(deviceId, DataConstants.CLIENT_SCOPE, Collections.singletonList(attr)).get();
Optional<AttributeKvEntry> saved = attributesService.find(deviceId, DataConstants.CLIENT_SCOPE, attr.getKey()).get();
Assert.assertTrue(saved.isPresent());
Assert.assertEquals(attr, saved.get());
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class BaseAttributesServiceTest method saveMultipleTypeAndFetch.
@Test
public void saveMultipleTypeAndFetch() throws Exception {
DeviceId deviceId = new DeviceId(UUIDs.timeBased());
KvEntry attrOldValue = new StringDataEntry("attribute1", "value1");
AttributeKvEntry attrOld = new BaseAttributeKvEntry(attrOldValue, 42L);
attributesService.save(deviceId, DataConstants.CLIENT_SCOPE, Collections.singletonList(attrOld)).get();
Optional<AttributeKvEntry> saved = attributesService.find(deviceId, DataConstants.CLIENT_SCOPE, attrOld.getKey()).get();
Assert.assertTrue(saved.isPresent());
Assert.assertEquals(attrOld, saved.get());
KvEntry attrNewValue = new StringDataEntry("attribute1", "value2");
AttributeKvEntry attrNew = new BaseAttributeKvEntry(attrNewValue, 73L);
attributesService.save(deviceId, DataConstants.CLIENT_SCOPE, Collections.singletonList(attrNew)).get();
saved = attributesService.find(deviceId, DataConstants.CLIENT_SCOPE, attrOld.getKey()).get();
Assert.assertEquals(attrNew, saved.get());
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class BaseEventServiceTest method saveEventIfNotExists.
@Test
public void saveEventIfNotExists() throws Exception {
DeviceId devId = new DeviceId(UUIDs.timeBased());
Event event = generateEvent(null, devId, "ALARM", UUIDs.timeBased().toString());
Optional<Event> saved = eventService.saveIfNotExists(event);
Assert.assertTrue(saved.isPresent());
saved = eventService.saveIfNotExists(event);
Assert.assertFalse(saved.isPresent());
}
Aggregations