EndpointResponseStrategy implements IResponseStrategy { @Override public void sendResponse(final IObject environment) throws ResponseException { try { IFieldName responseFieldName = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "response"); IFieldName contextFieldName = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "context"); IFieldName httpResponseIsSentFieldName = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "sendResponseOnChainEnd"); IFieldName endpointName = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "endpointName"); IFieldName channelFieldName = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "channel"); IObject responseIObject = (IObject) environment.getValue(responseFieldName); IObject contextIObject = (IObject) environment.getValue(contextFieldName); IChannelHandler channelHandler = (IChannelHandler) contextIObject.getValue(channelFieldName); IResponse response = IOC.resolve(Keys.getOrAdd(IResponse.class.getCanonicalName())); IResponseContentStrategy contentStrategy = IOC.resolve(Keys.getOrAdd(IResponseContentStrategy.class.getCanonicalName()), environment); contentStrategy.setContent(responseIObject, response); IResponseSender sender = IOC.resolve(Keys.getOrAdd(IResponseSender.class.getCanonicalName()), IOC.resolve(Keys.getOrAdd("http_request_key_for_response_sender"), environment), contextIObject.getValue(endpointName)); sender.send(response, environment, channelHandler); contextIObject.setValue(httpResponseIsSentFieldName, true); } catch (Exception e) { throw new ResponseException(e); } }  @Override void sendResponse(final IObject environment);  }
@Test public void Should_sendResponse() throws Exception { new EndpointResponseStrategy().sendResponse(environment); verify(responseContentStrategy).setContent(responseObj, response); verify(responseSender).send(same(response), same(environment), same(channelHandler)); assertEquals(Boolean.TRUE, context.getValue( IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "sendResponseOnChainEnd"))); }
@Test(expected = ResponseException.class) public void Should_wrapExceptions() throws Exception { doThrow(ResponseSendingException.class).when(responseSender).send(any(), any(), any()); new EndpointResponseStrategy().sendResponse(environment); }