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 780422562068fdc5a704075b80056084a4d22624..bc044d9c64916d0b4b61fc4ea071c0a1b08b4920 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 @@ -33,6 +33,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -54,6 +55,7 @@ import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.gridfs.GridFsTemplate; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.util.ReflectionTestUtils; import com.google.protobuf.ByteString; import com.thedeanda.lorem.LoremIpsum; @@ -64,6 +66,7 @@ import de.ozgcloud.apilib.user.OzgCloudUserProfile; import de.ozgcloud.apilib.user.OzgCloudUserProfileService; import de.ozgcloud.collaboration.CollaborationManagerConfiguration; import de.ozgcloud.collaboration.CollaborationRequest; +import de.ozgcloud.collaboration.CollaborationService; import de.ozgcloud.collaboration.CollaborationServiceGrpc.CollaborationServiceBlockingStub; import de.ozgcloud.collaboration.GrpcGetFileContentRequest; import de.ozgcloud.collaboration.request.CollaborationRequestId; @@ -107,7 +110,7 @@ import net.devh.boot.grpc.client.inject.GrpcClient; }) @DataITCase @WithMockCustomUser -@DirtiesContext +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) class CollaborationITCase { private static final String FIELD_COLLABORATION_VORGANG_ID = "collaborationVorgangId"; @@ -117,6 +120,8 @@ class CollaborationITCase { @Autowired private CommandService commandService; + @Autowired + private CollaborationService collaborationService; @Autowired private MongoOperations mongoOperations; @@ -286,45 +291,59 @@ class CollaborationITCase { private static final int COLLABORATION_LEVEL = 4; - @Captor - private ArgumentCaptor<PostfachNachricht> postfachNachrichtCaptor; + @Nested + class TestSuccessfully { + @Captor + private ArgumentCaptor<PostfachNachricht> postfachNachrichtCaptor; + + @BeforeEach + void init() { + when(ozgCloudUserProfile.getId()).thenReturn(OzgCloudUserId.from(CommandTestFactory.CREATED_BY)); + when(collaborationOzgCloudUserProfileService.getById(any())).thenReturn(ozgCloudUserProfile); + } - @BeforeEach - void init() { - when(ozgCloudUserProfile.getId()).thenReturn(OzgCloudUserId.from(CommandTestFactory.CREATED_BY)); - when(collaborationOzgCloudUserProfileService.getById(any())).thenReturn(ozgCloudUserProfile); - } + @Test + void shouldCreateCollaborationRequest() { + var command = commandService.createCommand(buildCreateCollaborationVorgangCommand(vorgangId, COLLABORATION_LEVEL)); - @Test - void shouldCreateCollaborationRequest() { - var command = commandService.createCommand(buildCreateCollaborationVorgangCommand(vorgangId, COLLABORATION_LEVEL)); + waitUntilCommandHasStatus(command.getId(), CommandStatus.FINISHED); - waitUntilCommandHasStatus(command.getId(), CommandStatus.FINISHED); + var collaborationRequests = loadCollaborationRequest(vorgangId); + assertThat(collaborationRequests).hasSize(1).first().extracting(VorgangAttachedItem::getItem, MAP) + .containsEntry(FIELD_COLLABORATION_VORGANG_ID, vorgangId); + } - var collaborationRequests = loadCollaborationRequest(vorgangId); - assertThat(collaborationRequests).hasSize(1).first().extracting(VorgangAttachedItem::getItem, MAP) - .containsEntry(FIELD_COLLABORATION_VORGANG_ID, vorgangId); - } + @Test + void shouldSendPostfachNachricht() { + var command = commandService.createCommand(buildCreateCollaborationVorgangCommand(vorgangId, COLLABORATION_LEVEL)); - @Test - void shouldSendPostfachNachricht() { - var command = commandService.createCommand(buildCreateCollaborationVorgangCommand(vorgangId, COLLABORATION_LEVEL)); + waitUntilCommandHasStatus(command.getId(), CommandStatus.FINISHED); - waitUntilCommandHasStatus(command.getId(), CommandStatus.FINISHED); + verify(postfachRemoteService).sendMessage(postfachNachrichtCaptor.capture()); + assertThat(postfachNachrichtCaptor.getValue().getPostfachAddress()).extracting(PostfachAddress::getIdentifier) + .hasToString(MUK_POSTFACH_ID); + } + + @Test + void shouldDeleteCollaborationRequest() { + doThrow(TechnicalException.class).when(postfachRemoteService).sendMessage(any()); + var command = commandService.createCommand(buildCreateCollaborationVorgangCommand(vorgangId, COLLABORATION_LEVEL)); + + waitUntilCommandHasStatus(command.getId(), CommandStatus.ERROR); - verify(postfachRemoteService).sendMessage(postfachNachrichtCaptor.capture()); - assertThat(postfachNachrichtCaptor.getValue().getPostfachAddress()).extracting(PostfachAddress::getIdentifier) - .hasToString(MUK_POSTFACH_ID); + assertThat(loadCollaborationRequest(vorgangId)).isEmpty(); + } } @Test - void shouldDeleteCollaborationRequest() { - doThrow(TechnicalException.class).when(postfachRemoteService).sendMessage(any()); + void shouldFailOnMissingFachstelle() { + ReflectionTestUtils.setField(collaborationService, "urlProvider", Optional.empty()); var command = commandService.createCommand(buildCreateCollaborationVorgangCommand(vorgangId, COLLABORATION_LEVEL)); waitUntilCommandHasStatus(command.getId(), CommandStatus.ERROR); - assertThat(loadCollaborationRequest(vorgangId)).isEmpty(); + command = mongoOperations.findById(command.getId(), Command.class); + assertThat(command.getErrorMessage()).contains("Fachstelle not configured."); } }