DrugGroupController extends BaseRestController { @RequestMapping(method = RequestMethod.GET, params = "q") @WSDoc("Gets Drug Groups by name") @ResponseBody() public String getDrugGroupsByName(@RequestParam("q") String query, HttpServletRequest request) throws ResponseException { initDrugGroupController(); List<DrugGroup> allDrugGroup = service.getDrugGroupByName(query); ArrayList results = new ArrayList(); for (DrugGroup drugGroup : allDrugGroup) { SimpleObject obj = new SimpleObject(); obj.add("uuid", drugGroup.getUuid()); obj.add("name", drugGroup.getName()); obj.add("description", drugGroup.getDescription()); results.add(obj); } return gson.toJson(new SimpleObject().add("results", results)); }  void initDrugGroupController(); @RequestMapping(method = RequestMethod.POST) @WSDoc("Save New DrugGroup") @ResponseBody Object createNewDrugGroup(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = "/{uuid}", method = RequestMethod.POST) @WSDoc("Updates an existing drug group") @ResponseBody Object updateDrugGroup(@PathVariable("uuid") String uuid, @RequestBody SimpleObject post,
	        HttpServletRequest request, HttpServletResponse response); @RequestMapping(method = RequestMethod.GET) @WSDoc("Get All Unretired Drug Groups in the system") @ResponseBody() String getAllDrugGroups(HttpServletRequest request, HttpServletResponse response); @RequestMapping(method = RequestMethod.GET, params = "q") @WSDoc("Gets Drug Groups by name") @ResponseBody() String getDrugGroupsByName(@RequestParam("q") String query, HttpServletRequest request); @RequestMapping(value = "/{uuid}", method = RequestMethod.GET) @WSDoc("Gets Drug Groups for the uuid path") @ResponseBody() String getAllDrugGroupByUuid(@PathVariable("uuid") String uuid, HttpServletRequest request); @RequestMapping(value = "/{uuid}", method = RequestMethod.GET, params = "v") @WSDoc("Gets Full representation of Drug Groups for the uuid path") @ResponseBody() String getAllDrugGroupByUuidFull(@PathVariable("uuid") String uuid, @RequestParam("v") String rep,
	        HttpServletRequest request); @RequestMapping(value = "/{uuid}", method = RequestMethod.DELETE, params = "!purge") @WSDoc("Retires the Drug Group") @ResponseBody Object retireDrugGroup(@PathVariable("uuid") String uuid,
	        @RequestParam(value = "reason", defaultValue = "web service call") String reason, HttpServletRequest request,
	        HttpServletResponse response); @RequestMapping(value = "/{uuid}", method = RequestMethod.DELETE, params = "purge") @ResponseBody Object purgeDrugGroup(@PathVariable("uuid") String uuid, HttpServletRequest request, HttpServletResponse response);  }
@Test public void getDrugGroupsByName_shouldReturnNoResultsIfThereAreNoMatchingDrugGroup() throws Exception { String results = controller.getDrugGroupsByName("zzzznotype", request); Assert.assertEquals(0, ((ArrayList) SimpleObject.parseJson(results).get("results")).size()); }
@Test public void getDrugGroupsByName_shouldFindMatchingDrugGroups() throws Exception { String results = controller.getDrugGroupsByName("TestDrugGroup2", request); LinkedHashMap drugGroup = (LinkedHashMap) ((ArrayList) SimpleObject.parseJson(results).get("results")).get(0); Util.log("Found DrugGroup(s)", drugGroup); Assert.assertEquals("68547121-1b70-465e-99ee-c9dfd95e7d30", drugGroup.get("uuid")); Assert.assertEquals("TestDrugGroup2", drugGroup.get("name")); Assert.assertNull(drugGroup.get("auditInfo")); }