MessageBusHandler implements IMessageBusHandler { @Override public void handle(final IObject message) throws MessageBusHandlerException { handle0(message, this.chain); } MessageBusHandler(final IQueue<ITask> taskQueue, final int stackDepth, final IReceiverChain receiverChain, final IAction<IObject> finalAction); @Override void handle(final IObject message); @Override void handle(final IObject message, final Object chainName); @Override void handleForReply(final IObject message, final Object replyToChainName); @Override void handleForReply(final IObject message, final Object chainName, final Object replyToChainName);  }
@Test public void checkMessageHandle() throws Exception { IResolveDependencyStrategy sequenceStrategy = mock(IResolveDependencyStrategy.class); IOC.register( IOC.resolve(IOC.getKeyForKeyStorage(), "info.smart_tools.smartactors.message_processing_interfaces.message_processing.IMessageProcessingSequence"), sequenceStrategy ); IResolveDependencyStrategy messageProcessorStrategy = mock(IResolveDependencyStrategy.class); IOC.register( IOC.resolve(IOC.getKeyForKeyStorage(), "info.smart_tools.smartactors.message_processing_interfaces.message_processing.IMessageProcessor"), messageProcessorStrategy ); IResolveDependencyStrategy iobjectStrategy = mock(IResolveDependencyStrategy.class); IOC.register( IOC.resolve(IOC.getKeyForKeyStorage(), "info.smart_tools.smartactors.iobject.iobject.IObject"), iobjectStrategy ); IMessageProcessingSequence sequence = mock(IMessageProcessingSequence.class); when(sequenceStrategy.resolve(1, this.chain)).thenReturn(sequence); IMessageProcessor processor = mock(IMessageProcessor.class); when(messageProcessorStrategy.resolve(this.queue, sequence)).thenReturn(processor); IObject context = mock(IObject.class); when(iobjectStrategy.resolve()).thenReturn(context); IObject message = mock(IObject.class); IMessageBusHandler handler = new MessageBusHandler(this.queue, 1, this.chain, mock(IAction.class)); handler.handle(message); verify(context, times(1)).setValue(eq(new FieldName("responseStrategy")), same(nullResponseStrategy)); verify(sequenceStrategy, times(1)).resolve(1, this.chain); verify(messageProcessorStrategy, times(1)).resolve(this.queue, sequence); verify(iobjectStrategy, times(1)).resolve(); verify(processor, times(1)).process(message, context); }
@Test (expected = MessageBusHandlerException.class) public void checkMessageBusHandlerExceptionOnErrorInHandle() throws Exception { IMessageBusHandler handler = new MessageBusHandler(this.queue, 1, this.chain, mock(IAction.class)); handler.handle(null); fail(); }
@Test public void checkMessageHandleWithSpecificChain() throws Exception { IResolveDependencyStrategy sequenceStrategy = mock(IResolveDependencyStrategy.class); IOC.register( IOC.resolve(IOC.getKeyForKeyStorage(), "info.smart_tools.smartactors.message_processing_interfaces.message_processing.IMessageProcessingSequence"), sequenceStrategy ); IResolveDependencyStrategy messageProcessorStrategy = mock(IResolveDependencyStrategy.class); IOC.register( IOC.resolve(IOC.getKeyForKeyStorage(), "info.smart_tools.smartactors.message_processing_interfaces.message_processing.IMessageProcessor"), messageProcessorStrategy ); IResolveDependencyStrategy iobjectStrategy = mock(IResolveDependencyStrategy.class); IOC.register( IOC.resolve(IOC.getKeyForKeyStorage(), "info.smart_tools.smartactors.iobject.iobject.IObject"), iobjectStrategy ); IResolveDependencyStrategy chainIdStrategy = mock(IResolveDependencyStrategy.class); IOC.register( IOC.resolve(IOC.getKeyForKeyStorage(), "chain_id_from_map_name"), chainIdStrategy ); IResolveDependencyStrategy chainStorageStrategy = mock(IResolveDependencyStrategy.class); IOC.register( IOC.resolve(IOC.getKeyForKeyStorage(), IChainStorage.class.getCanonicalName()), chainStorageStrategy ); Object chainId = mock(Object.class); Object chainName = mock(Object.class); IChainStorage storage = mock(IChainStorage.class); IReceiverChain chain = mock(IReceiverChain.class); when(chainIdStrategy.resolve(chainName)).thenReturn(chainId); when(chainStorageStrategy.resolve()).thenReturn(storage); when(storage.resolve(chainId)).thenReturn(chain); IMessageProcessingSequence sequence = mock(IMessageProcessingSequence.class); when(sequenceStrategy.resolve(1, chain)).thenReturn(sequence); IMessageProcessor processor = mock(IMessageProcessor.class); when(messageProcessorStrategy.resolve(this.queue, sequence)).thenReturn(processor); IObject context = mock(IObject.class); when(iobjectStrategy.resolve()).thenReturn(context); IObject message = mock(IObject.class); IMessageBusHandler handler = new MessageBusHandler(this.queue, 1, this.chain, mock(IAction.class)); handler.handle(message, chainName); verify(sequenceStrategy, times(1)).resolve(1, chain); verify(messageProcessorStrategy, times(1)).resolve(this.queue, sequence); verify(iobjectStrategy, times(1)).resolve(); verify(processor, times(1)).process(message, context); verify(chainIdStrategy, times(1)).resolve(chainName); verify(chainStorageStrategy, times(1)).resolve(); verify(storage, times(1)).resolve(chainId); }
@Test (expected = MessageBusHandlerException.class) public void checkMessageBusHandlerExceptionOnErrorInHandleWithSpecificChain() throws Exception { IMessageBusHandler handler = new MessageBusHandler(this.queue, 1, this.chain, mock(IAction.class)); handler.handle(null, null); fail(); }