Browse Source

Tell failure if originator is not a device

pull/9030/head
Dmytro Skarzhynets 2 years ago
parent
commit
094cff6174
  1. 7
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbDeviceStateNode.java
  2. 7
      rule-engine/rule-engine-components/src/test/java/org/thingsboard/rule/engine/action/TbDeviceStateNodeTest.java

7
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbDeviceStateNode.java

@ -98,8 +98,11 @@ public class TbDeviceStateNode implements TbNode {
return;
}
if (!EntityType.DEVICE.equals(msg.getOriginator().getEntityType())) {
ctx.tellSuccess(msg);
EntityType originatorEntityType = msg.getOriginator().getEntityType();
if (!EntityType.DEVICE.equals(originatorEntityType)) {
ctx.tellFailure(msg, new IllegalArgumentException(
"Unsupported originator entity type: [" + originatorEntityType + "]. Only DEVICE entity type is supported."
));
return;
}

7
rule-engine/rule-engine-components/src/test/java/org/thingsboard/rule/engine/action/TbDeviceStateNodeTest.java

@ -263,7 +263,12 @@ public class TbDeviceStateNodeTest {
node.onMsg(ctxMock, msg);
// THEN
then(ctxMock).should().tellSuccess(msg);
var exceptionCaptor = ArgumentCaptor.forClass(Exception.class);
then(ctxMock).should().tellFailure(eq(msg), exceptionCaptor.capture());
assertThat(exceptionCaptor.getValue())
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Unsupported originator entity type: [" + unsupportedType + "]. Only DEVICE entity type is supported.");
then(ctxMock).shouldHaveNoMoreInteractions();
}

Loading…
Cancel
Save