MessageProcessingSequenceRecoveryStrategy implements IResolveDependencyStrategy { @Override public <T> T resolve(final Object... args) throws ResolveDependencyStrategyException { try { IObject dump = (IObject) args[0]; int maxDepth = ((Number) dump.getValue(maxDepthFieldName)).intValue(); Iterator stepStack = ((Collection) dump.getValue(stepsStackFieldName)).iterator(); Iterator chainsStack = ((Collection) dump.getValue(chainsStackFieldName)).iterator(); IObject chainsDump = (IObject) dump.getValue(chainsDumpFieldName); IChainStorage storage = new ChainStorageDecorator( IOC.resolve(Keys.getOrAdd(IChainStorage.class.getCanonicalName())), chainsDump); Object mainChainId = IOC.resolve(Keys.getOrAdd("chain_id_from_map_name"), chainsStack.next()); int mainChainPos = ((Number) stepStack.next()).intValue(); IMessageProcessingSequence sequence = new MessageProcessingSequence(maxDepth, storage.resolve(mainChainId)); sequence.goTo(0, mainChainPos + 1); int level = 1; while (stepStack.hasNext()) { Object chainId = IOC.resolve(Keys.getOrAdd("chain_id_from_map_name"), chainsStack.next()); int pos = ((Number) stepStack.next()).intValue(); sequence.callChain(storage.resolve(chainId)); sequence.goTo(level++, pos + 1); } sequence.next(); return (T) sequence; } catch (ResolutionException | ReadValueException | InvalidArgumentException | ClassCastException | ChainNotFoundException | NestedChainStackOverflowException e) { throw new ResolveDependencyStrategyException(e); } } MessageProcessingSequenceRecoveryStrategy(); @Override T resolve(final Object... args);  }
@Test public void Should_recoverSequenceFromDumpRestoringDumpedChains() throws Exception { IReceiverChain chainA = mock(IReceiverChain.class), chainB = mock(IReceiverChain.class); IObject seqDump = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"), ("{" + "'maxDepth':3," + "'chainsStack':['a','b','a']," + "'stepsStack':[1,4,2]," + "'chainsDump':{" + " 'a': {'this-is':'chain-a dump'}" + "}" + "}").replace('\'','"')); when(chainStorageMock.resolve("b")).thenReturn(chainB); when(chainStorageMock.resolve("a")).thenThrow(ChainNotFoundException.class); when(chainResolutionStrategyMock.resolve( eq("a"), same(((IObject) seqDump .getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "chainsDump"))) .getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "a"))), any(), same(routerMock) )).thenReturn(chainA); when(chainA.get(0)).thenReturn(mock(IMessageReceiver.class)); when(chainA.get(1)).thenReturn(mock(IMessageReceiver.class)); when(chainA.get(2)).thenReturn(mock(IMessageReceiver.class)); when(chainA.get(3)).thenReturn(mock(IMessageReceiver.class)); IMessageProcessingSequence sequence = new MessageProcessingSequenceRecoveryStrategy().resolve(seqDump); assertNotNull(sequence); assertEquals(2, sequence.getCurrentLevel()); assertEquals(3, sequence.getStepAtLevel(2)); assertEquals(4, sequence.getStepAtLevel(1)); assertEquals(1, sequence.getStepAtLevel(0)); try { sequence.callChain(chainA); fail(); } catch (NestedChainStackOverflowException ok) {} }