Search in sources :

Example 1 with TbNodeConfiguration

use of org.thingsboard.rule.engine.api.TbNodeConfiguration in project thingsboard by thingsboard.

the class TbJsFilterNodeTest method initWithScript.

private void initWithScript() throws TbNodeException {
    TbJsFilterNodeConfiguration config = new TbJsFilterNodeConfiguration();
    config.setJsScript("scr");
    ObjectMapper mapper = new ObjectMapper();
    TbNodeConfiguration nodeConfiguration = new TbNodeConfiguration(mapper.valueToTree(config));
    when(ctx.createJsScriptEngine("scr")).thenReturn(scriptEngine);
    node = new TbJsFilterNode();
    node.init(ctx, nodeConfiguration);
}
Also used : TbNodeConfiguration(org.thingsboard.rule.engine.api.TbNodeConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with TbNodeConfiguration

use of org.thingsboard.rule.engine.api.TbNodeConfiguration in project thingsboard by thingsboard.

the class AbstractAttributeNodeTest method init.

void init(TbEntityGetAttrNode node) throws TbNodeException {
    ObjectMapper mapper = JacksonUtil.OBJECT_MAPPER;
    TbNodeConfiguration nodeConfiguration = new TbNodeConfiguration(mapper.valueToTree(getTbNodeConfig()));
    metaData = new HashMap<>();
    metaData.putIfAbsent("word", "temperature");
    metaData.putIfAbsent("result", "answer");
    this.node = node;
    this.node.init(null, nodeConfiguration);
}
Also used : TbNodeConfiguration(org.thingsboard.rule.engine.api.TbNodeConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with TbNodeConfiguration

use of org.thingsboard.rule.engine.api.TbNodeConfiguration 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");
}
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) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) TbNodeConfiguration(org.thingsboard.rule.engine.api.TbNodeConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with TbNodeConfiguration

use of org.thingsboard.rule.engine.api.TbNodeConfiguration in project thingsboard by thingsboard.

the class TbChangeOriginatorNodeTest method init.

public void init() throws TbNodeException {
    TbChangeOriginatorNodeConfiguration config = new TbChangeOriginatorNodeConfiguration();
    config.setOriginatorSource(TbChangeOriginatorNode.CUSTOMER_SOURCE);
    ObjectMapper mapper = new ObjectMapper();
    TbNodeConfiguration nodeConfiguration = new TbNodeConfiguration(mapper.valueToTree(config));
    when(ctx.getDbCallbackExecutor()).thenReturn(dbExecutor);
    node = new TbChangeOriginatorNode();
    node.init(null, nodeConfiguration);
}
Also used : TbNodeConfiguration(org.thingsboard.rule.engine.api.TbNodeConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with TbNodeConfiguration

use of org.thingsboard.rule.engine.api.TbNodeConfiguration in project thingsboard by thingsboard.

the class TbJsSwitchNodeTest method initWithScript.

private void initWithScript() throws TbNodeException {
    TbJsSwitchNodeConfiguration config = new TbJsSwitchNodeConfiguration();
    config.setJsScript("scr");
    ObjectMapper mapper = new ObjectMapper();
    TbNodeConfiguration nodeConfiguration = new TbNodeConfiguration(mapper.valueToTree(config));
    when(ctx.createJsScriptEngine("scr")).thenReturn(scriptEngine);
    node = new TbJsSwitchNode();
    node.init(ctx, nodeConfiguration);
}
Also used : TbNodeConfiguration(org.thingsboard.rule.engine.api.TbNodeConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

TbNodeConfiguration (org.thingsboard.rule.engine.api.TbNodeConfiguration)16 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)14 TbNodeException (org.thingsboard.rule.engine.api.TbNodeException)7 Uuids (com.datastax.oss.driver.api.core.uuid.Uuids)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Futures (com.google.common.util.concurrent.Futures)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 IOException (java.io.IOException)3 Callable (java.util.concurrent.Callable)3 Consumer (java.util.function.Consumer)3 ScriptException (javax.script.ScriptException)3 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Assert.assertNotSame (org.junit.Assert.assertNotSame)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Before (org.junit.Before)3 Test (org.junit.Test)3 RunWith (org.junit.runner.RunWith)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)3