@Test public void setPreferredWidgets() throws Exception { String userId = "user"; String moduleName = "newModule"; String ipAddr = "127.0.0.1"; List<String> widgetList = new ArrayList<>(); widgetList.add("newWidget"); PreferredWidgetsDto preferredWidgetsDto = new PreferredWidgetsDto(); preferredWidgetsDto.setPreferredWidgets(widgetList); preferredWidgetsDto.setModuleName(moduleName); ObjectMapper objectMapper = new ObjectMapper(); String in = objectMapper.writeValueAsString(preferredWidgetsDto); log.debug("Input JSON: " + in); expect(mockAuthentication.getName()).andReturn("user").atLeastOnce(); Capture<PreferredWidgetsDto> savedPreferredWidgetsDto = new Capture<>(); mockHttpSession.setAttribute("acm_ip_address", "127.0.0.1"); expect(mockUserPreferenceService.updateUserPreferenceWidgets(eq(userId), capture(savedPreferredWidgetsDto), eq(ipAddr))) .andReturn(preferredWidgetsDto); replayAll(); MvcResult result = mockMvc.perform( put("/api/v1/plugin/dashboard/widgets/preferred") .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .session(mockHttpSession) .principal(mockAuthentication) .content(in)) .andReturn(); verifyAll(); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); assertTrue(result.getResponse().getContentType().startsWith(MediaType.APPLICATION_JSON_VALUE)); String json = result.getResponse().getContentAsString(); log.info("results: " + json); PreferredWidgetsDto fromJson = new ObjectMapper().readValue(json, PreferredWidgetsDto.class); assertNotNull(fromJson); assertEquals(preferredWidgetsDto.getModuleName(), fromJson.getModuleName()); assertEquals(preferredWidgetsDto.getPreferredWidgets().get(0), fromJson.getPreferredWidgets().get(0)); }
@RequestMapping(value = "/preferred", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public PreferredWidgetsDto setPreferredWidgets( @RequestBody PreferredWidgetsDto in, Authentication authentication, HttpSession session) throws AcmObjectNotFoundException { String ipAddress = (String) session.getAttribute("acm_ip_address"); String userId = authentication.getName(); log.info("Setting widgets for user based on the user preference for user: [{}]", userId); return userPreferenceService.updateUserPreferenceWidgets(userId, in, ipAddress); }
SetUserPreferredWidgetsPerModule { @RequestMapping(value = "/preferred", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public PreferredWidgetsDto setPreferredWidgets( @RequestBody PreferredWidgetsDto in, Authentication authentication, HttpSession session) throws AcmObjectNotFoundException { String ipAddress = (String) session.getAttribute("acm_ip_address"); String userId = authentication.getName(); log.info("Setting widgets for user based on the user preference for user: [{}]", userId); return userPreferenceService.updateUserPreferenceWidgets(userId, in, ipAddress); } }
SetUserPreferredWidgetsPerModule { @RequestMapping(value = "/preferred", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public PreferredWidgetsDto setPreferredWidgets( @RequestBody PreferredWidgetsDto in, Authentication authentication, HttpSession session) throws AcmObjectNotFoundException { String ipAddress = (String) session.getAttribute("acm_ip_address"); String userId = authentication.getName(); log.info("Setting widgets for user based on the user preference for user: [{}]", userId); return userPreferenceService.updateUserPreferenceWidgets(userId, in, ipAddress); }  }
SetUserPreferredWidgetsPerModule { @RequestMapping(value = "/preferred", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public PreferredWidgetsDto setPreferredWidgets( @RequestBody PreferredWidgetsDto in, Authentication authentication, HttpSession session) throws AcmObjectNotFoundException { String ipAddress = (String) session.getAttribute("acm_ip_address"); String userId = authentication.getName(); log.info("Setting widgets for user based on the user preference for user: [{}]", userId); return userPreferenceService.updateUserPreferenceWidgets(userId, in, ipAddress); }  @RequestMapping(value = "/preferred", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody PreferredWidgetsDto setPreferredWidgets(
            @RequestBody PreferredWidgetsDto in,
            Authentication authentication,
            HttpSession session); UserPreferenceService getUserPreferenceService(); void setUserPreferenceService(UserPreferenceService userPreferenceService); }
SetUserPreferredWidgetsPerModule { @RequestMapping(value = "/preferred", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public PreferredWidgetsDto setPreferredWidgets( @RequestBody PreferredWidgetsDto in, Authentication authentication, HttpSession session) throws AcmObjectNotFoundException { String ipAddress = (String) session.getAttribute("acm_ip_address"); String userId = authentication.getName(); log.info("Setting widgets for user based on the user preference for user: [{}]", userId); return userPreferenceService.updateUserPreferenceWidgets(userId, in, ipAddress); }  @RequestMapping(value = "/preferred", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody PreferredWidgetsDto setPreferredWidgets(
            @RequestBody PreferredWidgetsDto in,
            Authentication authentication,
            HttpSession session); UserPreferenceService getUserPreferenceService(); void setUserPreferenceService(UserPreferenceService userPreferenceService);  }