@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); }
@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()); }
// 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); }
@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()); }