DuckDuckGoAgent extends AbstractAgent { @Override public AgentResponse process(AgentRequest request) { logger.debug("Handling the request: " + request.getText()); String requestText = request.getText(); String entityText = extractEntity(requestText); String data = requestData(entityText); return createResponse(data); } DuckDuckGoAgent(HttpClient client); @Override AgentResponse process(AgentRequest request);  }
@Test public void testGetGoodResponse() { String query = "Barack Obama"; String jsonData = FileReader.getFileAsString("duckduckgo/barack_obama.json"); HttpClient client = new FakeHttpClient(new FakeHttpResponse(jsonData)); Agent agent = new DuckDuckGoAgent(client); AgentResponse response = agent.process(new AgentRequest(query)); assertTrue(response.isSuccess()); assertTrue(response.getText().startsWith("Barack Hussein Obama II is an American politician")); }
@Test public void testWithFullSentence() { String jsonData = FileReader.getFileAsString("duckduckgo/barack_obama.json"); HttpClient client = new FakeHttpClient(new FakeHttpResponse(jsonData)); Agent agent = new DuckDuckGoAgent(client); AgentResponse response = agent.process(new AgentRequest("Who is Barack Obama?")); assertTrue(response.isSuccess()); assertTrue(response.getText().startsWith("Barack Hussein Obama II is an American politician")); }
@Test public void testGetDisambiguationResponse() { String query = "Obama"; String jsonData = FileReader.getFileAsString("duckduckgo/obama.json"); HttpClient client = new FakeHttpClient(new FakeHttpResponse(jsonData)); Agent agent = new DuckDuckGoAgent(client); AgentResponse response = agent.process(new AgentRequest(query)); assertEquals(ResponseStatus.Code.AGENT_DID_NOT_KNOW_ANSWER, response.getStatus().getCode()); }
@Test public void testGetEmptyResponse() { String query = "zergblah"; String jsonData = FileReader.getFileAsString("duckduckgo/zergblah.json"); HttpClient client = new FakeHttpClient(new FakeHttpResponse(jsonData)); Agent agent = new DuckDuckGoAgent(client); AgentResponse response = agent.process(new AgentRequest(query)); assertEquals(ResponseStatus.Code.AGENT_DID_NOT_KNOW_ANSWER, response.getStatus().getCode()); }