use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.
the class TbJsFilterNodeTest method exceptionInJsThrowsException.
@Test
public void exceptionInJsThrowsException() throws TbNodeException, ScriptException {
initWithScript();
TbMsgMetaData metaData = new TbMsgMetaData();
TbMsg msg = TbMsg.newMsg("USER", null, metaData, TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId);
when(scriptEngine.executeFilterAsync(msg)).thenReturn(Futures.immediateFailedFuture(new ScriptException("error")));
node.onMsg(ctx, msg);
verifyError(msg, "error", ScriptException.class);
}
use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.
the class AbstractAttributeNodeTest method deviceCustomerTelemetryFetched.
void deviceCustomerTelemetryFetched(Device device) throws TbNodeException {
ObjectMapper mapper = JacksonUtil.OBJECT_MAPPER;
TbNodeConfiguration nodeConfiguration = new TbNodeConfiguration(mapper.valueToTree(getTbNodeConfigForTelemetry()));
TbEntityGetAttrNode node = getEmptyNode();
node.init(null, nodeConfiguration);
msg = TbMsg.newMsg("DEVICE", device.getId(), new TbMsgMetaData(metaData), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId);
List<TsKvEntry> timeseries = Lists.newArrayList(new BasicTsKvEntry(1L, new StringDataEntry("temperature", "highest")));
when(ctx.getTimeseriesService()).thenReturn(timeseriesService);
when(timeseriesService.findLatest(any(), eq(getEntityId()), anyCollection())).thenReturn(Futures.immediateFuture(timeseries));
node.onMsg(ctx, msg);
verify(ctx).tellSuccess(msg);
assertEquals(msg.getMetaData().getValue("answer"), "highest");
}
use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.
the class TbMsgToEmailNodeTest method msgCanBeConverted.
@Test
public void msgCanBeConverted() throws IOException {
initWithScript();
metaData.putValue("username", "oreo");
metaData.putValue("userEmail", "user@email.io");
metaData.putValue("name", "temp");
metaData.putValue("passed", "5");
metaData.putValue("count", "100");
TbMsg msg = TbMsg.newMsg("USER", originator, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId);
emailNode.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("SEND_EMAIL", typeCaptor.getValue());
assertEquals(originator, originatorCaptor.getValue());
assertEquals("oreo", metadataCaptor.getValue().getValue("username"));
assertNotSame(metaData, metadataCaptor.getValue());
TbEmail actual = new ObjectMapper().readValue(dataCaptor.getValue().getBytes(), TbEmail.class);
TbEmail expected = TbEmail.builder().from("test@mail.org").to("user@email.io").subject("Hi oreo there").body("temp is to high. Current 5 and 100").build();
assertEquals(expected, actual);
}
use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.
the class AlarmStateTest method testSetAlarmConditionMetadata_repeatingCondition.
@Test
public void testSetAlarmConditionMetadata_repeatingCondition() {
AlarmRuleState ruleState = createMockAlarmRuleState(new RepeatingAlarmConditionSpec());
int eventCount = 3;
ruleState.getState().setEventCount(eventCount);
AlarmState alarmState = createMockAlarmState();
TbMsgMetaData metaData = new TbMsgMetaData();
alarmState.setAlarmConditionMetadata(ruleState, metaData);
assertEquals(AlarmConditionSpecType.REPEATING, ruleState.getSpec().getType());
assertNotNull(metaData.getValue(DataConstants.ALARM_CONDITION_REPEATS));
assertNull(metaData.getValue(DataConstants.ALARM_CONDITION_DURATION));
assertEquals(String.valueOf(eventCount), metaData.getValue(DataConstants.ALARM_CONDITION_REPEATS));
}
use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.
the class TbChangeOriginatorNodeTest method exceptionThrownIfCannotFindNewOriginator.
@Test
public void exceptionThrownIfCannotFindNewOriginator() 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(null));
node.onMsg(ctx, msg);
verify(ctx).tellNext(same(msg), same(FAILURE));
}
Aggregations