@Test public void testUpdate() throws NoSuchMethodException, SecurityException { HouseService mockService = EasyMock.createMock(HouseService.class); HouseRestController controller = EasyMock.createMockBuilder(HouseRestController.class) .addMockedMethod(HouseRestController.class.getDeclaredMethod("getDawgShowClient")).createMock(); ReflectionTestUtils.setField(controller, "service", mockService); ReflectionTestUtils.setField(controller, "serverUtils", utils); String[] id = new String[1]; id[0] = "id"; Map<String, Object> data = new HashMap<String, Object>(); Map<String, Object>[] matches = getMatches(); EasyMock.expect(mockService.getStbsById((String[]) EasyMock.anyObject())).andReturn(matches); mockService.replace((DawgDevice) EasyMock.anyObject()); EasyMock.expectLastCall(); EasyMock.replay(mockService); ReflectionTestUtils.setField(controller, "service", mockService); DawgShowClient dawgShowClient = EasyMock.createMock(DawgShowClient.class); EasyMock.expect(controller.getDawgShowClient()).andReturn(dawgShowClient); EasyMock.replay(controller); try { dawgShowClient.updateCache((String[]) EasyMock.anyObject()); EasyMock.expectLastCall().once(); } catch (HttpException e) { Assert.fail("Failed to mock DawgShowClient.updateCache() method.", e); } Assert.assertEquals(controller.update(id, data, true), 1); EasyMock.verify(controller); }
@RequestMapping(value="update", method = {RequestMethod.POST}) @ResponseBody public int update(@RequestParam String[] id, @RequestBody Map<String,Object> data, @RequestParam(defaultValue="false") boolean replace) { int counter = 0; for (int i = 0; i < id.length; i++) { id[i] = clean(id[i]); } Map<String, Object>[] matches = service.getStbsById(id); if (null != matches) { for (Map<String, Object> match : matches) { Map<String, Object> newProps = new HashMap<String, Object>(data); try { newProps.put(MetaStb.ID, match.get(MetaStb.ID)); newProps.put(MetaStb.MACADDRESS, match.get(MetaStb.MACADDRESS)); if (!newProps.containsKey(MetaStb.CATSSERVERHOST)) { newProps.put(MetaStb.CATSSERVERHOST, match.get(MetaStb.CATSSERVERHOST)); } if (!newProps.containsKey(MetaStb.CATSKEYSETMAPPING)) { newProps.put(MetaStb.CATSKEYSETMAPPING, match.get(MetaStb.CATSKEYSETMAPPING)); } PersistableDevice pd = new PersistableDevice(newProps); if (replace) { service.replace(pd); } else { service.upsertStb(pd); } counter++; } catch (Exception e) { e.printStackTrace(); logger.warn("Failed to update device. deviceId="+match.get("id")+", data="+match); } } try { getDawgShowClient().updateCache(id); } catch (HttpException e) { logger.error("Failed to update DAWG show meta stb cache", e); } } return counter; }
HouseRestController { @RequestMapping(value="update", method = {RequestMethod.POST}) @ResponseBody public int update(@RequestParam String[] id, @RequestBody Map<String,Object> data, @RequestParam(defaultValue="false") boolean replace) { int counter = 0; for (int i = 0; i < id.length; i++) { id[i] = clean(id[i]); } Map<String, Object>[] matches = service.getStbsById(id); if (null != matches) { for (Map<String, Object> match : matches) { Map<String, Object> newProps = new HashMap<String, Object>(data); try { newProps.put(MetaStb.ID, match.get(MetaStb.ID)); newProps.put(MetaStb.MACADDRESS, match.get(MetaStb.MACADDRESS)); if (!newProps.containsKey(MetaStb.CATSSERVERHOST)) { newProps.put(MetaStb.CATSSERVERHOST, match.get(MetaStb.CATSSERVERHOST)); } if (!newProps.containsKey(MetaStb.CATSKEYSETMAPPING)) { newProps.put(MetaStb.CATSKEYSETMAPPING, match.get(MetaStb.CATSKEYSETMAPPING)); } PersistableDevice pd = new PersistableDevice(newProps); if (replace) { service.replace(pd); } else { service.upsertStb(pd); } counter++; } catch (Exception e) { e.printStackTrace(); logger.warn("Failed to update device. deviceId="+match.get("id")+", data="+match); } } try { getDawgShowClient().updateCache(id); } catch (HttpException e) { logger.error("Failed to update DAWG show meta stb cache", e); } } return counter; } }
HouseRestController { @RequestMapping(value="update", method = {RequestMethod.POST}) @ResponseBody public int update(@RequestParam String[] id, @RequestBody Map<String,Object> data, @RequestParam(defaultValue="false") boolean replace) { int counter = 0; for (int i = 0; i < id.length; i++) { id[i] = clean(id[i]); } Map<String, Object>[] matches = service.getStbsById(id); if (null != matches) { for (Map<String, Object> match : matches) { Map<String, Object> newProps = new HashMap<String, Object>(data); try { newProps.put(MetaStb.ID, match.get(MetaStb.ID)); newProps.put(MetaStb.MACADDRESS, match.get(MetaStb.MACADDRESS)); if (!newProps.containsKey(MetaStb.CATSSERVERHOST)) { newProps.put(MetaStb.CATSSERVERHOST, match.get(MetaStb.CATSSERVERHOST)); } if (!newProps.containsKey(MetaStb.CATSKEYSETMAPPING)) { newProps.put(MetaStb.CATSKEYSETMAPPING, match.get(MetaStb.CATSKEYSETMAPPING)); } PersistableDevice pd = new PersistableDevice(newProps); if (replace) { service.replace(pd); } else { service.upsertStb(pd); } counter++; } catch (Exception e) { e.printStackTrace(); logger.warn("Failed to update device. deviceId="+match.get("id")+", data="+match); } } try { getDawgShowClient().updateCache(id); } catch (HttpException e) { logger.error("Failed to update DAWG show meta stb cache", e); } } return counter; }  }
HouseRestController { @RequestMapping(value="update", method = {RequestMethod.POST}) @ResponseBody public int update(@RequestParam String[] id, @RequestBody Map<String,Object> data, @RequestParam(defaultValue="false") boolean replace) { int counter = 0; for (int i = 0; i < id.length; i++) { id[i] = clean(id[i]); } Map<String, Object>[] matches = service.getStbsById(id); if (null != matches) { for (Map<String, Object> match : matches) { Map<String, Object> newProps = new HashMap<String, Object>(data); try { newProps.put(MetaStb.ID, match.get(MetaStb.ID)); newProps.put(MetaStb.MACADDRESS, match.get(MetaStb.MACADDRESS)); if (!newProps.containsKey(MetaStb.CATSSERVERHOST)) { newProps.put(MetaStb.CATSSERVERHOST, match.get(MetaStb.CATSSERVERHOST)); } if (!newProps.containsKey(MetaStb.CATSKEYSETMAPPING)) { newProps.put(MetaStb.CATSKEYSETMAPPING, match.get(MetaStb.CATSKEYSETMAPPING)); } PersistableDevice pd = new PersistableDevice(newProps); if (replace) { service.replace(pd); } else { service.upsertStb(pd); } counter++; } catch (Exception e) { e.printStackTrace(); logger.warn("Failed to update device. deviceId="+match.get("id")+", data="+match); } } try { getDawgShowClient().updateCache(id); } catch (HttpException e) { logger.error("Failed to update DAWG show meta stb cache", e); } } return counter; }  @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); }
HouseRestController { @RequestMapping(value="update", method = {RequestMethod.POST}) @ResponseBody public int update(@RequestParam String[] id, @RequestBody Map<String,Object> data, @RequestParam(defaultValue="false") boolean replace) { int counter = 0; for (int i = 0; i < id.length; i++) { id[i] = clean(id[i]); } Map<String, Object>[] matches = service.getStbsById(id); if (null != matches) { for (Map<String, Object> match : matches) { Map<String, Object> newProps = new HashMap<String, Object>(data); try { newProps.put(MetaStb.ID, match.get(MetaStb.ID)); newProps.put(MetaStb.MACADDRESS, match.get(MetaStb.MACADDRESS)); if (!newProps.containsKey(MetaStb.CATSSERVERHOST)) { newProps.put(MetaStb.CATSSERVERHOST, match.get(MetaStb.CATSSERVERHOST)); } if (!newProps.containsKey(MetaStb.CATSKEYSETMAPPING)) { newProps.put(MetaStb.CATSKEYSETMAPPING, match.get(MetaStb.CATSKEYSETMAPPING)); } PersistableDevice pd = new PersistableDevice(newProps); if (replace) { service.replace(pd); } else { service.upsertStb(pd); } counter++; } catch (Exception e) { e.printStackTrace(); logger.warn("Failed to update device. deviceId="+match.get("id")+", data="+match); } } try { getDawgShowClient().updateCache(id); } catch (HttpException e) { logger.error("Failed to update DAWG show meta stb cache", e); } } return counter; }  @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; }