Compare commits
7 commits
ec7b3b5e40
...
16be291a8d
Author | SHA1 | Date | |
---|---|---|---|
16be291a8d | |||
718e58ff18 | |||
3aaab8e9f2 | |||
|
d269fbff10 | ||
e4d3549785 | |||
673a07e5c1 | |||
|
39aac07c98 |
4 changed files with 1 additions and 69 deletions
|
@ -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)
|
||||||
|
|
|
@ -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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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())
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue