forked from Onlineberatung/onlineBeratung-userService
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from virtualidentityag/DIAKONIE-375-fix-deleti…
…on-routine-to-delete-rc-rooms-if-session-is-already-deleted-from-mariadb Diakonie 375 fix deletion routine to delete rc rooms if session is already deleted from mariadb
- Loading branch information
Showing
9 changed files
with
188 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...a/de/caritas/cob/userservice/api/workflow/delete/action/asker/DeleteSingleRoomAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package de.caritas.cob.userservice.api.workflow.delete.action.asker; | ||
|
||
import static de.caritas.cob.userservice.api.helper.CustomLocalDateTime.nowInUtc; | ||
import static de.caritas.cob.userservice.api.workflow.delete.model.DeletionSourceType.ASKER; | ||
import static org.apache.commons.lang3.StringUtils.isNotBlank; | ||
|
||
import de.caritas.cob.userservice.api.actions.ActionCommand; | ||
import de.caritas.cob.userservice.api.adapters.rocketchat.RocketChatService; | ||
import de.caritas.cob.userservice.api.exception.rocketchat.RocketChatDeleteGroupException; | ||
import de.caritas.cob.userservice.api.model.Session; | ||
import de.caritas.cob.userservice.api.workflow.delete.model.DeletionTargetType; | ||
import de.caritas.cob.userservice.api.workflow.delete.model.DeletionWorkflowError; | ||
import de.caritas.cob.userservice.api.workflow.delete.model.RocketchatRoomDeletionWorkflowDTO; | ||
import de.caritas.cob.userservice.api.workflow.delete.model.SessionDeletionWorkflowDTO; | ||
import java.util.List; | ||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Slf4j | ||
public class DeleteSingleRoomAction implements ActionCommand<RocketchatRoomDeletionWorkflowDTO> { | ||
|
||
protected final @NonNull RocketChatService rocketChatService; | ||
|
||
public DeleteSingleRoomAction(@NonNull RocketChatService rocketChatService) { | ||
this.rocketChatService = rocketChatService; | ||
} | ||
|
||
void deleteRocketChatGroup(String rcGroupId, List<DeletionWorkflowError> workflowErrors) { | ||
if (isNotBlank(rcGroupId)) { | ||
try { | ||
this.rocketChatService.deleteGroupAsTechnicalUser(rcGroupId); | ||
} catch (RocketChatDeleteGroupException e) { | ||
log.error("UserService delete workflow error: ", e); | ||
workflowErrors.add( | ||
DeletionWorkflowError.builder() | ||
.deletionSourceType(ASKER) | ||
.deletionTargetType(DeletionTargetType.ROCKET_CHAT) | ||
.identifier(rcGroupId) | ||
.reason("Deletion of Rocket.Chat group failed") | ||
.timestamp(nowInUtc()) | ||
.build()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Deletes the given {@link Session} in the database with the related Rocket.Chat room containing | ||
* all messages and uploads. | ||
* | ||
* @param actionTarget the {@link SessionDeletionWorkflowDTO} with the session to delete | ||
*/ | ||
@Override | ||
public void execute(RocketchatRoomDeletionWorkflowDTO actionTarget) { | ||
deleteRocketChatGroup( | ||
actionTarget.getRocketchatRoomId(), actionTarget.getDeletionWorkflowErrors()); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
.../caritas/cob/userservice/api/workflow/delete/model/RocketchatRoomDeletionWorkflowDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package de.caritas.cob.userservice.api.workflow.delete.model; | ||
|
||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class RocketchatRoomDeletionWorkflowDTO { | ||
|
||
private String rocketchatRoomId; | ||
private List<DeletionWorkflowError> deletionWorkflowErrors; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
.../caritas/cob/userservice/api/workflow/delete/action/asker/DeleteSingleRoomActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package de.caritas.cob.userservice.api.workflow.delete.action.asker; | ||
|
||
import static java.util.Collections.emptyList; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
import static org.powermock.reflect.Whitebox.setInternalState; | ||
|
||
import de.caritas.cob.userservice.api.adapters.rocketchat.RocketChatService; | ||
import de.caritas.cob.userservice.api.exception.rocketchat.RocketChatDeleteGroupException; | ||
import de.caritas.cob.userservice.api.workflow.delete.model.DeletionWorkflowError; | ||
import de.caritas.cob.userservice.api.workflow.delete.model.RocketchatRoomDeletionWorkflowDTO; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.jeasy.random.EasyRandom; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.slf4j.Logger; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class DeleteSingleRoomActionTest { | ||
|
||
@InjectMocks private DeleteSingleRoomAction deleteSingleRoomAction; | ||
|
||
@Mock private RocketChatService rocketChatService; | ||
|
||
@Mock private Logger logger; | ||
|
||
@Before | ||
public void setup() { | ||
setInternalState(DeleteSingleRoomAction.class, "log", logger); | ||
} | ||
|
||
@Test | ||
public void | ||
execute_Should_returnEmptyListAndPerformAllDeletions_When_userSessionIsDeletedSuccessful() | ||
throws Exception { | ||
String rocketChatId = new EasyRandom().nextObject(String.class); | ||
RocketchatRoomDeletionWorkflowDTO workflowDTO = | ||
new RocketchatRoomDeletionWorkflowDTO(rocketChatId, emptyList()); | ||
|
||
this.deleteSingleRoomAction.execute(workflowDTO); | ||
List<DeletionWorkflowError> workflowErrors = workflowDTO.getDeletionWorkflowErrors(); | ||
|
||
assertThat(workflowErrors, hasSize(0)); | ||
verifyNoMoreInteractions(this.logger); | ||
verify(this.rocketChatService, times(1)).deleteGroupAsTechnicalUser(any()); | ||
} | ||
|
||
@Test | ||
public void | ||
execute_Should_returnExpectedWorkflowErrors_When_noUserSessionDeletedStepIsSuccessful() | ||
throws Exception { | ||
doThrow(new RocketChatDeleteGroupException(new RuntimeException())) | ||
.when(this.rocketChatService) | ||
.deleteGroupAsTechnicalUser(any()); | ||
|
||
RocketchatRoomDeletionWorkflowDTO workflowDTO = | ||
new RocketchatRoomDeletionWorkflowDTO("rocketChatId", new ArrayList<>()); | ||
|
||
this.deleteSingleRoomAction.execute(workflowDTO); | ||
List<DeletionWorkflowError> workflowErrors = workflowDTO.getDeletionWorkflowErrors(); | ||
|
||
assertThat(workflowErrors, hasSize(1)); | ||
verify(logger, times(1)).error(anyString(), any(Exception.class)); | ||
} | ||
} |