-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add companion classes to Kotlin reflective hierarchy registration
- Loading branch information
Showing
5 changed files
with
112 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...tlin/standard/src/main/kotlin/io/quarkus/it/resteasy/reactive/kotlin/CompanionResource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.quarkus.it.resteasy.reactive.kotlin | ||
|
||
import jakarta.ws.rs.GET | ||
import jakarta.ws.rs.Path | ||
import jakarta.ws.rs.Produces | ||
import jakarta.ws.rs.core.MediaType | ||
|
||
@Path("/companion") | ||
class CompanionResource { | ||
@Path("success") | ||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
fun success() = ResponseData.success() | ||
|
||
@Path("failure") | ||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
fun failure() = ResponseData.failure("error") | ||
} |
17 changes: 17 additions & 0 deletions
17
...ve-kotlin/standard/src/main/kotlin/io/quarkus/it/resteasy/reactive/kotlin/ResponseData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.quarkus.it.resteasy.reactive.kotlin | ||
|
||
class ResponseData<T>( | ||
val code: Int = STATUS_CODE.SUCCESS.code, | ||
val msg: String = "", | ||
val data: T? = null, | ||
) { | ||
companion object { | ||
fun success() = ResponseData<Unit>() | ||
fun failure(msg: String) = ResponseData<Unit>(code = STATUS_CODE.ERROR.code, msg = msg) | ||
} | ||
} | ||
|
||
enum class STATUS_CODE(val code: Int) { | ||
SUCCESS(200), | ||
ERROR(500) | ||
} |
5 changes: 5 additions & 0 deletions
5
...ive-kotlin/standard/src/test/kotlin/io/quarkus/it/resteasy/reactive/kotlin/CompanionIT.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.quarkus.it.resteasy.reactive.kotlin | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest | ||
|
||
@QuarkusIntegrationTest class CompanionIT : CompanionTest() {} |
29 changes: 29 additions & 0 deletions
29
...e-kotlin/standard/src/test/kotlin/io/quarkus/it/resteasy/reactive/kotlin/CompanionTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.quarkus.it.resteasy.reactive.kotlin | ||
|
||
import io.quarkus.test.junit.QuarkusTest | ||
import io.restassured.module.kotlin.extensions.Then | ||
import io.restassured.module.kotlin.extensions.When | ||
import org.hamcrest.Matchers.* | ||
import org.junit.jupiter.api.Test | ||
|
||
@QuarkusTest | ||
class CompanionTest { | ||
|
||
@Test | ||
fun testSuccessResponseData() { | ||
When { get("/companion/success") } Then | ||
{ | ||
statusCode(200) | ||
body(containsString("200")) | ||
} | ||
} | ||
|
||
@Test | ||
fun testFailureResponseData() { | ||
When { get("/companion/failure") } Then | ||
{ | ||
statusCode(200) | ||
body(containsString("500"), containsString("error")) | ||
} | ||
} | ||
} |