Compare commits

...

3 commits

Author SHA1 Message Date
cf62906161 PMT-15: Implement Tests for Responses
All checks were successful
Quality Check / Validate OAS (push) Successful in 33s
Quality Check / Linting (push) Successful in 1m8s
Quality Check / Testing (push) Successful in 1m9s
Quality Check / Static Analysis (push) Successful in 1m13s
2024-10-09 10:51:03 +02:00
98b1e40dc9 PMT-15: added api documentation 2024-10-09 10:49:49 +02:00
aef63bcec3 PMT-15: Added a deleteProject by ID method 2024-10-09 10:42:37 +02:00
3 changed files with 67 additions and 1 deletions

View file

@ -51,4 +51,30 @@ paths:
401:
$ref: "#/components/responses/UnAuthorized"
500:
$ref: "#/components/responses/InternalError"
$ref: "#/components/responses/InternalError"
/project/{id}:
delete:
operationId: "deleteProject"
description: "Delete a specific Project"
parameters:
- in: path
name: id
schema:
type: integer
format: int64
required: true
responses:
204:
description: "Deletes a specific Project"
401:
$ref: "#/components/responses/UnAuthorized"
404:
description: "Project not found"
content:
text/plain:
schema:
type: string
500:
$ref: "#/components/responses/InternalError"

View file

@ -35,6 +35,16 @@ public class ApiController implements DefaultApi {
return Optional.empty();
}
@Override
public ResponseEntity<Void> deleteProject(Long id) {
if (!projectRepository.existsById(id)) {
return ResponseEntity.notFound().build();
}
projectRepository.deleteById(id);
return ResponseEntity.noContent().build();
}
@Override
public ResponseEntity<GetAllProjectsDTO> getAllProjects() {
GetAllProjectsDTO response = new GetAllProjectsDTO();

View file

@ -0,0 +1,30 @@
package de.hmmh.pmt.project;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.List;
import org.junit.jupiter.api.Test;
import de.hmmh.pmt.IntegrationTest;
import de.hmmh.pmt.db.Project;
public class DeleteTest extends IntegrationTest {
@Test
void projectNotFound() throws Exception {
mvc
.perform(delete(baseUri + "/project/1"))
.andExpect(status().isNotFound())
;
}
@Test
void deletedSuccessfully() throws Exception {
List<Project> allProjects = createTestProjectData();
mvc
.perform(delete(baseUri + "/project/" + allProjects.get(1).getId()))
.andExpect(status().isNoContent())
;
}
}