ReSendToChainRecoverStrategy implements IRecoverStrategy { @Override public void reSend(final IObject state) throws RecoverStrategyExecutionException { try { String sMessage = ((IObject) state.getValue(messageFieldName)).serialize(); IObject messageClone = IOC.resolve(Keys.getOrAdd(IObject.class.getName()), sMessage); IObject checkpointStatus = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject")); checkpointStatus.setValue(responsibleCheckpointIdFieldName, state.getValue(responsibleCheckpointIdFieldName)); checkpointStatus.setValue(checkpointEntryIdFieldName, state.getValue(entryIdFieldName)); checkpointStatus.setValue(prevCheckpointEntryIdFieldName, state.getValue(prevCheckpointEntryIdFieldName)); checkpointStatus.setValue(prevCheckpointIdFieldName, state.getValue(prevCheckpointIdFieldName)); messageClone.setValue(checkpointStatusFieldName, checkpointStatus); MessageBus.send(messageClone, chainChoiceStrategy.chooseRecoveryChain(state)); } catch (ResolutionException | ReadValueException | InvalidArgumentException | ChangeValueException | SendingMessageException | SerializeException e) { throw new RecoverStrategyExecutionException("Error occurred re-sending a message.", e); } } ReSendToChainRecoverStrategy(final IRecoveryChainChoiceStrategy chainChoiceStrategy); @Override void init(final IObject state, final IObject args, final IMessageProcessor processor); @Override void reSend(final IObject state);  }
@Test public void Should_reSendMessageToChainChosenByIRCCS() throws Exception { IObject state = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"), ("{" + "'responsibleCheckpointId':'rcid'," + "'entryId':'eid'," + "'prevCheckpointEntryId':'pceid'," + "'prevCheckpointId':'pcid'," + "'message':{'is-a-message':true}" + "}").replace('\'','"')); IMessageBusHandler messageBusHandler = mock(IMessageBusHandler.class); ScopeProvider.getCurrentScope().setValue(MessageBus.getMessageBusKey(), messageBusHandler); Object chainId = new Object(); when(recoveryChainChoiceStrategy.chooseRecoveryChain(same(state))).thenReturn(chainId); new ReSendToChainRecoverStrategy(recoveryChainChoiceStrategy).reSend(state); ArgumentCaptor<IObject> mc = ArgumentCaptor.forClass(IObject.class); verify(messageBusHandler).handle(mc.capture(), same(chainId)); assertNotNull(mc.getValue()); assertEquals(true, mc.getValue().getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "is-a-message"))); IObject checkpointStatus = (IObject) mc.getValue().getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "checkpointStatus")); assertNotNull(checkpointStatus); assertEquals("rcid", checkpointStatus.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "responsibleCheckpointId"))); assertEquals("eid", checkpointStatus.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "checkpointEntryId"))); assertEquals("pceid", checkpointStatus.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "prevCheckpointEntryId"))); assertEquals("pcid", checkpointStatus.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "prevCheckpointId"))); }