Skip to content

Commit

Permalink
Merge pull request #26 from virtualidentityag/DIAKONIE-335-deletion-r…
Browse files Browse the repository at this point in the history
…outing-more-error-tolerant

Diakonie 335 deletion routing more error tolerant
  • Loading branch information
tkuzynow authored Jul 19, 2024
2 parents ea80f0a + af4a090 commit 8b2f794
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers("/userstatistics", "/userstatistics/**")
.permitAll()
.antMatchers(HttpMethod.DELETE, "/useradmin/consultants/{consultantId:[0-9]+}/delete")
.hasAuthority(USER_ADMIN)
.hasAnyAuthority(USER_ADMIN, RESTRICTED_AGENCY_ADMIN)
.antMatchers(HttpMethod.GET, "/actuator/health")
.permitAll()
.antMatchers(HttpMethod.GET, "/actuator/health/*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,7 @@ private List<DeletionWorkflowError> performSessionDeletion(

Optional<Session> session = findSessionInUserSessionList(rcGroupId, userSessionList);

session.ifPresentOrElse(
s -> workflowErrors.addAll(deleteSessionService.performSessionDeletion(s)),
() ->
workflowErrors.add(
DeletionWorkflowError.builder()
.deletionSourceType(ASKER)
.deletionTargetType(ALL)
.identifier(rcGroupId)
.reason(RC_SESSION_GROUP_NOT_FOUND_REASON)
.timestamp(nowInUtc())
.build()));
session.ifPresent(s -> workflowErrors.addAll(deleteSessionService.performSessionDeletion(s)));

return workflowErrors;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
import java.util.Map;
import java.util.Optional;
import org.jeasy.random.EasyRandom;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;

@RunWith(MockitoJUnitRunner.class)
public class DeleteInactiveSessionsAndUserServiceTest {
@ExtendWith(MockitoExtension.class)
class DeleteInactiveSessionsAndUserServiceTest {

@InjectMocks private DeleteInactiveSessionsAndUserService deleteInactiveSessionsAndUserService;

Expand All @@ -42,8 +42,7 @@ public class DeleteInactiveSessionsAndUserServiceTest {
@Mock private InactivePrivateGroupsProvider inactivePrivateGroupsProvider;

@Test
public void
deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorsMail_When_userNotFoundReason() {
void deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorsMail_When_userNotFoundReason() {

EasyRandom easyRandom = new EasyRandom();
User user = easyRandom.nextObject(User.class);
Expand Down Expand Up @@ -71,7 +70,7 @@ public class DeleteInactiveSessionsAndUserServiceTest {
}

@Test
public void
void
deleteInactiveSessionsAndUsers_Should_DeleteEntireUserAccount_WhenUserHasOnlyInactiveSessions() {

EasyRandom easyRandom = new EasyRandom();
Expand All @@ -96,7 +95,7 @@ public class DeleteInactiveSessionsAndUserServiceTest {
}

@Test
public void
void
deleteInactiveSessionsAndUsers_Should_DeleteSingleSession_WhenUserHasActiveAndInactiveSessions() {

EasyRandom easyRandom = new EasyRandom();
Expand All @@ -121,7 +120,7 @@ public class DeleteInactiveSessionsAndUserServiceTest {
}

@Test
public void
void
deleteInactiveSessionsAndUsers_Should_logWorkflowErrorMail_WhenUserHasActiveAndInactiveSessionsAndHasErrors() {

EasyRandom easyRandom = new EasyRandom();
Expand Down Expand Up @@ -159,8 +158,8 @@ public class DeleteInactiveSessionsAndUserServiceTest {
}

@Test
public void
deleteInactiveSessionsAndUsers_Should_logWorkflowErrorMail_WhenSessionCouldNotBeFound() {
void
deleteInactiveSessionsAndUsers_Should_notLogError_WhenSessionCouldNotBeFound_BecauseItMayHaveBeenDeletedByPreviousWorkflowRun() {

EasyRandom easyRandom = new EasyRandom();
User user = easyRandom.nextObject(User.class);
Expand All @@ -181,15 +180,12 @@ public class DeleteInactiveSessionsAndUserServiceTest {

deleteInactiveSessionsAndUserService.deleteInactiveSessionsAndUsers();

verify(workflowErrorLogService, Mockito.times(1))
.logWorkflowErrors(argThat(list -> !list.isEmpty()));
verify(workflowErrorMailService, Mockito.times(1))
.buildAndSendErrorMail(Collections.emptyList());
verify(workflowErrorLogService, Mockito.never()).logWorkflowErrors(Mockito.anyList());
verify(workflowErrorMailService, Mockito.never()).buildAndSendErrorMail(Mockito.anyList());
}

@Test
public void
deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorMail_WhenUserCouldNotBeFound() {
void deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorMail_WhenUserCouldNotBeFound() {

EasyRandom easyRandom = new EasyRandom();
User user = easyRandom.nextObject(User.class);
Expand Down

0 comments on commit 8b2f794

Please sign in to comment.