From 57a913aa004f76f7bb7b9ea07e836c174f58a558 Mon Sep 17 00:00:00 2001 From: Yuriy Lytvynchuk Date: Wed, 17 Aug 2022 15:28:15 +0300 Subject: [PATCH] add node details --- .../rule/engine/transform/TbSplitArrayMsgNode.java | 8 ++++---- .../rule/engine/transform/TbSplitArrayMsgNodeTest.java | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/transform/TbSplitArrayMsgNode.java b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/transform/TbSplitArrayMsgNode.java index d6dbc88776..1c682fbf7c 100644 --- a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/transform/TbSplitArrayMsgNode.java +++ b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/transform/TbSplitArrayMsgNode.java @@ -39,9 +39,9 @@ import java.util.concurrent.ExecutionException; name = "split array msg", configClazz = EmptyNodeConfiguration.class, nodeDescription = "Split array message into several msgs", - nodeDetails = "Split the array fetched from the msg body. Returns inner objects of the extracted array as " - + "separate messages via Success chain. If msg data is not a JSON array, " - + "the incoming message is returned", + nodeDetails = "Split the array fetched from the msg body. If the msg data is not a JSON object returns the " + + "incoming message as outbound message with Failure chain, otherwise returns " + + "inner objects of the extracted array as separate messages via Success chain.", icon = "content_copy", configDirective = "tbNodeEmptyConfig" ) @@ -72,7 +72,7 @@ public class TbSplitArrayMsgNode implements TbNode { } } } else { - ctx.tellSuccess(msg); + ctx.tellFailure(msg, new RuntimeException("Msg data is not a JSON Array!")); } } diff --git a/rule-engine/rule-engine-components/src/test/java/org/thingsboard/rule/engine/transform/TbSplitArrayMsgNodeTest.java b/rule-engine/rule-engine-components/src/test/java/org/thingsboard/rule/engine/transform/TbSplitArrayMsgNodeTest.java index a54efad4aa..17bfd1663c 100644 --- a/rule-engine/rule-engine-components/src/test/java/org/thingsboard/rule/engine/transform/TbSplitArrayMsgNodeTest.java +++ b/rule-engine/rule-engine-components/src/test/java/org/thingsboard/rule/engine/transform/TbSplitArrayMsgNodeTest.java @@ -94,15 +94,18 @@ public class TbSplitArrayMsgNodeTest { } @Test - void givenNoArrayMsg_whenOnMsg_thenVerifyOutput() throws Exception { + void givenNoArrayMsg_whenOnMsg_thenFailure() throws Exception { String data = "{\"Attribute_1\":22.5,\"Attribute_2\":10.3}"; JsonNode dataNode = JacksonUtil.toJsonNode(data); TbMsg msg = getTbMsg(deviceId, dataNode.toString()); node.onMsg(ctx, msg); ArgumentCaptor newMsgCaptor = ArgumentCaptor.forClass(TbMsg.class); - verify(ctx, times(1)).tellSuccess(newMsgCaptor.capture()); - verify(ctx, never()).tellFailure(any(), any()); + ArgumentCaptor exceptionCaptor = ArgumentCaptor.forClass(Exception.class); + verify(ctx, never()).tellSuccess(any()); + verify(ctx, times(1)).tellFailure(newMsgCaptor.capture(), exceptionCaptor.capture()); + + assertThat(exceptionCaptor.getValue()).isInstanceOf(RuntimeException.class); TbMsg newMsg = newMsgCaptor.getValue(); assertThat(newMsg).isNotNull();