From 9bcffd63b4cdf11dd3ae3ebd0e9ca5cd93b3fa19 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Thu, 8 Aug 2024 16:46:00 +0200
Subject: [PATCH] OZG-6311 OZG-6429 Implemenet CollaborationController

---
 .vscode/settings.json                         |   3 +-
 .../CollaborationController.java              |   8 +-
 .../collaboration/CollaborationRequest.java   |  11 ++
 .../CollaborationRequestModelAssembler.java   |  11 +-
 .../collaboration/CollaborationService.java   |   7 ++
 .../CollaborationControllerTest.java          | 108 ++++++++++++++++++
 .../CollaborationRequestTestFactory.java      |  20 ++++
 7 files changed, 162 insertions(+), 6 deletions(-)
 create mode 100644 alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationRequest.java
 create mode 100644 alfa-service/src/test/java/de/ozgcloud/alfa/collaboration/CollaborationControllerTest.java
 create mode 100644 alfa-service/src/test/java/de/ozgcloud/alfa/collaboration/CollaborationRequestTestFactory.java

diff --git a/.vscode/settings.json b/.vscode/settings.json
index 02ffa78fc2..9b1e544699 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,4 +1,5 @@
 {
   "angular.enable-strict-mode-prompt": false,
-  "java.debug.settings.onBuildFailureProceed": true
+  "java.debug.settings.onBuildFailureProceed": true,
+  "java.compile.nullAnalysis.mode": "automatic"
 }
\ No newline at end of file
diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationController.java b/alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationController.java
index dd5ef7149f..2381fc5224 100644
--- a/alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationController.java
+++ b/alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationController.java
@@ -1,12 +1,12 @@
 package de.ozgcloud.alfa.collaboration;
 
 import org.springframework.hateoas.EntityModel;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import de.ozgcloud.alfa.vorgang.Vorgang;
 import lombok.RequiredArgsConstructor;
 
 @RestController
@@ -17,10 +17,10 @@ public class CollaborationController {
 	private final CollaborationRequestModelAssembler assembler;
 	private final CollaborationService service;
 
-	static final String PATH = "/api/collaborationrequests/"; // NOSONAR
+	static final String PATH = "/api/collaborationrequests"; // NOSONAR
 
 	@GetMapping("/{collaborationRequestId}")
-	public EntityModel<Vorgang> getVorgangWithEingang(@PathVariable String collaborationRequestId) {
-		return null;
+	public ResponseEntity<EntityModel<CollaborationRequest>> getVorgangWithEingang(@PathVariable String collaborationRequestId) {
+		return ResponseEntity.of(service.getById(collaborationRequestId).map(assembler::toModel));
 	}
 }
diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationRequest.java b/alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationRequest.java
new file mode 100644
index 0000000000..0436edc096
--- /dev/null
+++ b/alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationRequest.java
@@ -0,0 +1,11 @@
+package de.ozgcloud.alfa.collaboration;
+
+import lombok.Builder;
+import lombok.Getter;
+
+@Getter
+@Builder
+class CollaborationRequest {
+
+	private String id;
+}
diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationRequestModelAssembler.java b/alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationRequestModelAssembler.java
index a529c62b75..e569d2b5bd 100644
--- a/alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationRequestModelAssembler.java
+++ b/alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationRequestModelAssembler.java
@@ -1,5 +1,14 @@
 package de.ozgcloud.alfa.collaboration;
 
-class CollaborationRequestModelAssembler {
+import org.springframework.hateoas.EntityModel;
+import org.springframework.hateoas.server.RepresentationModelAssembler;
+
+class CollaborationRequestModelAssembler implements RepresentationModelAssembler<CollaborationRequest, EntityModel<CollaborationRequest>> {
+
+	@Override
+	public EntityModel<CollaborationRequest> toModel(CollaborationRequest collaborationRequest) {
+		// TODO Auto-generated method stub
+		throw new UnsupportedOperationException("Unimplemented method 'toModel'");
+	}
 
 }
diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationService.java b/alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationService.java
index 82dec1c69c..13eaf13388 100644
--- a/alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationService.java
+++ b/alfa-service/src/main/java/de/ozgcloud/alfa/collaboration/CollaborationService.java
@@ -1,5 +1,12 @@
 package de.ozgcloud.alfa.collaboration;
 
+import java.util.Optional;
+
 class CollaborationService {
 
+	public Optional<CollaborationRequest> getById(String id) {
+		// TODO Auto-generated method stub
+		throw new UnsupportedOperationException("Unimplemented method 'getById'");
+	}
+
 }
diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/collaboration/CollaborationControllerTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/collaboration/CollaborationControllerTest.java
new file mode 100644
index 0000000000..bb5684cbb7
--- /dev/null
+++ b/alfa-service/src/test/java/de/ozgcloud/alfa/collaboration/CollaborationControllerTest.java
@@ -0,0 +1,108 @@
+package de.ozgcloud.alfa.collaboration;
+
+import static org.assertj.core.api.Assertions.*;
+import static org.mockito.Mockito.*;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
+
+import java.util.Optional;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.springframework.hateoas.EntityModel;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.ResultActions;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import lombok.SneakyThrows;
+
+class CollaborationControllerTest {
+
+	@InjectMocks
+	private CollaborationController controller;
+
+	@Mock
+	private CollaborationService service;
+
+	@Mock
+	private CollaborationRequestModelAssembler assembler;
+
+	private MockMvc mockMvc;
+
+	@BeforeEach
+	void initTest() {
+		mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
+	}
+
+	@Nested
+	class TestGetById {
+
+		private final CollaborationRequest collaborationRequest = CollaborationRequestTestFactory.create();
+
+		@SneakyThrows
+		@Test
+		void shouldCallCollaborationRequestService() {
+			performRequest();
+
+			verify(service).getById(CollaborationRequestTestFactory.ID);
+		}
+
+		@SneakyThrows
+		@Test
+		void shouldReturnStatusNotFoundIfCollaborationRequestDoesNotExist() {
+			when(service.getById(CollaborationRequestTestFactory.ID)).thenReturn(Optional.empty());
+
+			var response = performRequest();
+
+			response.andExpect(status().isNotFound());
+		}
+
+		@Nested
+		class TestOnExistingorganisationsEinheit {
+
+			@BeforeEach
+			void mock() {
+				when(service.getById(CollaborationRequestTestFactory.ID)).thenReturn(Optional.of(collaborationRequest));
+			}
+
+			@Test
+			void shouldCallAssembler() {
+				performRequest();
+
+				verify(assembler).toModel(collaborationRequest);
+			}
+
+			@SneakyThrows
+			@Test
+			void shouldReturnStatusOk() {
+				when(assembler.toModel(collaborationRequest)).thenReturn(EntityModel.of(collaborationRequest));
+
+				var response = performRequest();
+
+				response.andExpect(status().isOk());
+			}
+
+			@SneakyThrows
+			@Test
+			void shouldReturnCollaborationRequestModel() {
+				var objectMapper = new ObjectMapper();
+				when(assembler.toModel(collaborationRequest)).thenReturn(EntityModel.of(collaborationRequest));
+
+				var response = performRequest();
+
+				assertThat(response.andReturn().getResponse().getContentAsString())
+						.contains(objectMapper.writeValueAsString(collaborationRequest).replaceAll("[\\{\\}]", ""));
+			}
+		}
+
+		@SneakyThrows
+		private ResultActions performRequest() {
+			return mockMvc.perform(get(CollaborationController.PATH + "/" + CollaborationRequestTestFactory.ID));
+		}
+	}
+}
diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/collaboration/CollaborationRequestTestFactory.java b/alfa-service/src/test/java/de/ozgcloud/alfa/collaboration/CollaborationRequestTestFactory.java
new file mode 100644
index 0000000000..bf6c1e3090
--- /dev/null
+++ b/alfa-service/src/test/java/de/ozgcloud/alfa/collaboration/CollaborationRequestTestFactory.java
@@ -0,0 +1,20 @@
+package de.ozgcloud.alfa.collaboration;
+
+import java.util.UUID;
+
+import de.ozgcloud.alfa.collaboration.CollaborationRequest.CollaborationRequestBuilder;
+
+public class CollaborationRequestTestFactory {
+
+	public static final String ID = UUID.randomUUID().toString();
+
+	public static CollaborationRequest create() {
+		return createBuilder()
+				.build();
+	}
+
+	private static CollaborationRequestBuilder createBuilder() {
+		return CollaborationRequest.builder()
+				.id(ID);
+	}
+}
-- 
GitLab