MessageBusResponseStrategy implements IResponseStrategy { @Override public void sendResponse(IObject environment) throws ResponseException { try { IObject context = (IObject) environment.getValue(contextFieldName); IObject response = (IObject) environment.getValue(responseFieldName); Object replyChainId = context.getValue(replyChainFieldName); String sResponse = response.serialize(); response = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"), sResponse); MessageBus.send(response, replyChainId); context.setValue(responseStrategyFieldName, nullResponseStrategy); } catch (ReadValueException | ChangeValueException | InvalidArgumentException | SendingMessageException | SerializeException | ResolutionException e) { throw new ResponseException(e); } } MessageBusResponseStrategy(); @Override void sendResponse(IObject environment);  }
@Test public void Should_sendResponseAndSetResponseStrategyToNullImplementation() throws Exception { strategy.sendResponse(environment); ArgumentCaptor<IObject> responseCaptor = ArgumentCaptor.forClass(IObject.class); verify(messageBusHandlerMock).handle(responseCaptor.capture(), same(replyChainId)); assertEquals(Boolean.TRUE, responseCaptor.getValue().getValue( IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "itIsAResponse") )); assertSame( nullResponseStrategyMock, context.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "responseStrategy"))); }
@Test(expected = ResponseException.class) public void Should_wrapExceptions() throws Exception { doThrow(SendingMessageException.class).when(messageBusHandlerMock).handle(any(), any()); strategy.sendResponse(environment); }