From b2141964b9d52da32fdc66e6f92e0b91e8b91d0a Mon Sep 17 00:00:00 2001 From: Robert Mathew Date: Fri, 28 Jun 2024 19:13:04 +0530 Subject: [PATCH 1/5] Added Spring boot with status API --- .fleet/run.json | 24 +++++++++++ .fleet/settings.json | 12 ++++++ build.gradle.kts | 3 ++ gradle/libs.versions.toml | 12 +++--- server/build.gradle.kts | 42 +++++++++++++++++++ .../com/sphereon/oid/fed/Application.kt | 11 +++++ .../src/main/resources/application.properties | 4 ++ settings.gradle.kts | 1 + 8 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 .fleet/run.json create mode 100644 .fleet/settings.json create mode 100644 server/build.gradle.kts create mode 100644 server/src/main/kotlin/com/sphereon/oid/fed/Application.kt create mode 100644 server/src/main/resources/application.properties diff --git a/.fleet/run.json b/.fleet/run.json new file mode 100644 index 00000000..2054655b --- /dev/null +++ b/.fleet/run.json @@ -0,0 +1,24 @@ +{ + "configurations": [ + { + "name": "OpenID-Federation [:server:build]", + "type": "gradle", + "workingDir": "C:\\Users\\Robo\\Sphereon\\OpenID-Federation", + "tasks": [":server:build"], + "args": [""], + "initScripts": { + "flmapper": "ext.mapPath = { path -> null }" + } + }, + { + "name": "OpenID-Federation [build]", + "type": "gradle", + "workingDir": "C:\\Users\\Robo\\Sphereon\\OpenID-Federation", + "tasks": ["build"], + "args": [""], + "initScripts": { + "flmapper": "ext.mapPath = { path -> null }" + } + } + ] +} \ No newline at end of file diff --git a/.fleet/settings.json b/.fleet/settings.json new file mode 100644 index 00000000..9c37f817 --- /dev/null +++ b/.fleet/settings.json @@ -0,0 +1,12 @@ +{ + "plugins": [ + { + "type": "add", + "pluginName": "fleet.spring.boot" + }, + { + "type": "add", + "pluginName": "fleet.mercury" + } + ] +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index ec93b697..239576aa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,4 +7,7 @@ plugins { alias(libs.plugins.compose.compiler) apply false alias(libs.plugins.kotlinJvm) apply false alias(libs.plugins.kotlinMultiplatform) apply false + alias(libs.plugins.springboot) apply false + alias(libs.plugins.springDependencyManagement) apply false + alias(libs.plugins.kotlinPluginSpring) apply false } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4559b0da..3db9123b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,8 +14,8 @@ compose-plugin = "1.6.10" junit = "4.13.2" kotlin = "2.0.0" kotlinxSerializationJson = "1.7.0-RC" -ktor = "2.3.11" -logback = "1.5.6" +springboot = "3.3.1" +spingDependencyManagement = "1.1.5" [libraries] kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } @@ -29,10 +29,6 @@ androidx-material = { group = "com.google.android.material", name = "material", androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "androidx-constraintlayout" } androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" } -logback = { module = "ch.qos.logback:logback-classic", version.ref = "logback" } -ktor-server-core = { module = "io.ktor:ktor-server-core-jvm", version.ref = "ktor" } -ktor-server-netty = { module = "io.ktor:ktor-server-netty-jvm", version.ref = "ktor" } -ktor-server-tests = { module = "io.ktor:ktor-server-tests-jvm", version.ref = "ktor" } [plugins] androidApplication = { id = "com.android.application", version.ref = "agp" } @@ -40,5 +36,7 @@ androidLibrary = { id = "com.android.library", version.ref = "agp" } jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" } compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } -ktor = { id = "io.ktor.plugin", version.ref = "ktor" } kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +springboot = { id = "org.springframework.boot", version.ref = "springboot"} +springDependencyManagement = { id = "io.spring.dependency-management", version.ref = "spingDependencyManagement"} +kotlinPluginSpring = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotlin" } \ No newline at end of file diff --git a/server/build.gradle.kts b/server/build.gradle.kts new file mode 100644 index 00000000..62c99881 --- /dev/null +++ b/server/build.gradle.kts @@ -0,0 +1,42 @@ +plugins { + alias(libs.plugins.springboot) + alias(libs.plugins.springDependencyManagement) + alias(libs.plugins.kotlinJvm) + alias(libs.plugins.kotlinPluginSpring) + application +} + +group = "com.sphereon.oid.fed" +version = "1.0.0" + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +dependencies { + + implementation("org.springframework.boot:spring-boot-starter-actuator") + implementation("org.springframework.boot:spring-boot-starter-web") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin") + implementation("org.jetbrains.kotlin:kotlin-reflect") + + + testImplementation("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") + testRuntimeOnly("org.junit.platform:junit-platform-launcher") + + runtimeOnly("org.springframework.boot:spring-boot-devtools") + //testImplementation(libs.kotlin.test.junit) +} + +kotlin { + compilerOptions { + freeCompilerArgs.addAll("-Xjsr305=strict") + } +} + +tasks.withType { + useJUnitPlatform() +} \ No newline at end of file diff --git a/server/src/main/kotlin/com/sphereon/oid/fed/Application.kt b/server/src/main/kotlin/com/sphereon/oid/fed/Application.kt new file mode 100644 index 00000000..2d2fe659 --- /dev/null +++ b/server/src/main/kotlin/com/sphereon/oid/fed/Application.kt @@ -0,0 +1,11 @@ +package com.sphereon.oid.fed + +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.runApplication + +@SpringBootApplication +class Application + +fun main(args: Array) { + runApplication(*args) +} \ No newline at end of file diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties new file mode 100644 index 00000000..e83bf36f --- /dev/null +++ b/server/src/main/resources/application.properties @@ -0,0 +1,4 @@ +spring.application.name=OpenID Federation + +management.endpoints.web.base-path=/ +management.endpoints.web.path-mapping.health=status diff --git a/settings.gradle.kts b/settings.gradle.kts index fbf00ad3..17c9a425 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -29,3 +29,4 @@ dependencyResolutionManagement { } include(":modules:openid-federation-common") +include(":server") From 12bd9b675bad1b71343a033b78a7a26afe685621 Mon Sep 17 00:00:00 2001 From: Robert Mathew Date: Mon, 1 Jul 2024 14:49:49 +0530 Subject: [PATCH 2/5] chores: PR feedback --- .fleet/run.json | 20 ++++++--- admin-server/build.gradle.kts | 34 +++++++++++++++ .../com/sphereon/oid/fed/Application.kt | 0 .../src/main/resources/application.properties | 1 + gradle/libs.versions.toml | 11 +++-- server/build.gradle.kts | 42 ------------------- 6 files changed, 57 insertions(+), 51 deletions(-) create mode 100644 admin-server/build.gradle.kts rename {server => admin-server}/src/main/kotlin/com/sphereon/oid/fed/Application.kt (100%) rename {server => admin-server}/src/main/resources/application.properties (77%) delete mode 100644 server/build.gradle.kts diff --git a/.fleet/run.json b/.fleet/run.json index 2054655b..1f631a49 100644 --- a/.fleet/run.json +++ b/.fleet/run.json @@ -3,9 +3,13 @@ { "name": "OpenID-Federation [:server:build]", "type": "gradle", - "workingDir": "C:\\Users\\Robo\\Sphereon\\OpenID-Federation", - "tasks": [":server:build"], - "args": [""], + "workingDir": "$PROJECT_DIR$", + "tasks": [ + ":server:build" + ], + "args": [ + "" + ], "initScripts": { "flmapper": "ext.mapPath = { path -> null }" } @@ -13,9 +17,13 @@ { "name": "OpenID-Federation [build]", "type": "gradle", - "workingDir": "C:\\Users\\Robo\\Sphereon\\OpenID-Federation", - "tasks": ["build"], - "args": [""], + "workingDir": "$PROJECT_DIR$", + "tasks": [ + "build" + ], + "args": [ + "" + ], "initScripts": { "flmapper": "ext.mapPath = { path -> null }" } diff --git a/admin-server/build.gradle.kts b/admin-server/build.gradle.kts new file mode 100644 index 00000000..55d5a430 --- /dev/null +++ b/admin-server/build.gradle.kts @@ -0,0 +1,34 @@ +plugins { + alias(libs.plugins.springboot) + alias(libs.plugins.springDependencyManagement) + alias(libs.plugins.kotlinJvm) + alias(libs.plugins.kotlinPluginSpring) + application +} + +group = "com.sphereon.oid.fed" +version = "1.0.0" + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +dependencies { + implementation(libs.springboot.actuator) + implementation(libs.springboot.web) + implementation(libs.kotlin.reflect) + + runtimeOnly(libs.springboot.devtools) +} + +kotlin { + compilerOptions { + freeCompilerArgs.addAll("-Xjsr305=strict") + } +} + +tasks.withType { + useJUnitPlatform() +} \ No newline at end of file diff --git a/server/src/main/kotlin/com/sphereon/oid/fed/Application.kt b/admin-server/src/main/kotlin/com/sphereon/oid/fed/Application.kt similarity index 100% rename from server/src/main/kotlin/com/sphereon/oid/fed/Application.kt rename to admin-server/src/main/kotlin/com/sphereon/oid/fed/Application.kt diff --git a/server/src/main/resources/application.properties b/admin-server/src/main/resources/application.properties similarity index 77% rename from server/src/main/resources/application.properties rename to admin-server/src/main/resources/application.properties index e83bf36f..79c568ef 100644 --- a/server/src/main/resources/application.properties +++ b/admin-server/src/main/resources/application.properties @@ -1,4 +1,5 @@ spring.application.name=OpenID Federation +# Mapping /actuator/health to /status management.endpoints.web.base-path=/ management.endpoints.web.path-mapping.health=status diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3db9123b..76006ce9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,7 +15,7 @@ junit = "4.13.2" kotlin = "2.0.0" kotlinxSerializationJson = "1.7.0-RC" springboot = "3.3.1" -spingDependencyManagement = "1.1.5" +springDependencyManagement = "1.1.5" [libraries] kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } @@ -30,6 +30,11 @@ androidx-constraintlayout = { group = "androidx.constraintlayout", name = "const androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" } +kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect" } +springboot-actuator = { group = "org.springframework.boot", name = "spring-boot-starter-actuator" } +springboot-web = { group = "org.springframework.boot", name = "spring-boot-starter-web" } +springboot-devtools = { group = "org.springframework.boot", name = "spring-boot-devtools" } + [plugins] androidApplication = { id = "com.android.application", version.ref = "agp" } androidLibrary = { id = "com.android.library", version.ref = "agp" } @@ -37,6 +42,6 @@ jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } -springboot = { id = "org.springframework.boot", version.ref = "springboot"} -springDependencyManagement = { id = "io.spring.dependency-management", version.ref = "spingDependencyManagement"} +springboot = { id = "org.springframework.boot", version.ref = "springboot" } +springDependencyManagement = { id = "io.spring.dependency-management", version.ref = "springDependencyManagement" } kotlinPluginSpring = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotlin" } \ No newline at end of file diff --git a/server/build.gradle.kts b/server/build.gradle.kts deleted file mode 100644 index 62c99881..00000000 --- a/server/build.gradle.kts +++ /dev/null @@ -1,42 +0,0 @@ -plugins { - alias(libs.plugins.springboot) - alias(libs.plugins.springDependencyManagement) - alias(libs.plugins.kotlinJvm) - alias(libs.plugins.kotlinPluginSpring) - application -} - -group = "com.sphereon.oid.fed" -version = "1.0.0" - -java { - toolchain { - languageVersion = JavaLanguageVersion.of(21) - } -} - -dependencies { - - implementation("org.springframework.boot:spring-boot-starter-actuator") - implementation("org.springframework.boot:spring-boot-starter-web") - implementation("com.fasterxml.jackson.module:jackson-module-kotlin") - implementation("org.jetbrains.kotlin:kotlin-reflect") - - - testImplementation("org.springframework.boot:spring-boot-starter-test") - testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") - - runtimeOnly("org.springframework.boot:spring-boot-devtools") - //testImplementation(libs.kotlin.test.junit) -} - -kotlin { - compilerOptions { - freeCompilerArgs.addAll("-Xjsr305=strict") - } -} - -tasks.withType { - useJUnitPlatform() -} \ No newline at end of file From aafe220385b97dbab56953f10f636edbf76cbd8d Mon Sep 17 00:00:00 2001 From: Robert Mathew Date: Mon, 1 Jul 2024 14:56:55 +0530 Subject: [PATCH 3/5] Updated the server name in gradle module --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 17c9a425..a7cd08e0 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -29,4 +29,4 @@ dependencyResolutionManagement { } include(":modules:openid-federation-common") -include(":server") +include(":admin-server") From a5c26a61bc2d7eb4d5063e0bd3f263cc9310324b Mon Sep 17 00:00:00 2001 From: Robert Mathew Date: Mon, 1 Jul 2024 19:15:03 +0530 Subject: [PATCH 4/5] Added test for status endpoint and added README --- .fleet/run.json | 2 +- admin-server/README.md | 19 ++++++++++++++ admin-server/build.gradle.kts | 8 ++++-- .../com/sphereon/oid/fed/ApplicationTests.kt | 13 ++++++++++ .../sphereon/oid/fed/StatusEndpointTest.kt | 25 +++++++++++++++++++ gradle/libs.versions.toml | 1 + 6 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 admin-server/README.md create mode 100644 admin-server/src/test/kotlin/com/sphereon/oid/fed/ApplicationTests.kt create mode 100644 admin-server/src/test/kotlin/com/sphereon/oid/fed/StatusEndpointTest.kt diff --git a/.fleet/run.json b/.fleet/run.json index 1f631a49..b3f28c35 100644 --- a/.fleet/run.json +++ b/.fleet/run.json @@ -5,7 +5,7 @@ "type": "gradle", "workingDir": "$PROJECT_DIR$", "tasks": [ - ":server:build" + ":admin-server:build" ], "args": [ "" diff --git a/admin-server/README.md b/admin-server/README.md new file mode 100644 index 00000000..eab39d24 --- /dev/null +++ b/admin-server/README.md @@ -0,0 +1,19 @@ +# Admin server + +API +
+```/status``` - To check health status + +
+ +To build +
+```./gradlew admin-server:build``` + +To run +
+```./gradlew admin-server:bootRun``` + +To run tests +
+```./gradlew admin-server:test``` \ No newline at end of file diff --git a/admin-server/build.gradle.kts b/admin-server/build.gradle.kts index 55d5a430..e791b804 100644 --- a/admin-server/build.gradle.kts +++ b/admin-server/build.gradle.kts @@ -19,7 +19,7 @@ dependencies { implementation(libs.springboot.actuator) implementation(libs.springboot.web) implementation(libs.kotlin.reflect) - + testImplementation(libs.springboot.test) runtimeOnly(libs.springboot.devtools) } @@ -30,5 +30,9 @@ kotlin { } tasks.withType { - useJUnitPlatform() + testLogging { + setExceptionFormat("full") + events("started", "skipped", "passed", "failed") + showStandardStreams = true + } } \ No newline at end of file diff --git a/admin-server/src/test/kotlin/com/sphereon/oid/fed/ApplicationTests.kt b/admin-server/src/test/kotlin/com/sphereon/oid/fed/ApplicationTests.kt new file mode 100644 index 00000000..e9539f43 --- /dev/null +++ b/admin-server/src/test/kotlin/com/sphereon/oid/fed/ApplicationTests.kt @@ -0,0 +1,13 @@ +package com.sphereon.oid.fed + +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest + +@SpringBootTest +class ApplicationTests { + + @Test + fun contextLoads() { + } + +} diff --git a/admin-server/src/test/kotlin/com/sphereon/oid/fed/StatusEndpointTest.kt b/admin-server/src/test/kotlin/com/sphereon/oid/fed/StatusEndpointTest.kt new file mode 100644 index 00000000..9e3af1ad --- /dev/null +++ b/admin-server/src/test/kotlin/com/sphereon/oid/fed/StatusEndpointTest.kt @@ -0,0 +1,25 @@ +package com.sphereon.oid.fed + +import org.junit.jupiter.api.Test +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.test.web.servlet.MockMvc +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.* + + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@AutoConfigureMockMvc +class StatusEndpointTest { + + @Autowired + private lateinit var mockMvc: MockMvc + + @Test + fun testStatusEndpoint() { + mockMvc.perform(get("/status")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.status").value("UP")) + } +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 76006ce9..8f2751ea 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -34,6 +34,7 @@ kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect" } springboot-actuator = { group = "org.springframework.boot", name = "spring-boot-starter-actuator" } springboot-web = { group = "org.springframework.boot", name = "spring-boot-starter-web" } springboot-devtools = { group = "org.springframework.boot", name = "spring-boot-devtools" } +springboot-test = { group = "org.springframework.boot", name = "spring-boot-starter-test" } [plugins] androidApplication = { id = "com.android.application", version.ref = "agp" } From eceb917a9a08610a6c5a21744129fa583123146a Mon Sep 17 00:00:00 2001 From: Robert Mathew Date: Tue, 2 Jul 2024 12:41:21 +0530 Subject: [PATCH 5/5] Enabled test run on gradle build --- admin-server/build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/admin-server/build.gradle.kts b/admin-server/build.gradle.kts index e791b804..e856481f 100644 --- a/admin-server/build.gradle.kts +++ b/admin-server/build.gradle.kts @@ -30,6 +30,7 @@ kotlin { } tasks.withType { + useJUnitPlatform() testLogging { setExceptionFormat("full") events("started", "skipped", "passed", "failed")