@Test(expected = UserNotInSessionException.class) public void accessUserDoesNotExist() { RemoveUserIntegrator service = new RemoveUserIntegrator(USERNAME_DOES_NOT_EXIST, USERNAME_TO_DELETE); service.execute(); }
@Test(expected = UnauthorizedOperationException.class) public void notRootUser() { String ars = addUserToSession(USERNAME); RemoveUserIntegrator service = new RemoveUserIntegrator(ars, USERNAME_TO_DELETE); service.execute(); }
/* * accessUsername exists, is in session and is root toDeleteUsername exists * and is not in session */ @Test(expected = UserNotInSessionException.class) public void successToDeleteIsNotInSession() { removeUserFromSession(root); RemoveUserIntegrator service = new RemoveUserIntegrator(root, USERNAME_TO_DELETE); service.execute(); }
@Test(expected = UserNotInSessionException.class) public void notInSessionAndNotRoot() { String ars = addUserToSession(USERNAME); removeUserFromSession(ars); RemoveUserIntegrator service = new RemoveUserIntegrator(ars, USERNAME_TO_DELETE); service.execute(); }
@Test(expected = UnavailableServiceException.class) public void testMockRemoteInvocationException(@Mocked final IDRemoteServices remoteService) throws Exception { new Expectations() { { remoteService.removeUser(anyString); result = new RemoteInvocationException(); } }; RemoveUserIntegrator integrator = new RemoveUserIntegrator(root, USERNAME); integrator.execute(); }
/* * accessUsername exists, is in session and is root toDeleteUsername exists * and is in session Test if user and session are both deleted */ @Test public void successToDeleteIsInSession(@Mocked final IDRemoteServices remoteService) throws Exception { new Expectations() { { remoteService.removeUser(anyString); } }; String token = addUserToSession(USERNAME_TO_DELETE); RemoveUserIntegrator service = new RemoveUserIntegrator(root, USERNAME_TO_DELETE); service.execute(); assertNull("Removed user but not removed from session", getUserFromSession(token)); }
@Test public void success(@Mocked final IDRemoteServices remoteService) { new Expectations() { { remoteService.removeUser(anyString); } }; RemoveUserIntegrator integrator = new RemoveUserIntegrator(root, USERNAME_TO_DELETE); integrator.execute(); boolean deleted = getUserFromUsername(USERNAME_TO_DELETE) == null; assertTrue("user was not deleted", deleted); assertNull("Spreadsheet was not deleted", getSpreadSheet(SPREADSHEET_NAME)); }
@Test public void successCompensation(@Mocked final IDRemoteServices remoteService) throws Exception { new Expectations() { { remoteService.removeUser(anyString); result = new RemoteInvocationException(); } }; RemoveUserIntegrator integrator = new RemoveUserIntegrator(root, USERNAME); try { integrator.execute(); } catch (UnavailableServiceException e) { User user = getUserFromUsername(USERNAME); assertNotNull(user.getName()); assertNotNull(user.getEmail()); } }
@Test(expected = LoginBubbleDocsException.class) public void userToDeleteDoesNotExist() { RemoveUserIntegrator service = new RemoveUserIntegrator(root, USERNAME_DOES_NOT_EXIST); service.execute(); }