TbChangeOriginatorNode extends TbAbstractTransformNode { @Override public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { this.config = TbNodeUtils.convert(configuration, TbChangeOriginatorNodeConfiguration.class); validateConfig(config); setConfig(config); }  @Override void init(TbContext ctx, TbNodeConfiguration configuration); @Override void destroy();  }
@Test public void originatorCanBeChangedToCustomerId() throws TbNodeException { init(); AssetId assetId = new AssetId(UUIDs.timeBased()); CustomerId customerId = new CustomerId(UUIDs.timeBased()); Asset asset = new Asset(); asset.setCustomerId(customerId); RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased()); RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); TbMsg msg = new TbMsg(UUIDs.timeBased(), "ASSET", assetId, new TbMsgMetaData(), "{}", ruleChainId, ruleNodeId, 0L); when(ctx.getAssetService()).thenReturn(assetService); when(assetService.findAssetByIdAsync(assetId)).thenReturn(Futures.immediateFuture(asset)); node.onMsg(ctx, msg); ArgumentCaptor<TbMsg> msgCaptor = ArgumentCaptor.forClass(TbMsg.class); ArgumentCaptor<String> typeCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<EntityId> originatorCaptor = ArgumentCaptor.forClass(EntityId.class); ArgumentCaptor<TbMsgMetaData> metadataCaptor = ArgumentCaptor.forClass(TbMsgMetaData.class); ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class); verify(ctx).transformMsg(msgCaptor.capture(), typeCaptor.capture(), originatorCaptor.capture(), metadataCaptor.capture(), dataCaptor.capture()); assertEquals(customerId, originatorCaptor.getValue()); }
@Test public void newChainCanBeStarted() throws TbNodeException { init(); AssetId assetId = new AssetId(UUIDs.timeBased()); CustomerId customerId = new CustomerId(UUIDs.timeBased()); Asset asset = new Asset(); asset.setCustomerId(customerId); RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased()); RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); TbMsg msg = new TbMsg(UUIDs.timeBased(), "ASSET", assetId, new TbMsgMetaData(), "{}", ruleChainId, ruleNodeId, 0L); when(ctx.getAssetService()).thenReturn(assetService); when(assetService.findAssetByIdAsync(assetId)).thenReturn(Futures.immediateFuture(asset)); node.onMsg(ctx, msg); ArgumentCaptor<TbMsg> msgCaptor = ArgumentCaptor.forClass(TbMsg.class); ArgumentCaptor<String> typeCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<EntityId> originatorCaptor = ArgumentCaptor.forClass(EntityId.class); ArgumentCaptor<TbMsgMetaData> metadataCaptor = ArgumentCaptor.forClass(TbMsgMetaData.class); ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class); verify(ctx).transformMsg(msgCaptor.capture(), typeCaptor.capture(), originatorCaptor.capture(), metadataCaptor.capture(), dataCaptor.capture()); assertEquals(customerId, originatorCaptor.getValue()); }
@Test public void exceptionThrownIfCannotFindNewOriginator() throws TbNodeException { init(); AssetId assetId = new AssetId(UUIDs.timeBased()); CustomerId customerId = new CustomerId(UUIDs.timeBased()); Asset asset = new Asset(); asset.setCustomerId(customerId); RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased()); RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); TbMsg msg = new TbMsg(UUIDs.timeBased(), "ASSET", assetId, new TbMsgMetaData(), "{}", ruleChainId, ruleNodeId, 0L); when(ctx.getAssetService()).thenReturn(assetService); when(assetService.findAssetByIdAsync(assetId)).thenReturn(Futures.immediateFuture(null)); node.onMsg(ctx, msg); verify(ctx).tellNext(same(msg), same(FAILURE)); }