From 4e757ec1c3f6ad38ebce9d84cb9174df296cd1a0 Mon Sep 17 00:00:00 2001 From: Robert Mathew Date: Tue, 2 Jul 2024 16:21:20 +0530 Subject: [PATCH] Enabled test run on gradle build * Enabled test run on gradle build --- .fleet/run.json | 2 +- admin-server/README.md | 19 ++++++++++++++ admin-server/build.gradle.kts | 7 +++++- .../com/sphereon/oid/fed/ApplicationTests.kt | 13 ++++++++++ .../sphereon/oid/fed/StatusEndpointTest.kt | 25 +++++++++++++++++++ gradle/libs.versions.toml | 1 + 6 files changed, 65 insertions(+), 2 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..e856481f 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) } @@ -31,4 +31,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" }