Example #1
0
  @Test
  public void testDeleteWorkflowSuccessfulLogicalDeleteWithTrueDeleteParam() throws Exception {

    WorkflowRestService wrs = new WorkflowRestService();
    Authenticator auth = mock(Authenticator.class);
    wrs.setAuthenticator(auth);

    User u = new User();
    u.setLogin("bob");
    u.setPermissions(Permission.DELETE_ALL_WORKFLOWS);

    WorkflowDAO workflowDAO = mock(WorkflowDAO.class);
    wrs.setWorkflowDAO(workflowDAO);
    Workflow w = new Workflow();
    when(workflowDAO.getWorkflowById("1", u)).thenReturn(w);

    DeleteReportImpl deleteResp = new DeleteReportImpl();
    deleteResp.setSuccessful(true);
    deleteResp.setId(1L);
    when(workflowDAO.delete(1L, Boolean.TRUE)).thenReturn(deleteResp);

    when(auth.authenticate(null)).thenReturn(u);

    EventDAO eventDAO = mock(EventDAO.class);
    wrs.setEventDAO(eventDAO);

    DeleteReport dwr = wrs.deleteWorkflow(1L, Boolean.TRUE, null, null, null, null);
    assertTrue(dwr != null);
    assertTrue(dwr.getId() == 1L);
    assertTrue(dwr.getReason(), dwr.getReason() == null);
    assertTrue(dwr.isSuccessful());

    verify(workflowDAO).delete(1L, Boolean.TRUE);
    //        verify(eventBuilder).setAsDeleteWorkflowEvent(event, w);
  }
Example #2
0
  @Test
  public void testDeleteWorkflowUserAuthorizedToDeleteOwnWorkflowButWorkflowOwneDoesNotMatch()
      throws Exception {

    WorkflowRestService wrs = new WorkflowRestService();
    Authenticator auth = mock(Authenticator.class);
    wrs.setAuthenticator(auth);

    User u = new User();
    u.setLogin("bob");
    u.setPermissions(Permission.DELETE_THEIR_WORKFLOWS);

    WorkflowDAO workflowDAO = mock(WorkflowDAO.class);
    wrs.setWorkflowDAO(workflowDAO);
    Workflow w = new Workflow();
    w.setOwner("joe");
    when(workflowDAO.getWorkflowById("1", u)).thenReturn(w);

    when(auth.authenticate(null)).thenReturn(u);

    DeleteReport dwr = wrs.deleteWorkflow(1L, null, null, null, null, null);
    assertTrue(dwr != null);
    assertTrue(dwr.getId() == 1L);
    assertTrue(dwr.getReason().equals("bob does not have permission to delete Workflow (1)"));
    assertFalse(dwr.isSuccessful());
  }
Example #3
0
  // test updateWorkflow deleted and version true/false
  @Test
  public void testUpdateWorkflowWithChangesToDeletedAndVersion() throws Exception {
    Authenticator auth = mock(Authenticator.class);
    HttpServletRequest request = mock(HttpServletRequest.class);

    WorkflowDAO workflowDAO = new WorkflowObjectifyDAOImpl(null);
    Workflow w = new Workflow();
    w.setName("wf");
    w = workflowDAO.insert(w);

    User u = new User();
    u.setLogin("bob");
    u.setPermissions(Permission.UPDATE_ALL_WORKFLOWS);

    when(auth.authenticate(request)).thenReturn(u);
    WorkflowRestService wrs = new WorkflowRestService();
    wrs.setAuthenticator(auth);

    w = wrs.updateWorkflow(w.getId(), null, Boolean.TRUE, 2, request);
    assertTrue(w.getId() != null);
    assertTrue(w.isDeleted() == true);
    assertTrue(w.getVersion() == 2);

    w = wrs.updateWorkflow(w.getId(), null, Boolean.FALSE, 3, request);
    assertTrue(w.getId() != null);
    assertTrue(w.isDeleted() == false);
    assertTrue(w.getVersion() == 3);

    w = wrs.updateWorkflow(w.getId(), null, null, null, request);
    assertTrue(w.getId() != null);
    assertTrue(w.isDeleted() == false);
    assertTrue(w.getVersion() == 3);
  }
Example #4
0
  @Test
  public void testDeleteWorkflowButNotAuthorized() throws Exception {

    WorkflowRestService wrs = new WorkflowRestService();
    Authenticator auth = mock(Authenticator.class);
    wrs.setAuthenticator(auth);

    User u = new User();
    u.setPermissions(Permission.NONE);
    when(auth.authenticate(null)).thenReturn(u);

    DeleteReport dr = wrs.deleteWorkflow(1L, null, null, null, null, null);
    assertTrue(dr != null);
    assertTrue(dr.isSuccessful() == false);
    assertTrue(dr.getReason().equals("Not authorized to delete"));
  }
Example #5
0
  // test updateWorkflow resave non existant workflow
  @Test
  public void testUpdateWorkflowResaveNonExistantWorkflow() throws Exception {
    Authenticator auth = mock(Authenticator.class);
    HttpServletRequest request = mock(HttpServletRequest.class);

    User u = new User();
    u.setLogin("bob");
    u.setPermissions(Permission.UPDATE_ALL_WORKFLOWS);

    when(auth.authenticate(request)).thenReturn(u);
    WorkflowRestService wrs = new WorkflowRestService();
    wrs.setAuthenticator(auth);

    try {
      wrs.updateWorkflow(1L, Boolean.TRUE, null, null, request);
      fail("Expected exception");
    } catch (WebApplicationException ex) {
      assertTrue(ex.getMessage(), ex.getMessage().contains("There was an error resaving Workflow"));
    }
  }
Example #6
0
  // test updateWorkflow no permission
  @Test
  public void testUpdateWorkflowNoPermission() throws Exception {
    Authenticator auth = mock(Authenticator.class);
    HttpServletRequest request = mock(HttpServletRequest.class);

    User u = new User();
    u.setLogin("bob");
    u.setPermissions(Permission.NONE);

    when(auth.authenticate(request)).thenReturn(u);
    WorkflowRestService wrs = new WorkflowRestService();
    wrs.setAuthenticator(auth);

    try {
      wrs.updateWorkflow(1L, null, null, null, request);
      fail("Expected exception");
    } catch (WebApplicationException wae) {
      assertTrue(
          wae.getMessage(), wae.getResponse().getStatus() == HttpServletResponse.SC_UNAUTHORIZED);
    }
  }
Example #7
0
  @Test
  public void testDeleteWorkflowAllAuthorizationButNoWorkflowFound() throws Exception {

    WorkflowRestService wrs = new WorkflowRestService();
    Authenticator auth = mock(Authenticator.class);
    wrs.setAuthenticator(auth);

    User u = new User();
    u.setLogin("bob");
    u.setPermissions(Permission.DELETE_ALL_WORKFLOWS);

    WorkflowDAO workflowDAO = mock(WorkflowDAO.class);
    wrs.setWorkflowDAO(workflowDAO);

    when(workflowDAO.getWorkflowById("1", u)).thenReturn(null);

    when(auth.authenticate(null)).thenReturn(u);

    DeleteReport dwr = wrs.deleteWorkflow(1L, null, null, null, null, null);
    assertTrue(dwr != null);
    assertTrue(dwr.getId() == 1L);
    assertTrue(dwr.getReason().equals("Workflow (1) not found"));
    assertFalse(dwr.isSuccessful());
  }