Search in sources :

Example 1 with StringDataEntry

use of org.thingsboard.server.common.data.kv.StringDataEntry in project thingsboard by thingsboard.

the class DefaultActorServiceTest method testBasicPostWithSyncSession.

@Test
public void testBasicPostWithSyncSession() throws Exception {
    SessionContext ssnCtx = mock(SessionContext.class);
    KvEntry entry1 = new StringDataEntry("key1", "value1");
    KvEntry entry2 = new StringDataEntry("key2", "value2");
    BasicTelemetryUploadRequest telemetry = new BasicTelemetryUploadRequest();
    long ts = 42;
    telemetry.add(ts, entry1);
    telemetry.add(ts, entry2);
    BasicAdaptorToSessionActorMsg msg = new BasicAdaptorToSessionActorMsg(ssnCtx, telemetry);
    DeviceId deviceId = new DeviceId(UUID.randomUUID());
    DeviceCredentialsFilter filter = new DeviceTokenCredentials("token1");
    Device device = mock(Device.class);
    when(device.getId()).thenReturn(deviceId);
    when(device.getTenantId()).thenReturn(tenantId);
    when(ssnCtx.getSessionId()).thenReturn(new DummySessionID("session1"));
    when(ssnCtx.getSessionType()).thenReturn(SessionType.SYNC);
    when(deviceAuthService.process(filter)).thenReturn(DeviceAuthResult.of(deviceId));
    when(deviceService.findDeviceById(deviceId)).thenReturn(device);
    ObjectMapper ruleMapper = new ObjectMapper();
    when(ruleMock.getFilters()).thenReturn(ruleMapper.readTree(FILTERS_CONFIGURATION));
    when(ruleMock.getAction()).thenReturn(ruleMapper.readTree(ACTION_CONFIGURATION));
    ComponentDescriptor filterComp = new ComponentDescriptor();
    filterComp.setClazz("org.thingsboard.server.extensions.core.filter.MsgTypeFilter");
    filterComp.setType(ComponentType.FILTER);
    when(componentService.getComponent("org.thingsboard.server.extensions.core.filter.MsgTypeFilter")).thenReturn(Optional.of(filterComp));
    ComponentDescriptor actionComp = new ComponentDescriptor();
    actionComp.setClazz("org.thingsboard.server.extensions.core.action.telemetry.TelemetryPluginAction");
    actionComp.setType(ComponentType.ACTION);
    when(componentService.getComponent("org.thingsboard.server.extensions.core.action.telemetry.TelemetryPluginAction")).thenReturn(Optional.of(actionComp));
    ObjectMapper pluginMapper = new ObjectMapper();
    JsonNode pluginAdditionalInfo = pluginMapper.readTree(PLUGIN_CONFIGURATION);
    when(pluginMock.getConfiguration()).thenReturn(pluginAdditionalInfo);
    when(pluginMock.getClazz()).thenReturn(TelemetryStoragePlugin.class.getName());
    when(attributesService.findAll(deviceId, DataConstants.CLIENT_SCOPE)).thenReturn(Futures.immediateFuture(Collections.emptyList()));
    when(attributesService.findAll(deviceId, DataConstants.SHARED_SCOPE)).thenReturn(Futures.immediateFuture(Collections.emptyList()));
    when(attributesService.findAll(deviceId, DataConstants.SERVER_SCOPE)).thenReturn(Futures.immediateFuture(Collections.emptyList()));
    initActorSystem();
    Thread.sleep(1000);
    actorService.process(new BasicToDeviceActorSessionMsg(device, msg));
    // Check that device data was saved to DB;
    List<TsKvEntry> expected = new ArrayList<>();
    expected.add(new BasicTsKvEntry(ts, entry1));
    expected.add(new BasicTsKvEntry(ts, entry2));
    verify(tsService, Mockito.timeout(5000)).save(deviceId, expected, 0L);
}
Also used : BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) Device(org.thingsboard.server.common.data.Device) ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) TelemetryStoragePlugin(org.thingsboard.server.extensions.core.plugin.telemetry.TelemetryStoragePlugin) JsonNode(com.fasterxml.jackson.databind.JsonNode) DeviceCredentialsFilter(org.thingsboard.server.common.data.security.DeviceCredentialsFilter) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry) BasicTelemetryUploadRequest(org.thingsboard.server.common.msg.core.BasicTelemetryUploadRequest) DeviceTokenCredentials(org.thingsboard.server.common.data.security.DeviceTokenCredentials) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with StringDataEntry

use of org.thingsboard.server.common.data.kv.StringDataEntry in project thingsboard by thingsboard.

the class BaseAttributesServiceTest method findAll.

@Test
public void findAll() throws Exception {
    DeviceId deviceId = new DeviceId(UUIDs.timeBased());
    KvEntry attrAOldValue = new StringDataEntry("A", "value1");
    AttributeKvEntry attrAOld = new BaseAttributeKvEntry(attrAOldValue, 42L);
    KvEntry attrANewValue = new StringDataEntry("A", "value2");
    AttributeKvEntry attrANew = new BaseAttributeKvEntry(attrANewValue, 73L);
    KvEntry attrBNewValue = new StringDataEntry("B", "value3");
    AttributeKvEntry attrBNew = new BaseAttributeKvEntry(attrBNewValue, 73L);
    attributesService.save(deviceId, DataConstants.CLIENT_SCOPE, Collections.singletonList(attrAOld)).get();
    attributesService.save(deviceId, DataConstants.CLIENT_SCOPE, Collections.singletonList(attrANew)).get();
    attributesService.save(deviceId, DataConstants.CLIENT_SCOPE, Collections.singletonList(attrBNew)).get();
    List<AttributeKvEntry> saved = attributesService.findAll(deviceId, DataConstants.CLIENT_SCOPE).get();
    Assert.assertNotNull(saved);
    Assert.assertEquals(2, saved.size());
    Assert.assertEquals(attrANew, saved.get(0));
    Assert.assertEquals(attrBNew, saved.get(1));
}
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)

Example 3 with StringDataEntry

use of org.thingsboard.server.common.data.kv.StringDataEntry 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());
}
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)

Example 4 with StringDataEntry

use of org.thingsboard.server.common.data.kv.StringDataEntry 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

Test (org.junit.Test)4 KvEntry (org.thingsboard.server.common.data.kv.KvEntry)4 StringDataEntry (org.thingsboard.server.common.data.kv.StringDataEntry)4 DeviceId (org.thingsboard.server.common.data.id.DeviceId)3 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)3 BaseAttributeKvEntry (org.thingsboard.server.common.data.kv.BaseAttributeKvEntry)3 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Device (org.thingsboard.server.common.data.Device)1 BasicTsKvEntry (org.thingsboard.server.common.data.kv.BasicTsKvEntry)1 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)1 ComponentDescriptor (org.thingsboard.server.common.data.plugin.ComponentDescriptor)1 DeviceCredentialsFilter (org.thingsboard.server.common.data.security.DeviceCredentialsFilter)1 DeviceTokenCredentials (org.thingsboard.server.common.data.security.DeviceTokenCredentials)1 BasicTelemetryUploadRequest (org.thingsboard.server.common.msg.core.BasicTelemetryUploadRequest)1 TelemetryStoragePlugin (org.thingsboard.server.extensions.core.plugin.telemetry.TelemetryStoragePlugin)1