@Test public void testResponse_whenHandlerForResponseExist_thenItShouldGenerateResponse() throws Exception { RootResponse expectedResponse = ResponseBuilder.tellResponse("lorem ipsum"); String expectedIntent = "INTENT"; RequestHandler.Factory requestHandlerFactory = mock(RequestHandler.Factory.class); RequestHandler requestHandler = mock(RequestHandler.class); assistantActions = new AssistantActions.Builder(responseHandlerMock) .addRequestHandlerFactory(expectedIntent, requestHandlerFactory) .build(); RootRequest expectedRootRequest = new RootRequest(); expectedRootRequest.inputs = new ArrayList<>(); Inputs input = new Inputs(); input.intent = expectedIntent; expectedRootRequest.inputs.add(input); when(requestHandlerFactory.create(expectedRootRequest)).thenReturn(requestHandler); when(requestHandler.getResponse()).thenReturn(expectedResponse); assistantActions.handleRequest(expectedRootRequest); verify(requestHandler).getResponse(); verify(responseHandlerMock).onResponse(expectedResponse); }
public void handleRequest(RootRequest rootRequest) { responseHandler.onPrepareContentType(ActionsConfig.HTTP_CONTENT_TYPE_JSON); responseHandler.onPrepareResponseHeaders(ActionsConfig.RESPONSE_HEADERS); String actionIntent = AssistantUtils.getActionIntent(rootRequest); if (actionIntent != null && requestHandlersFactories.containsKey(actionIntent)) { RequestHandler requestHandler = requestHandlersFactories.get(actionIntent).create(rootRequest); responseHandler.onResponse(requestHandler.getResponse()); } else { responseHandler.onResponse(ResponseBuilder.tellResponse(ActionsConfig.ERROR_MESSAGE)); } }
AssistantActions { public void handleRequest(RootRequest rootRequest) { responseHandler.onPrepareContentType(ActionsConfig.HTTP_CONTENT_TYPE_JSON); responseHandler.onPrepareResponseHeaders(ActionsConfig.RESPONSE_HEADERS); String actionIntent = AssistantUtils.getActionIntent(rootRequest); if (actionIntent != null && requestHandlersFactories.containsKey(actionIntent)) { RequestHandler requestHandler = requestHandlersFactories.get(actionIntent).create(rootRequest); responseHandler.onResponse(requestHandler.getResponse()); } else { responseHandler.onResponse(ResponseBuilder.tellResponse(ActionsConfig.ERROR_MESSAGE)); } } }
AssistantActions { public void handleRequest(RootRequest rootRequest) { responseHandler.onPrepareContentType(ActionsConfig.HTTP_CONTENT_TYPE_JSON); responseHandler.onPrepareResponseHeaders(ActionsConfig.RESPONSE_HEADERS); String actionIntent = AssistantUtils.getActionIntent(rootRequest); if (actionIntent != null && requestHandlersFactories.containsKey(actionIntent)) { RequestHandler requestHandler = requestHandlersFactories.get(actionIntent).create(rootRequest); responseHandler.onResponse(requestHandler.getResponse()); } else { responseHandler.onResponse(ResponseBuilder.tellResponse(ActionsConfig.ERROR_MESSAGE)); } } AssistantActions(ResponseHandler responseHandler,
                     Map<String, RequestHandler.Factory> requestHandlersFactories); }
AssistantActions { public void handleRequest(RootRequest rootRequest) { responseHandler.onPrepareContentType(ActionsConfig.HTTP_CONTENT_TYPE_JSON); responseHandler.onPrepareResponseHeaders(ActionsConfig.RESPONSE_HEADERS); String actionIntent = AssistantUtils.getActionIntent(rootRequest); if (actionIntent != null && requestHandlersFactories.containsKey(actionIntent)) { RequestHandler requestHandler = requestHandlersFactories.get(actionIntent).create(rootRequest); responseHandler.onResponse(requestHandler.getResponse()); } else { responseHandler.onResponse(ResponseBuilder.tellResponse(ActionsConfig.ERROR_MESSAGE)); } } AssistantActions(ResponseHandler responseHandler,
                     Map<String, RequestHandler.Factory> requestHandlersFactories); void handleRequest(RootRequest rootRequest); }
AssistantActions { public void handleRequest(RootRequest rootRequest) { responseHandler.onPrepareContentType(ActionsConfig.HTTP_CONTENT_TYPE_JSON); responseHandler.onPrepareResponseHeaders(ActionsConfig.RESPONSE_HEADERS); String actionIntent = AssistantUtils.getActionIntent(rootRequest); if (actionIntent != null && requestHandlersFactories.containsKey(actionIntent)) { RequestHandler requestHandler = requestHandlersFactories.get(actionIntent).create(rootRequest); responseHandler.onResponse(requestHandler.getResponse()); } else { responseHandler.onResponse(ResponseBuilder.tellResponse(ActionsConfig.ERROR_MESSAGE)); } } AssistantActions(ResponseHandler responseHandler,
                     Map<String, RequestHandler.Factory> requestHandlersFactories); void handleRequest(RootRequest rootRequest);  }