@Test
public void testDoDeletePap() throws IOException {

    CommonClassDao dao = Mockito.mock(CommonClassDao.class);
    DeleteHandler handler = new DeleteHandler(dao);
    // Request #1
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setBodyContent(
        "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Config_name.1.xml\", \"deleteCondition\": \"All Versions\"\n}\n");
    MockHttpServletResponse response = new MockHttpServletResponse();
    handler.doApiDeleteFromPap(request, response);
    assertTrue(response.containsHeader("error"));
    // Request #2
    request.setBodyContent(
        "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Action_name.1.xml\", \"deleteCondition\": \"All Versions\"\n}\n");
    handler.doApiDeleteFromPap(request, response);
    assertTrue(response.containsHeader("error"));
    // Request #3
    request.setBodyContent(
        "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Decision_name.1.xml\", \"deleteCondition\": \"All Versions\"\n}\n");
    handler.doApiDeleteFromPap(request, response);
    assertTrue(response.containsHeader("error"));
    // Request #4
    request.setBodyContent(
        "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Bar_name.1.xml\", \"deleteCondition\": \"All Versions\"\n}\n");
    handler.doApiDeleteFromPap(request, response);
    assertTrue(response.containsHeader("error"));
    // Request #5
    request.setBodyContent(
        "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Config_name.1.xml\", \"deleteCondition\": \"Current Version\"\n}\n");
    handler.doApiDeleteFromPap(request, response);
    assertTrue(response.containsHeader("error"));
    // Request #6
    request.setBodyContent(
        "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Action_name.1.xml\", \"deleteCondition\": \"Current Version\"\n}\n");
    handler.doApiDeleteFromPap(request, response);
    assertTrue(response.containsHeader("error"));
    // Request #7
    request.setBodyContent(
        "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Decision_name.1.xml\", \"deleteCondition\": \"Current Version\"\n}\n");
    handler.doApiDeleteFromPap(request, response);
    assertTrue(response.containsHeader("error"));
    // Mock dao
    List<PolicyVersion> pePVs = new ArrayList<PolicyVersion>();
    PolicyVersion pv = new PolicyVersion();
    pePVs.add(pv);
    List<Object> peObjs = new ArrayList<Object>(pePVs);
    List<PolicyEntity> peEnts = new ArrayList<PolicyEntity>();
    PolicyEntity peEnt = new PolicyEntity();
    peEnts.add(peEnt);
    List<Object> peEntObjs = new ArrayList<Object>(peEnts);
    Mockito.when(dao.getDataByQuery(eq("Select p from PolicyVersion p where p.policyName=:pname"), any()))
        .thenReturn(peObjs);
    Mockito.when(
        dao.getDataByQuery(eq("SELECT p FROM PolicyEntity p WHERE p.policyName=:pName and p.scope=:pScope"), any()))
        .thenReturn(peEntObjs);
    // Request #8
    request.setBodyContent(
        "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Decision_name.1.xml\", \"deleteCondition\": \"Current Version\"\n}\n");
    handler.doApiDeleteFromPap(request, response);
    assertTrue(response.containsHeader("error"));
    // Request #9
    request.setBodyContent(
        "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Decision_name.1.xml\", \"deleteCondition\": \"Current Version\"\n, \"deleteCondition\": \"All Versions\"}\n");
    handler.doApiDeleteFromPap(request, response);
    assertTrue(response.containsHeader("error"));
}