Search in sources :

Example 16 with AttributeKvEntry

use of org.thingsboard.server.common.data.kv.AttributeKvEntry 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());
}
Also used : BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry) DeviceId(org.thingsboard.server.common.data.id.DeviceId) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) Test(org.junit.Test) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest)

Aggregations

AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)16 BaseAttributeKvEntry (org.thingsboard.server.common.data.kv.BaseAttributeKvEntry)10 DeviceId (org.thingsboard.server.common.data.id.DeviceId)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 BooleanDataEntry (org.thingsboard.server.common.data.kv.BooleanDataEntry)5 DeviceAttributes (org.thingsboard.server.extensions.api.device.DeviceAttributes)5 DeviceMetaData (org.thingsboard.server.extensions.api.device.DeviceMetaData)5 DoubleDataEntry (org.thingsboard.server.common.data.kv.DoubleDataEntry)4 KvEntry (org.thingsboard.server.common.data.kv.KvEntry)3 StringDataEntry (org.thingsboard.server.common.data.kv.StringDataEntry)3 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)3 HashMap (java.util.HashMap)2 ActorContext (akka.actor.ActorContext)1 ActorRef (akka.actor.ActorRef)1 LoggingAdapter (akka.event.LoggingAdapter)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 java.util (java.util)1