Search in sources :

Example 41 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbChangeOriginatorNodeTest method originatorCanBeChangedToCustomerId.

@Test
public void originatorCanBeChangedToCustomerId() throws TbNodeException {
    init();
    AssetId assetId = new AssetId(Uuids.timeBased());
    CustomerId customerId = new CustomerId(Uuids.timeBased());
    Asset asset = new Asset();
    asset.setCustomerId(customerId);
    RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
    RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
    TbMsg msg = TbMsg.newMsg("ASSET", assetId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId);
    when(ctx.getAssetService()).thenReturn(assetService);
    when(assetService.findAssetByIdAsync(any(), eq(assetId))).thenReturn(Futures.immediateFuture(asset));
    node.onMsg(ctx, msg);
    ArgumentCaptor<TbMsg> msgCaptor = ArgumentCaptor.forClass(TbMsg.class);
    ArgumentCaptor<String> typeCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<EntityId> originatorCaptor = ArgumentCaptor.forClass(EntityId.class);
    ArgumentCaptor<TbMsgMetaData> metadataCaptor = ArgumentCaptor.forClass(TbMsgMetaData.class);
    ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class);
    verify(ctx).transformMsg(msgCaptor.capture(), typeCaptor.capture(), originatorCaptor.capture(), metadataCaptor.capture(), dataCaptor.capture());
    assertEquals(customerId, originatorCaptor.getValue());
}
Also used : RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) CustomerId(org.thingsboard.server.common.data.id.CustomerId) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) EntityId(org.thingsboard.server.common.data.id.EntityId) Asset(org.thingsboard.server.common.data.asset.Asset) AssetId(org.thingsboard.server.common.data.id.AssetId) TbMsg(org.thingsboard.server.common.msg.TbMsg) RuleNodeId(org.thingsboard.server.common.data.id.RuleNodeId) Test(org.junit.Test)

Example 42 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbChangeOriginatorNodeTest method newChainCanBeStarted.

@Test
public void newChainCanBeStarted() throws TbNodeException {
    init();
    AssetId assetId = new AssetId(Uuids.timeBased());
    CustomerId customerId = new CustomerId(Uuids.timeBased());
    Asset asset = new Asset();
    asset.setCustomerId(customerId);
    RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
    RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
    TbMsg msg = TbMsg.newMsg("ASSET", assetId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId);
    when(ctx.getAssetService()).thenReturn(assetService);
    when(assetService.findAssetByIdAsync(any(), eq(assetId))).thenReturn(Futures.immediateFuture(asset));
    node.onMsg(ctx, msg);
    ArgumentCaptor<TbMsg> msgCaptor = ArgumentCaptor.forClass(TbMsg.class);
    ArgumentCaptor<String> typeCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<EntityId> originatorCaptor = ArgumentCaptor.forClass(EntityId.class);
    ArgumentCaptor<TbMsgMetaData> metadataCaptor = ArgumentCaptor.forClass(TbMsgMetaData.class);
    ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class);
    verify(ctx).transformMsg(msgCaptor.capture(), typeCaptor.capture(), originatorCaptor.capture(), metadataCaptor.capture(), dataCaptor.capture());
    assertEquals(customerId, originatorCaptor.getValue());
}
Also used : RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) CustomerId(org.thingsboard.server.common.data.id.CustomerId) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) EntityId(org.thingsboard.server.common.data.id.EntityId) Asset(org.thingsboard.server.common.data.asset.Asset) AssetId(org.thingsboard.server.common.data.id.AssetId) TbMsg(org.thingsboard.server.common.msg.TbMsg) RuleNodeId(org.thingsboard.server.common.data.id.RuleNodeId) Test(org.junit.Test)

Example 43 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbCreateRelationNodeTest method testCreateNewRelationAndChangeOriginator.

@Test
public void testCreateNewRelationAndChangeOriginator() throws TbNodeException {
    init(createRelationNodeConfigWithChangeOriginator());
    DeviceId deviceId = new DeviceId(Uuids.timeBased());
    AssetId assetId = new AssetId(Uuids.timeBased());
    Asset asset = new Asset();
    asset.setId(assetId);
    when(assetService.findAssetByTenantIdAndName(any(), eq("AssetName"))).thenReturn(asset);
    when(assetService.findAssetByIdAsync(any(), eq(assetId))).thenReturn(Futures.immediateFuture(asset));
    TbMsgMetaData metaData = new TbMsgMetaData();
    metaData.putValue("name", "AssetName");
    metaData.putValue("type", "AssetType");
    msg = TbMsg.newMsg(DataConstants.ENTITY_CREATED, deviceId, metaData, TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId);
    when(ctx.getRelationService().checkRelation(any(), eq(assetId), eq(deviceId), eq(RELATION_TYPE_CONTAINS), eq(RelationTypeGroup.COMMON))).thenReturn(Futures.immediateFuture(false));
    when(ctx.getRelationService().saveRelationAsync(any(), eq(new EntityRelation(assetId, deviceId, RELATION_TYPE_CONTAINS, RelationTypeGroup.COMMON)))).thenReturn(Futures.immediateFuture(true));
    node.onMsg(ctx, msg);
    ArgumentCaptor<TbMsg> msgCaptor = ArgumentCaptor.forClass(TbMsg.class);
    ArgumentCaptor<String> typeCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<EntityId> originatorCaptor = ArgumentCaptor.forClass(EntityId.class);
    ArgumentCaptor<TbMsgMetaData> metadataCaptor = ArgumentCaptor.forClass(TbMsgMetaData.class);
    ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class);
    verify(ctx).transformMsg(msgCaptor.capture(), typeCaptor.capture(), originatorCaptor.capture(), metadataCaptor.capture(), dataCaptor.capture());
    assertEquals(assetId, originatorCaptor.getValue());
}
Also used : EntityId(org.thingsboard.server.common.data.id.EntityId) EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) DeviceId(org.thingsboard.server.common.data.id.DeviceId) Asset(org.thingsboard.server.common.data.asset.Asset) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) AssetId(org.thingsboard.server.common.data.id.AssetId) TbMsg(org.thingsboard.server.common.msg.TbMsg) Test(org.junit.Test)

Example 44 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbCreateRelationNodeTest method testCreateNewRelation.

@Test
public void testCreateNewRelation() throws TbNodeException {
    init(createRelationNodeConfig());
    DeviceId deviceId = new DeviceId(Uuids.timeBased());
    AssetId assetId = new AssetId(Uuids.timeBased());
    Asset asset = new Asset();
    asset.setId(assetId);
    when(assetService.findAssetByTenantIdAndName(any(), eq("AssetName"))).thenReturn(asset);
    when(assetService.findAssetByIdAsync(any(), eq(assetId))).thenReturn(Futures.immediateFuture(asset));
    TbMsgMetaData metaData = new TbMsgMetaData();
    metaData.putValue("name", "AssetName");
    metaData.putValue("type", "AssetType");
    msg = TbMsg.newMsg(DataConstants.ENTITY_CREATED, deviceId, metaData, TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId);
    when(ctx.getRelationService().checkRelation(any(), eq(assetId), eq(deviceId), eq(RELATION_TYPE_CONTAINS), eq(RelationTypeGroup.COMMON))).thenReturn(Futures.immediateFuture(false));
    when(ctx.getRelationService().saveRelationAsync(any(), eq(new EntityRelation(assetId, deviceId, RELATION_TYPE_CONTAINS, RelationTypeGroup.COMMON)))).thenReturn(Futures.immediateFuture(true));
    node.onMsg(ctx, msg);
    verify(ctx).tellNext(msg, TbRelationTypes.SUCCESS);
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) DeviceId(org.thingsboard.server.common.data.id.DeviceId) Asset(org.thingsboard.server.common.data.asset.Asset) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) AssetId(org.thingsboard.server.common.data.id.AssetId) Test(org.junit.Test)

Example 45 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbJsSwitchNodeTest method multipleRoutesAreAllowed.

@Test
public void multipleRoutesAreAllowed() throws TbNodeException {
    initWithScript();
    TbMsgMetaData metaData = new TbMsgMetaData();
    metaData.putValue("temp", "10");
    metaData.putValue("humidity", "99");
    String rawJson = "{\"name\": \"Vit\", \"passed\": 5}";
    TbMsg msg = TbMsg.newMsg("USER", null, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId);
    when(scriptEngine.executeSwitchAsync(msg)).thenReturn(Futures.immediateFuture(Sets.newHashSet("one", "three")));
    node.onMsg(ctx, msg);
    verify(ctx).tellNext(msg, Sets.newHashSet("one", "three"));
}
Also used : TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) TbMsg(org.thingsboard.server.common.msg.TbMsg) Test(org.junit.Test)

Aggregations

TbMsgMetaData (org.thingsboard.server.common.msg.TbMsgMetaData)89 TbMsg (org.thingsboard.server.common.msg.TbMsg)56 Test (org.junit.Test)49 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)26 Device (org.thingsboard.server.common.data.Device)17 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)17 List (java.util.List)16 DeviceProfileData (org.thingsboard.server.common.data.device.profile.DeviceProfileData)16 DeviceId (org.thingsboard.server.common.data.id.DeviceId)15 EntityId (org.thingsboard.server.common.data.id.EntityId)15 AlarmCondition (org.thingsboard.server.common.data.device.profile.AlarmCondition)14 AlarmConditionFilter (org.thingsboard.server.common.data.device.profile.AlarmConditionFilter)14 AlarmConditionFilterKey (org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey)14 AlarmRule (org.thingsboard.server.common.data.device.profile.AlarmRule)14 DeviceProfileAlarm (org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm)14 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)14 NumericFilterPredicate (org.thingsboard.server.common.data.query.NumericFilterPredicate)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)13 DynamicValue (org.thingsboard.server.common.data.query.DynamicValue)13 AttributeKvCompositeKey (org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey)13