ResponseSenderActor { public void sendResponse(final ResponseSenderMessage message) throws ResponseSenderActorException { IObjectWrapper messageWrapper = (IObjectWrapper) message; IFieldName responseFieldName = null; try { responseFieldName = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "response"); IObject responseIObject = messageWrapper.getEnvironmentIObject(responseFieldName); IObject environment = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject")); 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 configFieldName = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "config"); IFieldName messageFieldName = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "message"); IFieldName endpointName = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "endpointName"); environment.setValue(responseFieldName, responseIObject); environment.setValue(configFieldName, messageWrapper.getEnvironmentIObject(configFieldName)); environment.setValue(contextFieldName, messageWrapper.getEnvironmentIObject(contextFieldName)); environment.setValue(messageFieldName, messageWrapper.getEnvironmentIObject(messageFieldName)); IFieldName channelFieldName = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "channel"); IChannelHandler channelHandler = (IChannelHandler) messageWrapper.getEnvironmentIObject(contextFieldName).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), messageWrapper.getEnvironmentIObject(contextFieldName).getValue(endpointName)); sender.send(response, environment, channelHandler); messageWrapper.getEnvironmentIObject(contextFieldName).setValue(httpResponseIsSentFieldName, true); } catch (Exception e) { throw new ResponseSenderActorException(e); } } ResponseSenderActor(); void sendResponse(final ResponseSenderMessage message);  }
@Test public void testResponseSenderActorShouldHandleSend() throws InvalidArgumentException, SerializeException, ReadValueException, ResolutionException, InvalidArgumentException, ResponseSenderActorException, ChangeValueException, ResponseSendingException { IObject environment = new DSObject("{\"config\": null, \"message\": null, \"response\": {\"hello\":\"world\"}}"); IObject context = new DSObject(); context.setValue(new FieldName("channel"), null); environment.setValue(new FieldName("context"), context); Wrapper wrapper = new Wrapper(); wrapper.init(environment); ResponseSenderActor senderActor = new ResponseSenderActor(); senderActor.sendResponse(wrapper); verify(responseSender, times(1)).send(any(IResponse.class), any(IObject.class), any(IChannelHandler.class)); }