Compare commits
23 commits
80a8a74373
...
609cafcb71
Author | SHA1 | Date | |
---|---|---|---|
|
609cafcb71 | ||
|
3e92e2747c | ||
|
beb293753b | ||
57de299b99 | |||
154c38c29f | |||
0e5229520e | |||
d8bc3a5608 | |||
20492ecaef | |||
|
ec843eb946 | ||
28c5f8bbf3 | |||
|
397e8dd529 | ||
1b171cb085 | |||
2cf79e3568 | |||
d725addef8 | |||
165aee2ece | |||
e9e58b821e | |||
ca7ad3f19d | |||
d49d5233bf | |||
59e3bd1d53 | |||
0e4d58dc50 | |||
2e424484c3 | |||
cdb60f0d86 | |||
|
d84647f9e6 |
11 changed files with 439 additions and 99 deletions
|
@ -1,24 +1,12 @@
|
||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="Test" type="GradleRunConfiguration" factoryName="Gradle">
|
<configuration default="false" name="Test" type="JUnit" factoryName="JUnit">
|
||||||
<ExternalSystemSettings>
|
<module name="Project_Management_Tool.test" />
|
||||||
<option name="executionName" />
|
<option name="PACKAGE_NAME" value="" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="MAIN_CLASS_NAME" value="" />
|
||||||
<option name="externalSystemIdString" value="GRADLE" />
|
<option name="METHOD_NAME" value="" />
|
||||||
<option name="scriptParameters" value="" />
|
<option name="TEST_OBJECT" value="package" />
|
||||||
<option name="taskDescriptions">
|
<method v="2">
|
||||||
<list />
|
<option name="Make" enabled="true" />
|
||||||
</option>
|
</method>
|
||||||
<option name="taskNames">
|
|
||||||
<list>
|
|
||||||
<option value="test" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
<option name="vmOptions" />
|
|
||||||
</ExternalSystemSettings>
|
|
||||||
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
|
|
||||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
|
||||||
<DebugAllEnabled>false</DebugAllEnabled>
|
|
||||||
<RunAsTest>false</RunAsTest>
|
|
||||||
<method v="2" />
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</component>
|
</component>
|
125
api/pmt.yml
125
api/pmt.yml
|
@ -27,15 +27,80 @@ components:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: "#/components/schemas/ProjectInfo"
|
$ref: "#/components/schemas/ProjectInfo"
|
||||||
|
CreateProjectDTO:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
goal:
|
||||||
|
type: string
|
||||||
|
customerId:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
administratorId:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
start:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
plannedEnd:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
CreatedProjectDTO:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
goal:
|
||||||
|
type: string
|
||||||
|
customerId:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
administratorId:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
start:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
plannedEnd:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
responses:
|
responses:
|
||||||
UnAuthorized:
|
Unauthorized:
|
||||||
description: "Un Authorized"
|
description: "Unauthorized"
|
||||||
|
NotFound:
|
||||||
|
description: "Not Found"
|
||||||
|
content:
|
||||||
|
text/plain:
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
Conflict:
|
||||||
|
description: "Conflict"
|
||||||
|
content:
|
||||||
|
text/plain:
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
UnprocessableContent:
|
||||||
|
description: "Unprocessable Content"
|
||||||
|
content:
|
||||||
|
text/plain:
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
InternalError:
|
InternalError:
|
||||||
description: "Internal Server Error"
|
description: "Internal Server Error"
|
||||||
content:
|
content:
|
||||||
text/plain:
|
text/plain:
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
|
ServiceUnavailable:
|
||||||
|
description: "Service Unavailable"
|
||||||
|
content:
|
||||||
|
text/plain:
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
paths:
|
paths:
|
||||||
/project:
|
/project:
|
||||||
get:
|
get:
|
||||||
|
@ -49,6 +114,58 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/GetAllProjectsDTO"
|
$ref: "#/components/schemas/GetAllProjectsDTO"
|
||||||
401:
|
401:
|
||||||
$ref: "#/components/responses/UnAuthorized"
|
$ref: "#/components/responses/Unauthorized"
|
||||||
500:
|
500:
|
||||||
$ref: "#/components/responses/InternalError"
|
$ref: "#/components/responses/InternalError"
|
||||||
|
post:
|
||||||
|
operationId: "CreateProject"
|
||||||
|
description: "Creates a new Project"
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/CreateProjectDTO"
|
||||||
|
responses:
|
||||||
|
201:
|
||||||
|
description: "Project created successfully"
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/CreatedProjectDTO"
|
||||||
|
401:
|
||||||
|
$ref: "#/components/responses/Unauthorized"
|
||||||
|
404:
|
||||||
|
$ref: "#/components/responses/NotFound"
|
||||||
|
409:
|
||||||
|
$ref: "#/components/responses/Conflict"
|
||||||
|
422:
|
||||||
|
$ref: "#/components/responses/UnprocessableContent"
|
||||||
|
500:
|
||||||
|
$ref: "#/components/responses/InternalError"
|
||||||
|
503:
|
||||||
|
$ref: "#/components/responses/ServiceUnavailable"
|
||||||
|
/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"
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"invokerPackage": "de.hmmh.pmt",
|
"invokerPackage": "de.hmmh.pmt",
|
||||||
"java8": false,
|
"java8": false,
|
||||||
"java11": true,
|
"java11": true,
|
||||||
"dateLibrary": "java11",
|
"dateLibrary": "java8-localdatetime",
|
||||||
"library": "spring-boot3",
|
"library": "spring-boot3",
|
||||||
"defaultInterfaces": false,
|
"defaultInterfaces": false,
|
||||||
"serializableModel": true
|
"serializableModel": true
|
||||||
|
|
|
@ -1,29 +1,35 @@
|
||||||
package de.hmmh.pmt;
|
package de.hmmh.pmt;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import de.hmmh.pmt.employee.ApiClientFactory;
|
|
||||||
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.oas.DefaultApi;
|
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
||||||
|
import de.hmmh.pmt.dtos.CreatedProjectDTO;
|
||||||
import de.hmmh.pmt.dtos.GetAllProjectsDTO;
|
import de.hmmh.pmt.dtos.GetAllProjectsDTO;
|
||||||
import de.hmmh.pmt.dtos.ProjectInfo;
|
import de.hmmh.pmt.dtos.ProjectInfo;
|
||||||
|
import de.hmmh.pmt.employee.ApiClientFactory;
|
||||||
|
import de.hmmh.pmt.oas.DefaultApi;
|
||||||
|
import de.hmmh.pmt.util.Mapper;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
|
import org.springframework.web.client.RestClientException;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("${openapi.projectManagement.base-path:/api/v1}")
|
@RequestMapping("${openapi.projectManagement.base-path:/api/v1}")
|
||||||
public class ApiController implements DefaultApi {
|
public class ApiController implements DefaultApi {
|
||||||
|
@Autowired
|
||||||
|
private Mapper mapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApiClientFactory apiClientFactory;
|
private ApiClientFactory apiClientFactory;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ProjectRepository projectRepository;
|
private ProjectRepository projectRepository;
|
||||||
|
|
||||||
// apiClientFactory.getEmployeeApi().findAll1()
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<ObjectMapper> getObjectMapper() {
|
public Optional<ObjectMapper> getObjectMapper() {
|
||||||
|
@ -35,11 +41,21 @@ public class ApiController implements DefaultApi {
|
||||||
return Optional.empty();
|
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
|
@Override
|
||||||
public ResponseEntity<GetAllProjectsDTO> getAllProjects() {
|
public ResponseEntity<GetAllProjectsDTO> getAllProjects() {
|
||||||
GetAllProjectsDTO response = new GetAllProjectsDTO();
|
GetAllProjectsDTO response = new GetAllProjectsDTO();
|
||||||
|
|
||||||
for (Project project : this.projectRepository.findAll()){
|
for (Project project : this.projectRepository.findAll()) {
|
||||||
ProjectInfo projectInfo = new ProjectInfo();
|
ProjectInfo projectInfo = new ProjectInfo();
|
||||||
projectInfo.setId(project.getId());
|
projectInfo.setId(project.getId());
|
||||||
projectInfo.setName(project.getName());
|
projectInfo.setName(project.getName());
|
||||||
|
@ -48,4 +64,32 @@ public class ApiController implements DefaultApi {
|
||||||
|
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<CreatedProjectDTO> createProject(CreateProjectDTO body) {
|
||||||
|
if (projectRepository.existsByName(body.getName())) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.CONFLICT);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
apiClientFactory.getEmployeeApi().findById(body.getAdministratorId());
|
||||||
|
} catch (HttpClientErrorException exception) {
|
||||||
|
return new ResponseEntity<>(
|
||||||
|
exception.getStatusCode().equals(HttpStatus.NOT_FOUND)
|
||||||
|
? HttpStatus.NOT_FOUND
|
||||||
|
: HttpStatus.SERVICE_UNAVAILABLE
|
||||||
|
);
|
||||||
|
} catch (RestClientException exception) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
Project project = mapper.map(body);
|
||||||
|
if (!project.isValid()) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
projectRepository.save(project);
|
||||||
|
|
||||||
|
CreatedProjectDTO response = mapper.map(project);
|
||||||
|
return new ResponseEntity<>(response, HttpStatus.CREATED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
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;
|
||||||
|
@ -10,6 +13,7 @@ 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
|
||||||
|
@ -19,7 +23,7 @@ import java.time.LocalDateTime;
|
||||||
@Table(name = "project")
|
@Table(name = "project")
|
||||||
public class Project {
|
public class Project {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
|
@ -43,5 +47,16 @@ public class Project {
|
||||||
private LocalDateTime plannedEnd;
|
private LocalDateTime plannedEnd;
|
||||||
|
|
||||||
private LocalDateTime realEnd; // Cant be named just "end" because it's and SQL Keyword
|
private LocalDateTime realEnd; // Cant be named just "end" because it's and SQL Keyword
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isValid() {
|
||||||
|
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
|
||||||
|
Set<ConstraintViolation<Project>> violations = validator.validate(this);
|
||||||
|
|
||||||
|
return violations.isEmpty() &&
|
||||||
|
plannedEnd.isAfter(start) &&
|
||||||
|
(realEnd == null || realEnd.isAfter(start));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,4 +3,5 @@ package de.hmmh.pmt.db;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
public interface ProjectRepository extends JpaRepository<Project, Long> {
|
public interface ProjectRepository extends JpaRepository<Project, Long> {
|
||||||
|
boolean existsByName(String name);
|
||||||
}
|
}
|
||||||
|
|
32
src/main/java/de/hmmh/pmt/util/Mapper.java
Normal file
32
src/main/java/de/hmmh/pmt/util/Mapper.java
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package de.hmmh.pmt.util;
|
||||||
|
|
||||||
|
import de.hmmh.pmt.db.Project;
|
||||||
|
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
||||||
|
import de.hmmh.pmt.dtos.CreatedProjectDTO;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class Mapper {
|
||||||
|
public Project map(CreateProjectDTO dto) {
|
||||||
|
Project project = new Project();
|
||||||
|
project.setName(dto.getName());
|
||||||
|
project.setGoal(dto.getGoal());
|
||||||
|
project.setCustomerId(dto.getCustomerId());
|
||||||
|
project.setAdministratorId(dto.getAdministratorId());
|
||||||
|
project.setStart(dto.getStart());
|
||||||
|
project.setPlannedEnd(dto.getPlannedEnd());
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CreatedProjectDTO map(Project project) {
|
||||||
|
CreatedProjectDTO dto = new CreatedProjectDTO();
|
||||||
|
dto.setId(project.getId());
|
||||||
|
dto.setName(project.getName());
|
||||||
|
dto.setGoal(project.getGoal());
|
||||||
|
dto.setCustomerId(project.getCustomerId());
|
||||||
|
dto.setAdministratorId(project.getAdministratorId());
|
||||||
|
dto.setStart(project.getStart());
|
||||||
|
dto.setPlannedEnd(project.getPlannedEnd());
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,17 +1,22 @@
|
||||||
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.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;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureMockMvc(addFilters = false)
|
@AutoConfigureMockMvc(addFilters = false)
|
||||||
|
@ -23,8 +28,15 @@ 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();
|
||||||
|
@ -35,70 +47,65 @@ public abstract class IntegrationTest {
|
||||||
projectRepository.deleteAll();
|
projectRepository.deleteAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Project> createTestProjectData() {
|
protected Map<String, Project> createTestProjectData() {
|
||||||
Project project1 = new Project(
|
Map<String, Project> projects = new HashMap<>();
|
||||||
1L,
|
|
||||||
"Build a Dream Space Station",
|
Project researchLabProject = new Project();
|
||||||
"Launch a self-sustaining space habitat!",
|
researchLabProject.setName("Underwater Research Lab");
|
||||||
42L,
|
researchLabProject.setGoal( "Discover new marine species!");
|
||||||
101L,
|
researchLabProject.setCustomerId(73L);
|
||||||
LocalDateTime.of(2024, 3, 1, 10, 0),
|
researchLabProject.setAdministratorId(202L);
|
||||||
LocalDateTime.of(2028, 6, 30, 18, 0),
|
researchLabProject.setStart(LocalDateTime.of(2025, 5, 22, 8, 45));
|
||||||
LocalDateTime.of(2029, 12, 15, 16, 30)
|
researchLabProject.setPlannedEnd(LocalDateTime.of(2026, 5, 22, 8, 45));
|
||||||
);
|
projects.put("research-lab", researchLabProject);
|
||||||
Project project2 = new Project(
|
|
||||||
2L,
|
Project spaceStationProject = new Project();
|
||||||
"Underwater Research Lab",
|
spaceStationProject.setName("International Space Station Expansion");
|
||||||
"Discover new marine species!",
|
spaceStationProject.setGoal("Build new modules for extended research.");
|
||||||
73L,
|
spaceStationProject.setCustomerId(85L);
|
||||||
202L,
|
spaceStationProject.setAdministratorId(150L);
|
||||||
LocalDateTime.of(2025, 5, 22, 8, 45),
|
spaceStationProject.setStart(LocalDateTime.of(2024, 10, 15, 10, 0));
|
||||||
LocalDateTime.of(2027, 11, 5, 17, 0),
|
spaceStationProject.setPlannedEnd(LocalDateTime.of(2025, 12, 15, 10, 0));
|
||||||
LocalDateTime.of(2027, 10, 20, 14, 0)
|
projects.put("space-station", spaceStationProject);
|
||||||
);
|
|
||||||
Project project3 = new Project(
|
Project aiResearchProject = new Project();
|
||||||
3L,
|
aiResearchProject.setName("AI Human Interaction Study");
|
||||||
"AI-Powered Smart City",
|
aiResearchProject.setGoal("Study AI interactions in healthcare.");
|
||||||
"Create the world's most advanced smart city!",
|
aiResearchProject.setCustomerId(63L);
|
||||||
89L,
|
aiResearchProject.setAdministratorId(180L);
|
||||||
303L,
|
aiResearchProject.setStart(LocalDateTime.of(2023, 11, 3, 9, 30));
|
||||||
LocalDateTime.of(2026, 9, 14, 12, 0),
|
aiResearchProject.setPlannedEnd(LocalDateTime.of(2024, 6, 3, 9, 30));
|
||||||
LocalDateTime.of(2030, 4, 1, 9, 30),
|
projects.put("ai-research", aiResearchProject);
|
||||||
LocalDateTime.of(2030, 5, 2, 15, 0)
|
|
||||||
);
|
Project renewableEnergyProject = new Project();
|
||||||
Project project4 = new Project(
|
renewableEnergyProject.setName("Renewable Energy Storage System");
|
||||||
4L,
|
renewableEnergyProject.setGoal("Develop new battery tech for solar power.");
|
||||||
"Renewable Energy Revolution",
|
renewableEnergyProject.setCustomerId(90L);
|
||||||
"Replace all fossil fuels with renewables!",
|
renewableEnergyProject.setAdministratorId(175L);
|
||||||
56L,
|
renewableEnergyProject.setStart(LocalDateTime.of(2024, 1, 10, 11, 0));
|
||||||
404L,
|
renewableEnergyProject.setPlannedEnd(LocalDateTime.of(2025, 1, 10, 11, 0));
|
||||||
LocalDateTime.of(2023, 7, 19, 11, 30),
|
projects.put("renewable-energy", renewableEnergyProject);
|
||||||
LocalDateTime.of(2029, 12, 31, 20, 0),
|
|
||||||
LocalDateTime.of(2029, 10, 5, 18, 45)
|
Project climateChangeProject = new Project();
|
||||||
);
|
climateChangeProject.setName("Climate Change Impact Analysis");
|
||||||
Project project5 = new Project(
|
climateChangeProject.setGoal("Study global warming effects on ecosystems.");
|
||||||
5L,
|
climateChangeProject.setCustomerId(72L);
|
||||||
"Virtual Reality Theme Park",
|
climateChangeProject.setAdministratorId(190L);
|
||||||
"Build a fully immersive VR theme park!",
|
climateChangeProject.setStart(LocalDateTime.of(2025, 3, 12, 8, 0));
|
||||||
99L,
|
climateChangeProject.setPlannedEnd(LocalDateTime.of(2026, 3, 12, 8, 0));
|
||||||
505L,
|
projects.put("climate change", climateChangeProject);
|
||||||
LocalDateTime.of(2024, 2, 28, 9, 15),
|
|
||||||
LocalDateTime.of(2026, 9, 30, 17, 0),
|
|
||||||
LocalDateTime.of(2026, 8, 15, 13, 45)
|
Project medicalResearchProject = new Project();
|
||||||
);
|
medicalResearchProject.setName("Cancer Treatment Innovation");
|
||||||
|
medicalResearchProject.setGoal("Develop new gene therapy techniques.");
|
||||||
|
medicalResearchProject.setCustomerId(95L);
|
||||||
|
medicalResearchProject.setAdministratorId(155L);
|
||||||
|
medicalResearchProject.setStart(LocalDateTime.of(2024, 8, 20, 9, 15));
|
||||||
|
medicalResearchProject.setPlannedEnd(LocalDateTime.of(2026, 8, 20, 9, 15));
|
||||||
|
projects.put("medical-research", medicalResearchProject);
|
||||||
|
|
||||||
projectRepository.save(project1);
|
projectRepository.saveAllAndFlush(projects.values());
|
||||||
projectRepository.save(project2);
|
return projects;
|
||||||
projectRepository.save(project3);
|
|
||||||
projectRepository.save(project4);
|
|
||||||
projectRepository.save(project5);
|
|
||||||
|
|
||||||
return List.of(
|
|
||||||
project1,
|
|
||||||
project2,
|
|
||||||
project3,
|
|
||||||
project4,
|
|
||||||
project5
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
105
src/test/java/de/hmmh/pmt/project/CreateTest.java
Normal file
105
src/test/java/de/hmmh/pmt/project/CreateTest.java
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
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.HttpStatusCode;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.web.servlet.RequestBuilder;
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
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 {
|
||||||
|
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
|
||||||
|
.thenReturn(new EmployeeResponseDTO());
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
RequestBuilder requestBuilder = MockMvcRequestBuilders
|
||||||
|
.post(baseUri + "/project")
|
||||||
|
.accept(MediaType.APPLICATION_JSON)
|
||||||
|
.content(this.objectMapper.writeValueAsString(createDTO))
|
||||||
|
.contentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
|
this.mvc
|
||||||
|
.perform(requestBuilder)
|
||||||
|
.andExpect(status().isCreated())
|
||||||
|
.andExpect(jsonPath("$.id").exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldNotCreateProjectWithSameName() throws Exception {
|
||||||
|
|
||||||
|
CreateProjectDTO createDTO = new CreateProjectDTO();
|
||||||
|
createDTO.setName("Test");
|
||||||
|
createDTO.setGoal("A Test Goal");
|
||||||
|
createDTO.setCustomerId(10L);
|
||||||
|
createDTO.setAdministratorId(1L);
|
||||||
|
createDTO.setStart(LocalDateTime.of(2000, 1, 13, 12, 51));
|
||||||
|
createDTO.setPlannedEnd(LocalDateTime.of(2002, 3, 21, 11, 42));
|
||||||
|
|
||||||
|
RequestBuilder firstProjectRequestBuilder = createProjectRequestBuilder(createDTO);
|
||||||
|
|
||||||
|
this.mvc
|
||||||
|
.perform(firstProjectRequestBuilder)
|
||||||
|
.andExpect(status().isCreated())
|
||||||
|
.andExpect(jsonPath("$.id").exists());
|
||||||
|
|
||||||
|
RequestBuilder secondProjectRequestBuilder = createProjectRequestBuilder(createDTO);
|
||||||
|
|
||||||
|
this.mvc
|
||||||
|
.perform(secondProjectRequestBuilder)
|
||||||
|
.andExpect(status().isConflict());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldNotCreateProjectWhenAdministratorDoesNotExist() throws Exception {
|
||||||
|
HttpClientErrorException httpClientErrorException = mock(HttpClientErrorException.class);
|
||||||
|
|
||||||
|
when(httpClientErrorException.getStatusCode()).thenReturn(HttpStatusCode.valueOf(404));
|
||||||
|
|
||||||
|
when(this.mockEmployeeApi.findById(1L))
|
||||||
|
.thenThrow(httpClientErrorException);
|
||||||
|
|
||||||
|
CreateProjectDTO createDTO = new CreateProjectDTO();
|
||||||
|
createDTO.setName("Test");
|
||||||
|
createDTO.setGoal("A Test Goal");
|
||||||
|
createDTO.setCustomerId(10L);
|
||||||
|
createDTO.setAdministratorId(1L);
|
||||||
|
createDTO.setStart(LocalDateTime.of(2000, 1, 13, 12, 51));
|
||||||
|
createDTO.setPlannedEnd(LocalDateTime.of(2002, 3, 21, 11, 42));
|
||||||
|
|
||||||
|
RequestBuilder projectRequestBuilder = createProjectRequestBuilder(createDTO);
|
||||||
|
|
||||||
|
this.mvc
|
||||||
|
.perform(projectRequestBuilder)
|
||||||
|
.andExpect(status().isNotFound());
|
||||||
|
}
|
||||||
|
|
||||||
|
private RequestBuilder createProjectRequestBuilder(CreateProjectDTO createDTO) throws Exception {
|
||||||
|
|
||||||
|
return MockMvcRequestBuilders
|
||||||
|
.post(baseUri + "/project")
|
||||||
|
.accept(MediaType.APPLICATION_JSON)
|
||||||
|
.content(this.objectMapper.writeValueAsString(createDTO))
|
||||||
|
.contentType(MediaType.APPLICATION_JSON);
|
||||||
|
}
|
||||||
|
}
|
31
src/test/java/de/hmmh/pmt/project/DeleteTest.java
Normal file
31
src/test/java/de/hmmh/pmt/project/DeleteTest.java
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
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 java.util.Map;
|
||||||
|
|
||||||
|
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 {
|
||||||
|
Map<String,Project> allProjects = createTestProjectData();
|
||||||
|
mvc
|
||||||
|
.perform(delete(baseUri + "/project/" + allProjects.get("space-station").getId()))
|
||||||
|
.andExpect(status().isNoContent())
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ import de.hmmh.pmt.IntegrationTest;
|
||||||
import de.hmmh.pmt.db.Project;
|
import de.hmmh.pmt.db.Project;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.empty;
|
import static org.hamcrest.Matchers.empty;
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
|
@ -25,7 +25,7 @@ public class GetAllTest extends IntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void multipleProjects() throws Exception {
|
void multipleProjects() throws Exception {
|
||||||
List<Project> allProjects = createTestProjectData();
|
Map<String, Project> allProjects = createTestProjectData();
|
||||||
|
|
||||||
mvc
|
mvc
|
||||||
.perform(get(baseUri + "/project"))
|
.perform(get(baseUri + "/project"))
|
||||||
|
|
Loading…
Reference in a new issue