HouseRestController { @SuppressWarnings({"unchecked", "rawtypes" }) @RequestMapping(value="update/tags/{op}", method = {RequestMethod.POST}) @ResponseBody public void updateTags(@RequestBody Map<String,Object> payload, @PathVariable("op") String op) { List<String> id = (List<String>) payload.get("id"); List<String> tag = (List<String>) payload.get("tag"); boolean add = op.equals("add"); if (null == id || id.size() < 1) { throw new DawgIllegalArgumentException("Could not update tags. No ids were provided."); } if (null == tag || tag.size() < 1) { throw new DawgIllegalArgumentException("Could not update tags. No tags were provided."); } tag = validateTags(tag); List<String> validIds = new ArrayList<String>(); for(String i : id) { try { validIds.add(clean(i)); } catch (Exception e) { logger.warn("Updating tags, id unparsable. Id="+i); } } if (validIds.size() < 1) { throw new DawgIllegalArgumentException("Could not update tags. None of the provided ids were valid."); } Map<String, Object>[] matches = service.getStbsById(validIds.toArray(new String[validIds.size()])); if (null == matches || matches.length < 1) { throw new DawgIllegalArgumentException("Could not update tags. None of the provided existed."); } List<PersistableDevice> devicesToUpdate = new ArrayList<PersistableDevice>(); for (Map<String, Object> match : matches) { if (null != match) { try { Set<String> updated = new HashSet<String>(); if (match.containsKey("tags")) { updated.addAll((Collection) match.get("tags")); } if (add) { updated.addAll(tag); } else { updated.removeAll(tag); } match.put("tags", updated); devicesToUpdate.add(new PersistableDevice(match)); } catch (Exception e) { logger.warn("Failed to update device. deviceId="+match.get("id")+", data="+match,e); } } } service.upsertStb(devicesToUpdate.toArray(new PersistableDevice[devicesToUpdate.size()])); }  @RequestMapping(value="list*", method = RequestMethod.GET) @ResponseBody Map<String,Object>[] listAll(); @RequestMapping(value="id/{id}", method = {RequestMethod.GET}) @ResponseBody Map<String,Object> getStbsById(@PathVariable String id); @RequestMapping(value="edit/{id}", method = {RequestMethod.GET}) @ResponseBody Map<String,Object> editStb(@PathVariable String id); @RequestMapping(value="id/{id}", method={RequestMethod.DELETE}) @ResponseBody void deleteSingle(@PathVariable String id); @RequestMapping(value="id/{id}", method = {RequestMethod.PUT}) @ResponseBody void add(@PathVariable String id, @RequestBody Map<String,Object> data); @RequestMapping(value="id", method = {RequestMethod.POST}) @ResponseBody Map<String,Object>[] getStbsByIds(@RequestParam String[] id); @RequestMapping(value="update", method = {RequestMethod.POST}) @ResponseBody int update(@RequestParam String[] id, @RequestBody Map<String,Object> data,
            @RequestParam(defaultValue="false") boolean replace); @RequestMapping(value="remotetypes", method = {RequestMethod.GET}, produces = "application/json; charset=utf-8") @ResponseBody List<String> getRemoteTypes(); @SuppressWarnings({"unchecked", "rawtypes" }) @RequestMapping(value="update/tags/{op}", method = {RequestMethod.POST}) @ResponseBody void updateTags(@RequestBody Map<String,Object> payload, @PathVariable("op") String op); @RequestMapping(value="query", method = {RequestMethod.GET,RequestMethod.POST}) @ResponseBody Map<String,Object>[] getStbsByQuery(@RequestParam String q); @RequestMapping(value = "tag/{tag}", method = { RequestMethod.GET, RequestMethod.POST }) @ResponseBody Map<String, Object>[] getStbsByTag(@PathVariable String tag, @RequestParam(required = false) String q); @RequestMapping(value="delete", method = {RequestMethod.GET,RequestMethod.POST}) @ResponseBody void deleteStb(@RequestParam String[] id); @RequestMapping(value="populate/{token}", method=RequestMethod.POST) @ResponseBody int populate(@PathVariable String token,
            @RequestParam(required = false, defaultValue = "false", value = "isToOverride") Boolean isToOverrideMetaData); static final String[] ignoreProps; }
@Test(expectedExceptions = DawgIllegalArgumentException.class) public void testUpdatePayload() { HouseService mockService = EasyMock.createMock(HouseService.class); HouseRestController controller = new HouseRestController(); ReflectionTestUtils.setField(controller, "service", mockService); ReflectionTestUtils.setField(controller, "serverUtils", utils); Map<String, Object> payload = new HashMap<String, Object>(); controller.updateTags(payload,"add"); }