diff --git a/vorgang-manager-server/src/main/java/de/ozgcloud/vorgang/command/CommandRepository.java b/vorgang-manager-server/src/main/java/de/ozgcloud/vorgang/command/CommandRepository.java index ee3b10bd2228f0ed371ada2347f2163dc462785e..dce3ec92f0c506bcabce138f6104003737adff39 100644 --- a/vorgang-manager-server/src/main/java/de/ozgcloud/vorgang/command/CommandRepository.java +++ b/vorgang-manager-server/src/main/java/de/ozgcloud/vorgang/command/CommandRepository.java @@ -263,7 +263,7 @@ class CommandRepository { return query; } - public Command setRevokeStatusWithResource(String id, String createdResource) { + public Command setRevokeStatus(String id, String createdResource) { return mongoOperations.findAndModify(queryById(id), buildUpdateStatusRevoke(createdResource), FindAndModifyOptions.options().returnNew(true), Command.class); } diff --git a/vorgang-manager-server/src/main/java/de/ozgcloud/vorgang/command/CommandService.java b/vorgang-manager-server/src/main/java/de/ozgcloud/vorgang/command/CommandService.java index d525138e13c1b40ece1bb09452ac77f6d78f3837..ff7653e640230c195b26595b3b50c0589f305303 100644 --- a/vorgang-manager-server/src/main/java/de/ozgcloud/vorgang/command/CommandService.java +++ b/vorgang-manager-server/src/main/java/de/ozgcloud/vorgang/command/CommandService.java @@ -117,7 +117,7 @@ public class CommandService { public void setCommandFinished(String commandId, String createdResource) { var command = getById(commandId); if (shouldRevoke(command)) { - command = repository.setRevokeStatusWithResource(commandId, createdResource); + command = repository.setRevokeStatus(commandId, createdResource); publishRevokeCommandEvent(command); return; } diff --git a/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/collaboration/CollaborationITCase.java b/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/collaboration/CollaborationITCase.java index 2c87abc4a00c6675c1c96c931fedbca8da8572c8..3a1508c570ac7a6ac3bd1e41fe1815041e1541e6 100644 --- a/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/collaboration/CollaborationITCase.java +++ b/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/collaboration/CollaborationITCase.java @@ -124,20 +124,6 @@ class CollaborationITCase { vorgangId = mongoOperations.save(VorgangTestFactory.createBuilder().id(null).version(0L).build()).getId(); } - private CreateCommandRequest buildCreateCollaborationVorgangCommand(String vorgangId, int collaborationLevel) { - return CreateCommandRequest.builder() - .callContext(CallContext.builder().client("test").build()) - .vorgangId(vorgangId) - .relationId(vorgangId) - .order("CREATE_COLLABORATION_REQUEST") - .bodyObject(Map.of( - "titel", TITEL, - "anfrage", ANFRAGE, - "collaborationLevel", collaborationLevel, - "zustaendigeStelle", ZustaendigeStelleTestFactory.ORGANISATIONSEINHEIT_ID)) - .build(); - } - @DisplayName("Get file content") @Nested class TestGetFileContent { @@ -205,6 +191,20 @@ class CollaborationITCase { } } + private CreateCommandRequest buildCreateCollaborationVorgangCommand(String vorgangId, int collaborationLevel) { + return CreateCommandRequest.builder() + .callContext(CallContext.builder().client("test").build()) + .vorgangId(vorgangId) + .relationId(vorgangId) + .order("CREATE_COLLABORATION_REQUEST") + .bodyObject(Map.of( + "titel", TITEL, + "anfrage", ANFRAGE, + "collaborationLevel", collaborationLevel, + "zustaendigeStelle", ZustaendigeStelleTestFactory.ORGANISATIONSEINHEIT_ID)) + .build(); + } + private List<VorgangAttachedItem> loadCollaborationRequest(String vorgangId) { var query = new Query(new Criteria().andOperator( Criteria.where(VorgangAttachedItem.FIELDNAME_VORGANG_ID).is(vorgangId), @@ -212,16 +212,10 @@ class CollaborationITCase { return mongoOperations.find(query, VorgangAttachedItem.class); } - private void waitUntilCommandFinished(String commandId) { - await().atMost(60, TimeUnit.SECONDS).until( - () -> mongoOperations.findById(commandId, Command.class), - command -> command.getStatus() == CommandStatus.FINISHED); - } - - private void waitUntilCommandError(String commandId) { + private void waitUntilCommandHasStatus(String commandId, CommandStatus status) { await().atMost(60, TimeUnit.SECONDS).until( () -> mongoOperations.findById(commandId, Command.class), - command -> command.getStatus() == CommandStatus.ERROR); + command -> command.getStatus() == status); } @Nested @@ -235,9 +229,10 @@ class CollaborationITCase { @Test void shouldSetCollaborationVorgangId() { - var command = commandService.createCommand(buildCreateCollaborationVorgangCommand(vorgangId, 1)); + var command = commandService.createCommand( + buildCreateCollaborationVorgangCommand(vorgangId, CreateCollaborationVorgangRequestTestFactory.COLLABORATION_LEVEL)); - waitUntilCommandFinished(command.getId()); + waitUntilCommandHasStatus(command.getId(), CommandStatus.FINISHED); var collaborationRequests = loadCollaborationRequest(vorgangId); assertThat(collaborationRequests).hasSize(1).first().extracting(VorgangAttachedItem::getItem, MAP) @@ -246,9 +241,10 @@ class CollaborationITCase { @Test void shouldCreateCollaborationVorgang() { - var command = commandService.createCommand(buildCreateCollaborationVorgangCommand(vorgangId, 1)); + var command = commandService.createCommand( + buildCreateCollaborationVorgangCommand(vorgangId, CreateCollaborationVorgangRequestTestFactory.COLLABORATION_LEVEL)); - waitUntilCommandFinished(command.getId()); + waitUntilCommandHasStatus(command.getId(), CommandStatus.FINISHED); var collaborationVorgang = loadCollaborationVorgang(vorgangId); assertThat(collaborationVorgang.getHeader()).extracting(VorgangHead::getCollaborationLevel) @@ -268,8 +264,10 @@ class CollaborationITCase { @Nested class TestCreateFachstellenBeteiligungRequest { + private static final int COLLABORATION_LEVEL = 4; + @Captor - private ArgumentCaptor<PostfachNachricht> postfachMailCaptor; + private ArgumentCaptor<PostfachNachricht> postfachNachrichtCaptor; @BeforeEach void init() { @@ -279,9 +277,9 @@ class CollaborationITCase { @Test void shouldCreateCollaborationRequest() { - var command = commandService.createCommand(buildCreateCollaborationVorgangCommand(vorgangId, 4)); + var command = commandService.createCommand(buildCreateCollaborationVorgangCommand(vorgangId, COLLABORATION_LEVEL)); - waitUntilCommandFinished(command.getId()); + waitUntilCommandHasStatus(command.getId(), CommandStatus.FINISHED); var collaborationRequests = loadCollaborationRequest(vorgangId); assertThat(collaborationRequests).hasSize(1).first().extracting(VorgangAttachedItem::getItem, MAP) @@ -289,25 +287,24 @@ class CollaborationITCase { } @Test - void shouldSendPostfachMail() { - var command = commandService.createCommand(buildCreateCollaborationVorgangCommand(vorgangId, 4)); + void shouldSendPostfachNachricht() { + var command = commandService.createCommand(buildCreateCollaborationVorgangCommand(vorgangId, COLLABORATION_LEVEL)); - waitUntilCommandFinished(command.getId()); + waitUntilCommandHasStatus(command.getId(), CommandStatus.FINISHED); - verify(postfachRemoteService).sendMessage(postfachMailCaptor.capture()); - assertThat(postfachMailCaptor.getValue().getPostfachAddress()).extracting(PostfachAddress::getIdentifier) + verify(postfachRemoteService).sendMessage(postfachNachrichtCaptor.capture()); + assertThat(postfachNachrichtCaptor.getValue().getPostfachAddress()).extracting(PostfachAddress::getIdentifier) .hasToString(PostfachAddressTestFactory.STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE); } @Test void shouldDeleteCollaborationRequest() { doThrow(TechnicalException.class).when(postfachRemoteService).sendMessage(any()); - var command = commandService.createCommand(buildCreateCollaborationVorgangCommand(vorgangId, 4)); + var command = commandService.createCommand(buildCreateCollaborationVorgangCommand(vorgangId, COLLABORATION_LEVEL)); - waitUntilCommandError(command.getId()); + waitUntilCommandHasStatus(command.getId(), CommandStatus.ERROR); assertThat(loadCollaborationRequest(vorgangId)).isEmpty(); } } - } \ No newline at end of file diff --git a/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/command/CommandRepositoryITCase.java b/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/command/CommandRepositoryITCase.java index 5d8a9b645f93e81a213124bf6f8c25cd2395d123..9eaa3375a1aa56c43b7dce6e75254c711e6075c8 100644 --- a/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/command/CommandRepositoryITCase.java +++ b/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/command/CommandRepositoryITCase.java @@ -665,7 +665,7 @@ class CommandRepositoryITCase { } private void setRevokeStatusWithResource(String commandId) { - repository.setRevokeStatusWithResource(commandId, CommandTestFactory.CREATED_RESOURCE); + repository.setRevokeStatus(commandId, CommandTestFactory.CREATED_RESOURCE); } } diff --git a/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/command/CommandServiceTest.java b/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/command/CommandServiceTest.java index d1c5e210b6f5dec73bbc8476cd444180dc6371a2..3f4d68d90efa91280762ec75d49a7692d352a175 100644 --- a/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/command/CommandServiceTest.java +++ b/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/command/CommandServiceTest.java @@ -219,7 +219,7 @@ class CommandServiceTest { @BeforeEach void init() { - when(repository.setRevokeStatusWithResource(anyString(), anyString())).thenReturn(REVOKE_PENDING_COMMAND); + when(repository.setRevokeStatus(anyString(), anyString())).thenReturn(REVOKE_PENDING_COMMAND); doReturn(true).when(service).shouldRevoke(any()); doReturn(REVOKE_PENDING_COMMAND).when(service).getById(anyString()); } @@ -235,7 +235,7 @@ class CommandServiceTest { void shouldCallRepository() { setCommandFinished(); - verify(repository).setRevokeStatusWithResource(CommandTestFactory.ID, CommandTestFactory.CREATED_RESOURCE); + verify(repository).setRevokeStatus(CommandTestFactory.ID, CommandTestFactory.CREATED_RESOURCE); } @Test