PMT-2: Setup
This commit is contained in:
parent
977d20d840
commit
47ddf4158a
20 changed files with 368 additions and 22 deletions
57
.gitignore
vendored
57
.gitignore
vendored
|
@ -1,26 +1,39 @@
|
||||||
# ---> Java
|
.gradle
|
||||||
# Compiled class file
|
gradlew
|
||||||
*.class
|
gradlew.bat
|
||||||
|
build/
|
||||||
|
gradle/
|
||||||
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
# Log file
|
### STS ###
|
||||||
*.log
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
bin/
|
||||||
|
!**/src/main/**/bin/
|
||||||
|
!**/src/test/**/bin/
|
||||||
|
|
||||||
# BlueJ files
|
### IntelliJ IDEA ###
|
||||||
*.ctxt
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
out/
|
||||||
|
!**/src/main/**/out/
|
||||||
|
!**/src/test/**/out/
|
||||||
|
|
||||||
# Mobile Tools for Java (J2ME)
|
### NetBeans ###
|
||||||
.mtj.tmp/
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
# Package Files #
|
/dist/
|
||||||
*.jar
|
/nbdist/
|
||||||
*.war
|
/.nb-gradle/
|
||||||
*.nar
|
|
||||||
*.ear
|
|
||||||
*.zip
|
|
||||||
*.tar.gz
|
|
||||||
*.rar
|
|
||||||
|
|
||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
|
||||||
hs_err_pid*
|
|
||||||
replay_pid*
|
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
24
.run/Generate From OAS.run.xml
Normal file
24
.run/Generate From OAS.run.xml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Generate From OAS" type="GradleRunConfiguration" factoryName="Gradle">
|
||||||
|
<ExternalSystemSettings>
|
||||||
|
<option name="executionName" />
|
||||||
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="externalSystemIdString" value="GRADLE" />
|
||||||
|
<option name="scriptParameters" value="" />
|
||||||
|
<option name="taskDescriptions">
|
||||||
|
<list />
|
||||||
|
</option>
|
||||||
|
<option name="taskNames">
|
||||||
|
<list>
|
||||||
|
<option value="generateSwaggerCode" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
<option name="vmOptions" />
|
||||||
|
</ExternalSystemSettings>
|
||||||
|
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
|
||||||
|
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||||
|
<DebugAllEnabled>false</DebugAllEnabled>
|
||||||
|
<RunAsTest>false</RunAsTest>
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
11
.run/Postgres.run.xml
Normal file
11
.run/Postgres.run.xml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Postgres" type="docker-deploy" factoryName="docker-compose.yml" server-name="Docker">
|
||||||
|
<deployment type="docker-compose.yml">
|
||||||
|
<settings>
|
||||||
|
<option name="envFilePath" value="" />
|
||||||
|
<option name="sourceFilePath" value="compose.yml" />
|
||||||
|
</settings>
|
||||||
|
</deployment>
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
10
.run/Run.run.xml
Normal file
10
.run/Run.run.xml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Run" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
|
||||||
|
<module name="Project_Management_Tool.main" />
|
||||||
|
<option name="SPRING_BOOT_MAIN_CLASS" value="de.hmmh.pmt.ProjectManagementToolApplication" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
<option name="RunConfigurationTask" enabled="false" run_configuration_name="Postgres" run_configuration_type="docker-deploy" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
24
.run/Validate OAS.run.xml
Normal file
24
.run/Validate OAS.run.xml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Validate OAS" type="GradleRunConfiguration" factoryName="Gradle">
|
||||||
|
<ExternalSystemSettings>
|
||||||
|
<option name="executionName" />
|
||||||
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="externalSystemIdString" value="GRADLE" />
|
||||||
|
<option name="scriptParameters" value="" />
|
||||||
|
<option name="taskDescriptions">
|
||||||
|
<list />
|
||||||
|
</option>
|
||||||
|
<option name="taskNames">
|
||||||
|
<list>
|
||||||
|
<option value="validateSwagger" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
<option name="vmOptions" />
|
||||||
|
</ExternalSystemSettings>
|
||||||
|
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
|
||||||
|
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||||
|
<DebugAllEnabled>false</DebugAllEnabled>
|
||||||
|
<RunAsTest>false</RunAsTest>
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
84
build.gradle.kts
Normal file
84
build.gradle.kts
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
import org.hidetake.gradle.swagger.generator.GenerateSwaggerCode
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
java
|
||||||
|
id("org.springframework.boot") version "3.3.3"
|
||||||
|
id("io.spring.dependency-management") version "1.1.6"
|
||||||
|
id("org.hidetake.swagger.generator") version "2.19.2"
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "de.hmmh"
|
||||||
|
version = "0.0.1-SNAPSHOT"
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion = JavaLanguageVersion.of(22)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
compileOnly {
|
||||||
|
extendsFrom(configurations.annotationProcessor.get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
//Spring
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-validation")
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||||
|
runtimeOnly("org.postgresql:postgresql")
|
||||||
|
|
||||||
|
//Lombok
|
||||||
|
compileOnly("org.projectlombok:lombok")
|
||||||
|
annotationProcessor("org.projectlombok:lombok")
|
||||||
|
|
||||||
|
//Test
|
||||||
|
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||||
|
testImplementation("org.springframework.boot:spring-boot-testcontainers")
|
||||||
|
testImplementation("org.testcontainers:junit-jupiter")
|
||||||
|
testImplementation("org.testcontainers:postgresql")
|
||||||
|
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||||
|
|
||||||
|
//OAS
|
||||||
|
swaggerCodegen("org.openapitools:openapi-generator-cli:7.8.0")
|
||||||
|
implementation("io.swagger.core.v3:swagger-annotations:2.2.22")
|
||||||
|
}
|
||||||
|
|
||||||
|
swaggerSources {
|
||||||
|
register("pmt") {
|
||||||
|
setInputFile(file("${rootDir}/src/main/resources/api.yml"))
|
||||||
|
code.configFile = file("${rootDir}/src/main/resources/gen-config.json")
|
||||||
|
val validationTask = validation
|
||||||
|
code(delegateClosureOf<GenerateSwaggerCode> {
|
||||||
|
language = "spring"
|
||||||
|
components = listOf("models", "apis", "supportingFiles=ApiUtil.java")
|
||||||
|
code.rawOptions = listOf("--ignore-file-override=" + file("${rootDir}/src/main/resources/.codegen-ignore").absolutePath)
|
||||||
|
dependsOn(validationTask)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
processResources {
|
||||||
|
dependsOn(generateSwaggerCode)
|
||||||
|
}
|
||||||
|
withType<Test> {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
named("compileJava").configure {
|
||||||
|
dependsOn(swaggerSources.getByName("pmt").code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
java.srcDir("${swaggerSources.getByName("pmt").code.outputDir}/src/main/java")
|
||||||
|
resources.srcDir("${swaggerSources.getByName("pmt").code.outputDir}/src/main/resources")
|
||||||
|
}
|
||||||
|
}
|
16
compose.yml
Normal file
16
compose.yml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
container_name: pmt_postgres
|
||||||
|
image: postgres:16
|
||||||
|
environment:
|
||||||
|
- POSTGRES_DB=pmt
|
||||||
|
- POSTGRES_USER=pmt_user
|
||||||
|
- POSTGRES_PASSWORD=pmt123
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
volumes:
|
||||||
|
- "pmt_data:/var/lib/postgresql/data"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pmt_data:
|
||||||
|
name: pmt_data
|
1
settings.gradle.kts
Normal file
1
settings.gradle.kts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
rootProject.name = "Project Management Tool"
|
19
src/main/java/de/hmmh/pmt/ApiController.java
Normal file
19
src/main/java/de/hmmh/pmt/ApiController.java
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package de.hmmh.pmt;
|
||||||
|
|
||||||
|
import de.hmmh.pmt.oas.DefaultApi;
|
||||||
|
import de.hmmh.pmt.oas.HelloOut;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("${openapi.projectManagement.base-path:/api/v1}")
|
||||||
|
public class ApiController implements DefaultApi {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<HelloOut> getHello() throws Exception {
|
||||||
|
HelloOut hello = new HelloOut();
|
||||||
|
hello.setMsg("Hello World");
|
||||||
|
return ResponseEntity.ok(hello);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package de.hmmh.pmt;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class ProjectManagementToolApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(ProjectManagementToolApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
0
src/main/java/de/hmmh/pmt/oas/.gitkeep
Normal file
0
src/main/java/de/hmmh/pmt/oas/.gitkeep
Normal file
2
src/main/resources/.codegen-ignore
Normal file
2
src/main/resources/.codegen-ignore
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
**/*ApiController.java
|
||||||
|
**/org/openapitools/configuration/
|
43
src/main/resources/api.yml
Normal file
43
src/main/resources/api.yml
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
openapi: 3.0.0
|
||||||
|
info:
|
||||||
|
title: Project Management API
|
||||||
|
description: An API for Managing Internal tools
|
||||||
|
version: 1.0.0
|
||||||
|
servers:
|
||||||
|
- url: /api/v1
|
||||||
|
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
HelloOut:
|
||||||
|
description: "A Test Schema"
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
msg:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
OK:
|
||||||
|
description: "OK"
|
||||||
|
content:
|
||||||
|
text/plain:
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
InternalError:
|
||||||
|
description: "Internal Server Error"
|
||||||
|
content:
|
||||||
|
text/plain:
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
paths:
|
||||||
|
/hello:
|
||||||
|
get:
|
||||||
|
operationId: "GetHello"
|
||||||
|
description: "A Simple Hello World Endpoint"
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "A Hello Response"
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/HelloOut"
|
||||||
|
500:
|
||||||
|
$ref: "#/components/responses/InternalError"
|
9
src/main/resources/application.properties
Normal file
9
src/main/resources/application.properties
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# General
|
||||||
|
spring.application.name=Project Management Tool
|
||||||
|
server.port=8080
|
||||||
|
|
||||||
|
# DB
|
||||||
|
spring.datasource.url=jdbc:postgresql://localhost:5432/pmt
|
||||||
|
spring.datasource.username=pmt_user
|
||||||
|
spring.datasource.password=pmt123
|
||||||
|
spring.jpa.hibernate.ddl-auto=create-drop
|
20
src/main/resources/gen-config.json
Normal file
20
src/main/resources/gen-config.json
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"library": "spring-boot",
|
||||||
|
"dateLibrary": "java8",
|
||||||
|
"hideGenerationTimestamp": true,
|
||||||
|
"modelPackage": "de.hmmh.pmt.oas",
|
||||||
|
"apiPackage": "de.hmmh.pmt.oas",
|
||||||
|
"invokerPackage": "de.hmmh.pmt.oas",
|
||||||
|
"serializableModel": true,
|
||||||
|
"openApiNullable": false,
|
||||||
|
"useTags": true,
|
||||||
|
"useGzipFeature": true,
|
||||||
|
"unhandledException": true,
|
||||||
|
"useSpringBoot3": true,
|
||||||
|
"useSwaggerUI": true,
|
||||||
|
"importMappings": {
|
||||||
|
"ResourceSupport": "org.springframework.hateoas.RepresentationModel",
|
||||||
|
"Link": "org.springframework.hateoas.Link"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
26
src/test/java/de/hmmh/pmt/IntegrationTest.java
Normal file
26
src/test/java/de/hmmh/pmt/IntegrationTest.java
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
package de.hmmh.pmt;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@AutoConfigureMockMvc
|
||||||
|
@ActiveProfiles("test")
|
||||||
|
@ContextConfiguration(initializers = PostgresContextInitializer.class)
|
||||||
|
public abstract class IntegrationTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected MockMvc mockMvc;
|
||||||
|
|
||||||
|
//protected Repository repository;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
//repository.deleteAll();
|
||||||
|
}
|
||||||
|
}
|
28
src/test/java/de/hmmh/pmt/PostgresContextInitializer.java
Normal file
28
src/test/java/de/hmmh/pmt/PostgresContextInitializer.java
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package de.hmmh.pmt;
|
||||||
|
|
||||||
|
import org.springframework.boot.test.util.TestPropertyValues;
|
||||||
|
import org.springframework.context.ApplicationContextInitializer;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
import org.testcontainers.containers.PostgreSQLContainer;
|
||||||
|
import org.testcontainers.utility.DockerImageName;
|
||||||
|
|
||||||
|
public class PostgresContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||||
|
|
||||||
|
private static final PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(
|
||||||
|
DockerImageName.parse("postgres:16")
|
||||||
|
)
|
||||||
|
.withDatabaseName("test_db")
|
||||||
|
.withUsername("test-db-user")
|
||||||
|
.withPassword("test-db-password")
|
||||||
|
.withReuse(true);
|
||||||
|
|
||||||
|
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
|
||||||
|
postgres.start();
|
||||||
|
|
||||||
|
TestPropertyValues.of(
|
||||||
|
"spring.datasource.url=" + postgres.getJdbcUrl(),
|
||||||
|
"spring.datasource.username=" + postgres.getUsername(),
|
||||||
|
"spring.datasource.password=" + postgres.getPassword()
|
||||||
|
).applyTo(configurableApplicationContext.getEnvironment());
|
||||||
|
}
|
||||||
|
}
|
3
src/test/resources/application-test.properties
Normal file
3
src/test/resources/application-test.properties
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
spring.datasource.url=set_by_test_containers
|
||||||
|
spring.datasource.username=set_by_test_containers
|
||||||
|
spring.datasource.password=set_by_test_containers
|
Loading…
Reference in a new issue