@Test public void test28Delete() throws Exception { JSONObject mockJSONObject = Mockito.mock(JSONObject.class); HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); User mockUser = Mockito.mock(User.class); PolicyController mockPolicyController = Mockito.mock(PolicyController.class); List<Object> policyEntityList = new ArrayList<Object>(); PolicyEntity mockPolicyEntity = Mockito.mock(PolicyEntity.class); policyEntityList.add(mockPolicyEntity); long policyId = 1; PolicyManagerServlet servlet = new PolicyManagerServlet() { private static final long serialVersionUID = 1L; @Override protected User getUserSession(HttpServletRequest request) { return mockUser; } }; PolicyManagerServlet.setPolicyController(mockPolicyController); when(mockUser.getOrgUserId()).thenReturn("sampleUserId"); when(mockJSONObject.getString("path")).thenReturn("/sampleScope:samplePolicyName.1.xml"); when(mockJSONObject.has("deleteVersion")).thenReturn(true); when(mockJSONObject.getString("deleteVersion")).thenReturn("ALL"); when(mockPolicyController.getDataByQuery(any(String.class), any(SimpleBindings.class))) .thenReturn(policyEntityList); when(mockPolicyEntity.getPolicyId()).thenReturn(policyId); when(mockPolicyEntity.getScope()).thenReturn("sampleScope"); when(mockPolicyEntity.getPolicyName()).thenReturn("samplePolicyName"); JSONObject returnObj = Whitebox.invokeMethod(servlet, "delete", mockJSONObject, mockRequest); assertTrue(returnObj.has("result")); verify(mockUser, atLeast(1)).getOrgUserId(); verify(mockJSONObject, atLeast(1)).getString(any(String.class)); verify(mockJSONObject, atLeast(1)).has(any(String.class)); verify(mockPolicyController, atLeast(1)).getDataByQuery(any(String.class), any(SimpleBindings.class)); verify(mockPolicyEntity, atLeast(1)).getPolicyId(); verify(mockPolicyEntity, atLeast(1)).getScope(); verify(mockPolicyEntity, atLeast(1)).getPolicyName(); when(mockJSONObject.getString("path")).thenReturn("/sampleScope\\:samplePolicyName.1.xml"); when(mockJSONObject.getString("deleteVersion")).thenReturn("CURRENT"); returnObj = Whitebox.invokeMethod(servlet, "delete", mockJSONObject, mockRequest); assertTrue(returnObj.has("result")); verify(mockJSONObject, atLeast(1)).getString(any(String.class)); when(mockJSONObject.getString("path")).thenReturn("/sampleScope:samplePolicyName.2.txt"); when(mockJSONObject.has("deleteVersion")).thenReturn(false); returnObj = Whitebox.invokeMethod(servlet, "delete", mockJSONObject, mockRequest); assertTrue(returnObj.has("result")); verify(mockJSONObject, atLeast(1)).getString("path"); verify(mockJSONObject, atLeast(1)).has("deleteVersion"); }
public static synchronized void setPolicyController(PolicyController policyController) { PolicyManagerServlet.policyController = policyController; }
PolicyManagerServlet extends HttpServlet { public static synchronized void setPolicyController(PolicyController policyController) { PolicyManagerServlet.policyController = policyController; } }
PolicyManagerServlet extends HttpServlet { public static synchronized void setPolicyController(PolicyController policyController) { PolicyManagerServlet.policyController = policyController; }  }
PolicyManagerServlet extends HttpServlet { public static synchronized void setPolicyController(PolicyController policyController) { PolicyManagerServlet.policyController = policyController; }  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 { public static synchronized void setPolicyController(PolicyController policyController) { PolicyManagerServlet.policyController = policyController; }  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);  }