TriggerWordRouter implements Router { @Override public Agent[] route(Request request) { String requestText = request.getText().toLowerCase(); String[] tokens = tokenizer.tokenize(requestText); if (tokens.length == 0) { return new Agent[0]; } Agent agent = agentMap.get(tokens[0]); if (agent != null) { return new Agent[]{agent}; } else { return new Agent[0]; } } TriggerWordRouter(RouterAgentConfig agentsConfig); @Override Agent[] route(Request request); @Override Agent[] getAgents(); static final String TRIGGERS; }
@Test public void testRouting() { Agent agent = mock(Agent.class); MultiValuedMap params = new MultiValuedMap(); params.addString(TriggerWordRouter.TRIGGERS, "twitter"); RouterAgentConfig config = RouterAgentConfig.create().add(agent, params); Router router = new TriggerWordRouter(config); Agent agents[] = router.route(new Request("twitter hello world")); Agent expected[] = new Agent[]{agent}; assertArrayEquals(expected, agents); }
@Test public void testRoutingWithNoAgentMatch() { Agent agent = mock(Agent.class); MultiValuedMap params = new MultiValuedMap(); params.addString(TriggerWordRouter.TRIGGERS, "twitter"); RouterAgentConfig config = RouterAgentConfig.create().add(agent, params); Router router = new TriggerWordRouter(config); Agent agents[] = router.route(new Request("film hello world")); Agent expected[] = new Agent[0]; assertArrayEquals(expected, agents); }
@Test public void testRoutingWithEmptyRequest() { Router router = new TriggerWordRouter(RouterAgentConfig.create()); Agent agents[] = router.route(new Request("")); Agent expected[] = new Agent[0]; assertArrayEquals(expected, agents); }