Tell failure if originator is not a device

This commit is contained in:
Dmytro Skarzhynets 2024-02-14 14:01:20 +02:00
parent f5a7fe73ab
commit 094cff6174
2 changed files with 11 additions and 3 deletions

View File

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

View File

@ -263,7 +263,12 @@ public class TbDeviceStateNodeTest {
node.onMsg(ctxMock, msg); node.onMsg(ctxMock, msg);
// THEN // 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(); then(ctxMock).shouldHaveNoMoreInteractions();
} }