Compare commits

..

7 commits

Author SHA1 Message Date
16be291a8d
PMT-16: Implement New Endpoint Logic
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 1m10s
Quality Check / Static Analysis (push) Successful in 1m14s
Co-authored-by: Rajbir Singh <rajbir.singh@hmmh.de>
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
2024-10-07 16:05:32 +02:00
718e58ff18
PMT-16: Add Validation for Time Range to Project Entity
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
2024-10-07 16:03:18 +02:00
3aaab8e9f2
PMT-16: Add Mapper for Project Creation/Created DTO to/from Project Entity
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
2024-10-07 16:03:18 +02:00
Rajbir Singh
d269fbff10 PMT-16: Add Method to Check if Project with Name Exists to ProjectRepository 2024-10-07 16:02:59 +02:00
e4d3549785
PMT-16: Change Java Datetime Library to be follow Spring Context.
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
2024-10-07 15:55:05 +02:00
673a07e5c1
PMT-16: Add More Errors to Endpoint Specification
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
2024-10-07 15:54:06 +02:00
Rajbir Singh
39aac07c98
PMT-16: Add Endpoint Specification 2024-10-07 15:53:26 +02:00
4 changed files with 1 additions and 69 deletions

View file

@ -110,7 +110,6 @@ tasks {
} }
withType<Test> { withType<Test> {
useJUnitPlatform() useJUnitPlatform()
maxParallelForks = 1
} }
named("compileJava").configure { named("compileJava").configure {
dependsOn(swaggerSources.getByName("pmt").code) dependsOn(swaggerSources.getByName("pmt").code)

View file

@ -1,9 +1,6 @@
package de.hmmh.pmt.db; package de.hmmh.pmt.db;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size; import jakarta.validation.constraints.Size;
@ -13,7 +10,6 @@ import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Set;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@ -50,13 +46,7 @@ public class Project {
public boolean isValid() { public boolean isValid() {
Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); return plannedEnd.isAfter(start) && (realEnd == null || realEnd.isAfter(start));
Set<ConstraintViolation<Project>> violations = validator.validate(this);
return violations.isEmpty() &&
plannedEnd.isAfter(start) &&
(realEnd == null || realEnd.isAfter(start));
} }
} }

View file

@ -1,17 +1,12 @@
package de.hmmh.pmt; package de.hmmh.pmt;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.hmmh.pmt.db.Project; import de.hmmh.pmt.db.Project;
import de.hmmh.pmt.db.ProjectRepository; import de.hmmh.pmt.db.ProjectRepository;
import de.hmmh.pmt.employee.ApiClientFactory;
import de.hmmh.pmt.employee.api.EmployeeControllerApi;
import de.hmmh.pmt.employee.api.QualificationControllerApi;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
@ -28,15 +23,8 @@ public abstract class IntegrationTest {
@Autowired @Autowired
protected MockMvc mvc; protected MockMvc mvc;
@Autowired @Autowired
protected ObjectMapper objectMapper;
@Autowired
protected ProjectRepository projectRepository; protected ProjectRepository projectRepository;
@MockBean
protected EmployeeControllerApi mockEmployeeApi;
@MockBean
protected QualificationControllerApi mockQualificationApi;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
projectRepository.deleteAll(); projectRepository.deleteAll();

View file

@ -1,45 +0,0 @@
package de.hmmh.pmt.project;
import de.hmmh.pmt.IntegrationTest;
import de.hmmh.pmt.dtos.CreateProjectDTO;
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.time.LocalDateTime;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class CreateTest extends IntegrationTest {
@Test
void successfullyCreate() throws Exception {
CreateProjectDTO createDTO = new CreateProjectDTO();
createDTO.setName("Test");
createDTO.setGoal("A Test Goal");
createDTO.setCustomerId(10L);
createDTO.setAdministratorId(10L);
createDTO.setStart(LocalDateTime.of(2000, 1, 13, 12, 51));
createDTO.setPlannedEnd(LocalDateTime.of(2002, 3, 21, 11, 42));
String body = objectMapper.writeValueAsString(createDTO);
RequestBuilder requestBuilder = MockMvcRequestBuilders
.post(baseUri + "/project")
.accept(MediaType.APPLICATION_JSON)
.content(body)
.contentType(MediaType.APPLICATION_JSON);
Mockito.when(mockEmployeeApi.findById(Mockito.anyLong())).thenReturn(new EmployeeResponseDTO());
mvc
.perform(requestBuilder)
.andExpect(status().isCreated())
.andExpect(jsonPath("$.id").exists())
;
}
}