@Test public void test29ParsePolicyList() throws Exception { PolicyManagerServlet servlet = new PolicyManagerServlet(); List<JSONObject> resultList = new ArrayList<JSONObject>(); PolicyController mockPolicyController = Mockito.mock(PolicyController.class); UserInfo mockUserInfo = Mockito.mock(UserInfo.class); String policyName = "sampleName\\"; String policyVersion = "sampleVersion"; List<Object> activeDataList = new ArrayList<Object>(); PolicyVersion mockPolicyVersion = Mockito.mock(PolicyVersion.class); activeDataList.add(mockPolicyVersion); Date mockDate = Mockito.mock(Date.class); when(mockPolicyController.getDataByQuery(any(String.class), any(SimpleBindings.class))) .thenReturn(activeDataList); when(mockPolicyVersion.getPolicyName()).thenReturn("testPolicyName"); when(mockPolicyVersion.getModifiedDate()).thenReturn(mockDate); when(mockPolicyVersion.getActiveVersion()).thenReturn(1); when(mockPolicyVersion.getCreatedBy()).thenReturn("sampleUserName"); when(mockPolicyVersion.getModifiedBy()).thenReturn("sampleUserName"); when(mockPolicyController.getEntityItem(UserInfo.class, "userLoginId", "sampleUserName")) .thenReturn(mockUserInfo); when(mockUserInfo.getUserName()).thenReturn("testUserName"); Whitebox.invokeMethod(servlet, "parsePolicyList", resultList, mockPolicyController, policyName, policyVersion); verify(mockPolicyController, atLeast(1)).getDataByQuery(any(String.class), any(SimpleBindings.class)); verify(mockPolicyVersion, atLeast(1)).getPolicyName(); verify(mockPolicyVersion, atLeast(1)).getModifiedDate(); verify(mockPolicyVersion, atLeast(1)).getActiveVersion(); verify(mockPolicyVersion, atLeast(1)).getCreatedBy(); verify(mockPolicyVersion, atLeast(1)).getModifiedBy(); }
private String getUserName(String loginId) { UserInfo userInfo = (UserInfo) getPolicyControllerInstance().getEntityItem(UserInfo.class, "userLoginId", loginId); if (userInfo == null) { return SUPERADMIN; } return userInfo.getUserName(); }
PolicyManagerServlet extends HttpServlet { private String getUserName(String loginId) { UserInfo userInfo = (UserInfo) getPolicyControllerInstance().getEntityItem(UserInfo.class, "userLoginId", loginId); if (userInfo == null) { return SUPERADMIN; } return userInfo.getUserName(); } }
PolicyManagerServlet extends HttpServlet { private String getUserName(String loginId) { UserInfo userInfo = (UserInfo) getPolicyControllerInstance().getEntityItem(UserInfo.class, "userLoginId", loginId); if (userInfo == null) { return SUPERADMIN; } return userInfo.getUserName(); }  }
PolicyManagerServlet extends HttpServlet { private String getUserName(String loginId) { UserInfo userInfo = (UserInfo) getPolicyControllerInstance().getEntityItem(UserInfo.class, "userLoginId", loginId); if (userInfo == null) { return SUPERADMIN; } return userInfo.getUserName(); }  static synchronized void setPolicyController(PolicyController policyController); static JsonArray getPolicyNames(); static void setPolicyNames(JsonArray policyNames); static List<String> getServiceTypeNamesList(); @Override void init(ServletConfig servletConfig); static void setTestUserId(String testUserId); }
PolicyManagerServlet extends HttpServlet { private String getUserName(String loginId) { UserInfo userInfo = (UserInfo) getPolicyControllerInstance().getEntityItem(UserInfo.class, "userLoginId", loginId); if (userInfo == null) { return SUPERADMIN; } return userInfo.getUserName(); }  static synchronized void setPolicyController(PolicyController policyController); static JsonArray getPolicyNames(); static void setPolicyNames(JsonArray policyNames); static List<String> getServiceTypeNamesList(); @Override void init(ServletConfig servletConfig); static void setTestUserId(String testUserId);  }