AutoPushController extends RestrictedBaseController { @RequestMapping( value = {"/get_AutoPushPoliciesContainerData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) public void getPolicyGroupContainerData(HttpServletRequest request, HttpServletResponse response) { try { Set<String> scopes = new HashSet<>(); List<String> roles = new ArrayList<>(); List<Object> data = new ArrayList<>(); Map<String, Object> model = new HashMap<>(); String userId = UserUtils.getUserSession(request).getOrgUserId(); PolicyController controller = policyController != null ? getPolicyController() : new PolicyController(); List<Object> userRoles = controller.getRoles(userId); for (Object role : userRoles) { Roles userRole = (Roles) role; roles.add(userRole.getRole()); addAllScopes(userRole, scopes); } if (roles.contains("super-admin") || roles.contains("super-editor") || roles.contains("super-guest")) { data = commonClassDao.getData(PolicyVersion.class); } else { if (!scopes.isEmpty()) { for (String scope : scopes) { scope += "%"; String query = "From PolicyVersion where policy_name like :scope and id > 0"; SimpleBindings params = new SimpleBindings(); params.put("scope", scope); List<Object> filterdatas = commonClassDao.getDataByQuery(query, params); if (filterdatas != null) { data.addAll(filterdatas); } } } else { PolicyVersion emptyPolicyName = new PolicyVersion(); emptyPolicyName .setPolicyName("Please Contact Policy Super Admin, There are no scopes assigned to you"); data.add(emptyPolicyName); } } ObjectMapper mapper = new ObjectMapper(); model.put("policydatas", mapper.writeValueAsString(data)); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); response.getWriter().write(new JSONObject(msg).toString()); } catch (Exception e) { logger.error("Exception Occurred" + e); } }  PolicyController getPolicyController(); void setPolicyController(PolicyController policyController); synchronized void refreshGroups(); @RequestMapping( value = {"/get_AutoPushPoliciesContainerData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPolicyGroupContainerData(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/auto_Push/PushPolicyToPDP.htm"}, method = {RequestMethod.POST}) ModelAndView pushPolicyToPDPGroup(HttpServletRequest request, HttpServletResponse response); @SuppressWarnings("unchecked") @RequestMapping(value = {"/auto_Push/remove_GroupPolicies.htm"}, method = {RequestMethod.POST}) ModelAndView removePDPGroup(HttpServletRequest request, HttpServletResponse response);  }
@Test public void testNegativeCase1() { try { apController.getPolicyGroupContainerData(null, null); } catch (Exception ex) { fail("No exceptions expected, received: " + ex); } }
@Test public void testGetPolicyGroupContainerData() throws Exception { Roles superAdmin = new Roles(); Roles superEditor = new Roles(); Roles superGuest = new Roles(); rolesList.add(superAdmin); rolesList.add(superEditor); rolesList.add(superGuest); apController.setPolicyController(mockPolicyController); apController.getPolicyGroupContainerData(mockRequest, mockResponse); verify(mockRequest, atLeast(1)).getSession(false); verify(mockUser, atLeast(1)).getOrgUserId(); verify(mockPolicyController, atLeast(1)).getRoles(any(String.class)); }