ConditionChainChoiceStrategy implements IChainChoiceStrategy { @Override public Object chooseChain(final IMessageProcessor messageProcessor) throws ChainChoiceException { try { if ((Boolean) messageProcessor.getMessage().getValue(chainConditionFN)) { Object name = messageProcessor.getSequence().getCurrentReceiverArguments().getValue(trueChainFN); return IOC.resolve(Keys.getOrAdd("chain_id_from_map_name"), name); } Object name = messageProcessor.getSequence().getCurrentReceiverArguments().getValue(falseChainFN); return IOC.resolve(Keys.getOrAdd("chain_id_from_map_name"), name); } catch (Exception e) { throw new ChainChoiceException("Could not execute condition chain choice strategy."); } } ConditionChainChoiceStrategy(); @Override Object chooseChain(final IMessageProcessor messageProcessor);  }
@Test public void Should_chooseChainConditionIsTrue() throws Exception { IObject messageArgs = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"), "{'chainCondition': true}".replace('\'', '"')); when(messageProcessorMock.getMessage()).thenReturn(messageArgs); IChainChoiceStrategy strategy = new ConditionChainChoiceStrategy(); assertSame(trueId, strategy.chooseChain(messageProcessorMock)); }
@Test public void Should_chooseChainConditionIsFalse() throws Exception { IObject messageArgs = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"), "{'chainCondition': false}".replace('\'', '"')); when(messageProcessorMock.getMessage()).thenReturn(messageArgs); IChainChoiceStrategy strategy = new ConditionChainChoiceStrategy(); assertSame(falseId, strategy.chooseChain(messageProcessorMock)); }
@Test(expected = ChainChoiceException.class) public void Should_wrapExceptionThrownByIOC() throws Exception { when(chainIdStrategy.resolve(any())).thenThrow(ResolveDependencyStrategyException.class); IChainChoiceStrategy strategy = new ConditionChainChoiceStrategy(); strategy.chooseChain(messageProcessorMock); }