Node nodeDetails

This commit is contained in:
Yuriy Lytvynchuk 2022-08-09 10:44:45 +03:00
parent ef28b19f80
commit 0e9dc6a19e
2 changed files with 4 additions and 24 deletions

View File

@ -36,7 +36,8 @@ import java.util.stream.Collectors;
name = "delete attributes", name = "delete attributes",
configClazz = TbMsgDeleteAttributesConfiguration.class, configClazz = TbMsgDeleteAttributesConfiguration.class,
nodeDescription = "Delete attributes for Message Originator.", nodeDescription = "Delete attributes for Message Originator.",
nodeDetails = "Allowed scope parameter values: <b>SERVER/CLIENT/SHARED</b>. Will try to remove attributes by keys from the list", nodeDetails = "Attempt to remove attributes by selected keys. If msg originator doesn't have an attribute with " +
" a key selected in the configuration, it will be ignored.",
uiResources = {"static/rulenode/rulenode-core-config.js"}, uiResources = {"static/rulenode/rulenode-core-config.js"},
configDirective = "tbActionNodeDeleteAttributesConfig", configDirective = "tbActionNodeDeleteAttributesConfig",
icon = "remove_circle" icon = "remove_circle"
@ -58,7 +59,7 @@ public class TbMsgDeleteAttributes implements TbNode {
.filter(StringUtils::isNotBlank) .filter(StringUtils::isNotBlank)
.collect(Collectors.toList()); .collect(Collectors.toList());
if (keysToDelete.isEmpty()) { if (keysToDelete.isEmpty()) {
ctx.tellFailure(msg, new RuntimeException("Selected keys patterns have invalid values!")); ctx.tellSuccess(msg);
} else { } else {
ctx.getTelemetryService().deleteAndNotify(ctx.getTenantId(), msg.getOriginator(), config.getScope(), keysToDelete, new TelemetryNodeCallback(ctx, msg)); ctx.getTelemetryService().deleteAndNotify(ctx.getTenantId(), msg.getOriginator(), config.getScope(), keysToDelete, new TelemetryNodeCallback(ctx, msg));
} }

View File

@ -67,7 +67,7 @@ public class TbMsgDeleteAttributesTest {
callback = mock(TbMsgCallback.class); callback = mock(TbMsgCallback.class);
ctx = mock(TbContext.class); ctx = mock(TbContext.class);
config = new TbMsgDeleteAttributesConfiguration().defaultConfiguration(); config = new TbMsgDeleteAttributesConfiguration().defaultConfiguration();
config.setKeys(List.of("${TestAttribute_1}", "$[TestAttribute_2]", "$[TestAttribute_3]")); config.setKeys(List.of("${TestAttribute_1}", "$[TestAttribute_2]", "$[TestAttribute_3]", "TestAttribute_4"));
nodeConfiguration = new TbNodeConfiguration(mapper.valueToTree(config)); nodeConfiguration = new TbNodeConfiguration(mapper.valueToTree(config));
node = spy(new TbMsgDeleteAttributes()); node = spy(new TbMsgDeleteAttributes());
node.init(ctx, nodeConfiguration); node.init(ctx, nodeConfiguration);
@ -116,25 +116,4 @@ public class TbMsgDeleteAttributesTest {
verify(ctx, never()).tellFailure(any(), any()); verify(ctx, never()).tellFailure(any(), any());
verify(telemetryService, times(1)).deleteAndNotify(any(), any(), anyString(), anyList(), any()); verify(telemetryService, times(1)).deleteAndNotify(any(), any(), anyString(), anyList(), any());
} }
@Test
void giveInvalidScope_whenOnMsg_thenTellFailure() throws Exception {
final TbMsgMetaData metaData = new TbMsgMetaData();
final String data = "{\"TestAttribute_1\": \"\", \"TestAttribute_2\": \"\"}";
config.setKeys(List.of("$[TestAttribute_1]", "$[TestAttribute_2]"));
nodeConfiguration = new TbNodeConfiguration(mapper.valueToTree(config));
node.init(ctx, nodeConfiguration);
TbMsg msg = TbMsg.newMsg("POST_ATTRIBUTES_REQUEST", deviceId, metaData, data, callback);
node.onMsg(ctx, msg);
ArgumentCaptor<TbMsg> newMsgCaptor = ArgumentCaptor.forClass(TbMsg.class);
ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class);
verify(ctx, never()).tellSuccess(any());
verify(ctx, times(1)).tellFailure(newMsgCaptor.capture(), exceptionCaptor.capture());
assertThat(newMsgCaptor.getValue()).isSameAs(msg);
assertThat(exceptionCaptor.getValue()).isInstanceOf(RuntimeException.class);
}
} }