diff --git a/.vscode/settings.json b/.vscode/settings.json index 02ffa78fc20462c7539afdc7ef4cc8b7b63bdd1b..9b1e5446992d170181e31942d75d020e12bbe5d3 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 dd5ef7149fea4e8d6cb84ed297eca9f869cc88f9..2381fc522444b32691d541e6a279b9d28d7c9a00 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 0000000000000000000000000000000000000000..0436edc096345976c9f3f37b11d9420d5eaf9e8c --- /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 a529c62b757f3efc5cd4634a61f35245ec16c246..e569d2b5bdd7bb9c81665af1821594ee76cbcb2a 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 82dec1c69c19d31d72cee6d4d059726dade82008..13eaf1338880b974f32a5335083fcae0114c339f 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 0000000000000000000000000000000000000000..bb5684cbb71cd57181b371ce99fad3d503c34fa6 --- /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 0000000000000000000000000000000000000000..bf6c1e309025f7cf8a26e7df22f9353b5a5c7b99 --- /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); + } +}