Compare commits
9 commits
5c06b052af
...
4a89ba3a0a
Author | SHA1 | Date | |
---|---|---|---|
4a89ba3a0a | |||
bc6221f055 | |||
371bfd0cb3 | |||
06cea189b1 | |||
3ea112664d | |||
fc8cea3cd2 | |||
927ec19bed | |||
02d4fede5b | |||
f70b84a7a5 |
8 changed files with 212 additions and 65 deletions
32
api/pmt.yml
32
api/pmt.yml
|
@ -15,19 +15,21 @@ components:
|
||||||
scheme: bearer
|
scheme: bearer
|
||||||
bearerFormat: JWT
|
bearerFormat: JWT
|
||||||
schemas:
|
schemas:
|
||||||
HelloOut:
|
ProjectInfo:
|
||||||
description: "A Test Schema"
|
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
msg:
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
name:
|
||||||
type: string
|
type: string
|
||||||
|
GetAllProjectsDTO:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: "#/components/schemas/ProjectInfo"
|
||||||
responses:
|
responses:
|
||||||
OK:
|
UnAuthorized:
|
||||||
description: "OK"
|
description: "Un Authorized"
|
||||||
content:
|
|
||||||
text/plain:
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
InternalError:
|
InternalError:
|
||||||
description: "Internal Server Error"
|
description: "Internal Server Error"
|
||||||
content:
|
content:
|
||||||
|
@ -35,16 +37,18 @@ components:
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
paths:
|
paths:
|
||||||
/hello:
|
/project:
|
||||||
get:
|
get:
|
||||||
operationId: "GetHello"
|
operationId: "getAllProjects"
|
||||||
description: "A Simple Hello World Endpoint"
|
description: "Get a List of all Projects"
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: "A Hello Response"
|
description: "Returns a List of all Projects"
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/HelloOut"
|
$ref: "#/components/schemas/GetAllProjectsDTO"
|
||||||
|
401:
|
||||||
|
$ref: "#/components/responses/UnAuthorized"
|
||||||
500:
|
500:
|
||||||
$ref: "#/components/responses/InternalError"
|
$ref: "#/components/responses/InternalError"
|
|
@ -110,6 +110,7 @@ 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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -2,9 +2,11 @@ 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.employee.ApiClientFactory;
|
||||||
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
|
import de.hmmh.pmt.db.Project;
|
||||||
|
import de.hmmh.pmt.db.ProjectRepository;
|
||||||
import de.hmmh.pmt.oas.DefaultApi;
|
import de.hmmh.pmt.oas.DefaultApi;
|
||||||
import de.hmmh.pmt.dtos.HelloOut;
|
import de.hmmh.pmt.dtos.GetAllProjectsDTO;
|
||||||
|
import de.hmmh.pmt.dtos.ProjectInfo;
|
||||||
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.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
@ -18,6 +20,10 @@ import java.util.Optional;
|
||||||
public class ApiController implements DefaultApi {
|
public class ApiController implements DefaultApi {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApiClientFactory apiClientFactory;
|
private ApiClientFactory apiClientFactory;
|
||||||
|
@Autowired
|
||||||
|
private ProjectRepository projectRepository;
|
||||||
|
|
||||||
|
// apiClientFactory.getEmployeeApi().findAll1()
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<ObjectMapper> getObjectMapper() {
|
public Optional<ObjectMapper> getObjectMapper() {
|
||||||
|
@ -30,15 +36,16 @@ public class ApiController implements DefaultApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<HelloOut> getHello() {
|
public ResponseEntity<GetAllProjectsDTO> getAllProjects() {
|
||||||
|
GetAllProjectsDTO response = new GetAllProjectsDTO();
|
||||||
|
|
||||||
StringBuilder employees = new StringBuilder();
|
for (Project project : this.projectRepository.findAll()){
|
||||||
for (EmployeeResponseDTO employeeResponseDTO : apiClientFactory.getEmployeeApi().findAll1()) {
|
ProjectInfo projectInfo = new ProjectInfo();
|
||||||
employees.append(employeeResponseDTO.toString());
|
projectInfo.setId(project.getId());
|
||||||
|
projectInfo.setName(project.getName());
|
||||||
|
response.add(projectInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
HelloOut hello = new HelloOut();
|
return ResponseEntity.ok(response);
|
||||||
hello.setMsg(employees.toString());
|
|
||||||
return ResponseEntity.ok(hello);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
47
src/main/java/de/hmmh/pmt/db/Project.java
Normal file
47
src/main/java/de/hmmh/pmt/db/Project.java
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
package de.hmmh.pmt.db;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Entity
|
||||||
|
@Table(name = "project")
|
||||||
|
public class Project {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Size(min = 3, max = 64)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Size(min = 10)
|
||||||
|
private String goal;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Long customerId;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Long administratorId; // Is an Employee
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private LocalDateTime start;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private LocalDateTime plannedEnd;
|
||||||
|
|
||||||
|
private LocalDateTime realEnd; // Cant be named just "end" because it's and SQL Keyword
|
||||||
|
}
|
||||||
|
|
6
src/main/java/de/hmmh/pmt/db/ProjectRepository.java
Normal file
6
src/main/java/de/hmmh/pmt/db/ProjectRepository.java
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package de.hmmh.pmt.db;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface ProjectRepository extends JpaRepository<Project, Long> {
|
||||||
|
}
|
|
@ -1,16 +1,22 @@
|
||||||
package de.hmmh.pmt;
|
package de.hmmh.pmt;
|
||||||
|
|
||||||
//import de.hmmh.pmt.db.Project;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
//import de.hmmh.pmt.db.ProjectRepository;
|
import de.hmmh.pmt.db.Project;
|
||||||
|
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;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureMockMvc(addFilters = false)
|
@AutoConfigureMockMvc(addFilters = false)
|
||||||
|
@ -21,53 +27,90 @@ public abstract class IntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected MockMvc mvc;
|
protected MockMvc mvc;
|
||||||
//@Autowired
|
@Autowired
|
||||||
//protected ProjectRepository projectRepository;
|
protected ObjectMapper objectMapper;
|
||||||
|
@Autowired
|
||||||
|
protected ProjectRepository projectRepository;
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
protected EmployeeControllerApi mockEmployeeApi;
|
||||||
|
@MockBean
|
||||||
|
protected QualificationControllerApi mockQualificationApi;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
//projectRepository.deleteAll();
|
projectRepository.deleteAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
void cleanUp() {
|
void cleanUp() {
|
||||||
//projectRepository.deleteAll();
|
projectRepository.deleteAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createTestData() {
|
protected List<Project> createTestProjectData() {
|
||||||
/*Project testProject1 = new Project(
|
Project project1 = new Project(
|
||||||
0L,
|
1L,
|
||||||
"testName1",
|
"Build a Dream Space Station",
|
||||||
"testGoaaaaaaaal!",
|
"Launch a self-sustaining space habitat!",
|
||||||
0L,
|
42L,
|
||||||
0L,
|
101L,
|
||||||
LocalDateTime.of(2001, 9, 11, 13, 34),
|
LocalDateTime.of(2024, 3, 1, 10, 0),
|
||||||
LocalDateTime.of(2002, 8, 13, 14, 34),
|
LocalDateTime.of(2028, 6, 30, 18, 0),
|
||||||
LocalDateTime.of(2003, 7, 12, 23, 34)
|
LocalDateTime.of(2029, 12, 15, 16, 30)
|
||||||
);
|
);
|
||||||
Project testProject2 = new Project(
|
Project project2 = new Project(
|
||||||
0L,
|
2L,
|
||||||
"testName2",
|
"Underwater Research Lab",
|
||||||
"testGoaaaaaaaal!",
|
"Discover new marine species!",
|
||||||
0L,
|
73L,
|
||||||
0L,
|
202L,
|
||||||
LocalDateTime.of(2009, 9, 11, 13, 34),
|
LocalDateTime.of(2025, 5, 22, 8, 45),
|
||||||
LocalDateTime.of(2009, 12, 13, 14, 34),
|
LocalDateTime.of(2027, 11, 5, 17, 0),
|
||||||
LocalDateTime.of(2010, 7, 12, 23, 34)
|
LocalDateTime.of(2027, 10, 20, 14, 0)
|
||||||
);
|
);
|
||||||
Project testProject3 = new Project(
|
Project project3 = new Project(
|
||||||
0L,
|
3L,
|
||||||
"testName3",
|
"AI-Powered Smart City",
|
||||||
"testGoaaaaaaaal!",
|
"Create the world's most advanced smart city!",
|
||||||
0L,
|
89L,
|
||||||
0L,
|
303L,
|
||||||
LocalDateTime.of(2010, 9, 11, 13, 34),
|
LocalDateTime.of(2026, 9, 14, 12, 0),
|
||||||
LocalDateTime.of(2012, 8, 13, 14, 34),
|
LocalDateTime.of(2030, 4, 1, 9, 30),
|
||||||
LocalDateTime.of(2013, 7, 12, 23, 34)
|
LocalDateTime.of(2030, 5, 2, 15, 0)
|
||||||
|
);
|
||||||
|
Project project4 = new Project(
|
||||||
|
4L,
|
||||||
|
"Renewable Energy Revolution",
|
||||||
|
"Replace all fossil fuels with renewables!",
|
||||||
|
56L,
|
||||||
|
404L,
|
||||||
|
LocalDateTime.of(2023, 7, 19, 11, 30),
|
||||||
|
LocalDateTime.of(2029, 12, 31, 20, 0),
|
||||||
|
LocalDateTime.of(2029, 10, 5, 18, 45)
|
||||||
|
);
|
||||||
|
Project project5 = new Project(
|
||||||
|
5L,
|
||||||
|
"Virtual Reality Theme Park",
|
||||||
|
"Build a fully immersive VR theme park!",
|
||||||
|
99L,
|
||||||
|
505L,
|
||||||
|
LocalDateTime.of(2024, 2, 28, 9, 15),
|
||||||
|
LocalDateTime.of(2026, 9, 30, 17, 0),
|
||||||
|
LocalDateTime.of(2026, 8, 15, 13, 45)
|
||||||
|
);
|
||||||
|
|
||||||
|
projectRepository.save(project1);
|
||||||
|
projectRepository.save(project2);
|
||||||
|
projectRepository.save(project3);
|
||||||
|
projectRepository.save(project4);
|
||||||
|
projectRepository.save(project5);
|
||||||
|
|
||||||
|
return List.of(
|
||||||
|
project1,
|
||||||
|
project2,
|
||||||
|
project3,
|
||||||
|
project4,
|
||||||
|
project5
|
||||||
);
|
);
|
||||||
projectRepository.save(testProject1);
|
|
||||||
projectRepository.save(testProject2);
|
|
||||||
projectRepository.save(testProject3);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
39
src/test/java/de/hmmh/pmt/project/GetAllTest.java
Normal file
39
src/test/java/de/hmmh/pmt/project/GetAllTest.java
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package de.hmmh.pmt.project;
|
||||||
|
|
||||||
|
import de.hmmh.pmt.IntegrationTest;
|
||||||
|
|
||||||
|
import de.hmmh.pmt.db.Project;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.empty;
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
public class GetAllTest extends IntegrationTest {
|
||||||
|
@Test
|
||||||
|
void noProjects() throws Exception {
|
||||||
|
mvc
|
||||||
|
.perform(get(baseUri + "/project"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$", empty()))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void multipleProjects() throws Exception {
|
||||||
|
List<Project> allProjects = createTestProjectData();
|
||||||
|
|
||||||
|
mvc
|
||||||
|
.perform(get(baseUri + "/project"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$", hasSize(allProjects.size())))
|
||||||
|
.andExpect(jsonPath("$[*].id").exists())
|
||||||
|
.andExpect(jsonPath("$[*].name").exists())
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue