-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for produces in MicronautConverter (#34)
- Loading branch information
Showing
12 changed files
with
375 additions
and
2 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
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
210 changes: 210 additions & 0 deletions
210
.../test/kotlin/de/codecentric/hikaku/converters/micronaut/MicronautConverterProducesTest.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,210 @@ | ||
package de.codecentric.hikaku.converters.micronaut | ||
|
||
import de.codecentric.hikaku.endpoints.Endpoint | ||
import de.codecentric.hikaku.endpoints.HttpMethod.GET | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Nested | ||
import org.junit.jupiter.api.Test | ||
|
||
class MicronautConverterProducesTest { | ||
|
||
@Nested | ||
inner class DeclaredByControllerOnClass { | ||
|
||
@Test | ||
fun `single media type`() { | ||
//given | ||
val specification = setOf( | ||
Endpoint( | ||
path = "/todos", | ||
httpMethod = GET, | ||
produces = setOf( | ||
"text/plain" | ||
) | ||
) | ||
) | ||
|
||
//when | ||
val result = MicronautConverter("test.micronaut.produces.onclass.onlycontroller.singlemediatype").conversionResult | ||
|
||
//then | ||
assertThat(result).containsExactlyInAnyOrderElementsOf(specification) | ||
} | ||
|
||
@Test | ||
fun `multiple media types`() { | ||
//given | ||
val specification = setOf( | ||
Endpoint( | ||
path = "/todos", | ||
httpMethod = GET, | ||
produces = setOf( | ||
"text/plain", | ||
"application/xml" | ||
) | ||
) | ||
) | ||
|
||
//when | ||
val result = MicronautConverter("test.micronaut.produces.onclass.onlycontroller.multiplemediatypes").conversionResult | ||
|
||
//then | ||
assertThat(result).containsExactlyInAnyOrderElementsOf(specification) | ||
} | ||
} | ||
|
||
@Nested | ||
inner class ProducesOnClassOverridesController { | ||
|
||
@Test | ||
fun `single media type`() { | ||
//given | ||
val specification = setOf( | ||
Endpoint( | ||
path = "/todos", | ||
httpMethod = GET, | ||
produces = setOf( | ||
"application/xml" | ||
) | ||
) | ||
) | ||
|
||
//when | ||
val result = MicronautConverter("test.micronaut.produces.onclass.producesoverridescontroller.singlemediatype").conversionResult | ||
|
||
//then | ||
assertThat(result).containsExactlyInAnyOrderElementsOf(specification) | ||
} | ||
|
||
@Test | ||
fun `multiple media types`() { | ||
//given | ||
val specification = setOf( | ||
Endpoint( | ||
path = "/todos", | ||
httpMethod = GET, | ||
produces = setOf( | ||
"application/json", | ||
"application/pdf" | ||
) | ||
) | ||
) | ||
|
||
//when | ||
val result = MicronautConverter("test.micronaut.produces.onclass.producesoverridescontroller.multiplemediatypes").conversionResult | ||
|
||
//then | ||
assertThat(result).containsExactlyInAnyOrderElementsOf(specification) | ||
} | ||
} | ||
|
||
@Nested | ||
inner class DeclaredByProducesOnFunction { | ||
|
||
@Test | ||
fun `single media type`() { | ||
//given | ||
val specification = setOf( | ||
Endpoint( | ||
path = "/todos", | ||
httpMethod = GET, | ||
produces = setOf( | ||
"text/plain" | ||
) | ||
) | ||
) | ||
|
||
//when | ||
val result = MicronautConverter("test.micronaut.produces.onfunction.onlyproduces.singlemediatype").conversionResult | ||
|
||
//then | ||
assertThat(result).containsExactlyInAnyOrderElementsOf(specification) | ||
} | ||
|
||
@Test | ||
fun `multiple media types`() { | ||
//given | ||
val specification = setOf( | ||
Endpoint( | ||
path = "/todos", | ||
httpMethod = GET, | ||
produces = setOf( | ||
"text/plain", | ||
"application/xml" | ||
) | ||
) | ||
) | ||
|
||
//when | ||
val result = MicronautConverter("test.micronaut.produces.onfunction.onlyproduces.multiplemediatypes").conversionResult | ||
|
||
//then | ||
assertThat(result).containsExactlyInAnyOrderElementsOf(specification) | ||
} | ||
} | ||
|
||
@Nested | ||
inner class ProducesOnFunctionOverridesController { | ||
|
||
@Test | ||
fun `single media type`() { | ||
//given | ||
val specification = setOf( | ||
Endpoint( | ||
path = "/todos", | ||
httpMethod = GET, | ||
produces = setOf( | ||
"application/xml" | ||
) | ||
) | ||
) | ||
|
||
//when | ||
val result = MicronautConverter("test.micronaut.produces.onfunction.producesoverridescontroller.singlemediatype").conversionResult | ||
|
||
//then | ||
assertThat(result).containsExactlyInAnyOrderElementsOf(specification) | ||
} | ||
|
||
@Test | ||
fun `multiple media types`() { | ||
//given | ||
val specification = setOf( | ||
Endpoint( | ||
path = "/todos", | ||
httpMethod = GET, | ||
produces = setOf( | ||
"application/json", | ||
"application/pdf" | ||
) | ||
) | ||
) | ||
|
||
//when | ||
val result = MicronautConverter("test.micronaut.produces.onfunction.producesoverridescontroller.multiplemediatypes").conversionResult | ||
|
||
//then | ||
assertThat(result).containsExactlyInAnyOrderElementsOf(specification) | ||
} | ||
} | ||
|
||
@Test | ||
fun `use default media if no produces info has been set`() { | ||
//given | ||
val specification = setOf( | ||
Endpoint( | ||
path = "/todos", | ||
httpMethod = GET, | ||
produces = setOf( | ||
"application/json" | ||
) | ||
) | ||
) | ||
|
||
//when | ||
val result = MicronautConverter("test.micronaut.produces.default").conversionResult | ||
|
||
//then | ||
assertThat(result).containsExactlyInAnyOrderElementsOf(specification) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
micronaut/src/test/kotlin/test/micronaut/produces/default/DefaultTestController.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,12 @@ | ||
package test.micronaut.produces.default | ||
|
||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
import test.micronaut.Todo | ||
|
||
@Controller("/todos") | ||
class ProducesDefaultMediaTypeTestController { | ||
|
||
@Get | ||
fun todos() = Todo() | ||
} |
12 changes: 12 additions & 0 deletions
12
...ces/onclass/onlycontroller/multiplemediatypes/ProducesMultipleMediaTypesTestController.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,12 @@ | ||
package test.micronaut.produces.onclass.onlycontroller.multiplemediatypes | ||
|
||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
import test.micronaut.Todo | ||
|
||
@Controller("/todos", produces = ["text/plain", "application/xml"]) | ||
class ProducesMultipleMediaTypesTestController { | ||
|
||
@Get | ||
fun todos() = Todo() | ||
} |
13 changes: 13 additions & 0 deletions
13
.../produces/onclass/onlycontroller/singlemediatype/ProducesSingleMediaTypeTestController.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,13 @@ | ||
package test.micronaut.produces.onclass.onlycontroller.singlemediatype | ||
|
||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
import test.micronaut.Todo | ||
|
||
|
||
@Controller("/todos", produces = ["text/plain"]) | ||
class ProducesSingleMediaTypeTestController { | ||
|
||
@Get | ||
fun todos() = Todo() | ||
} |
14 changes: 14 additions & 0 deletions
14
...roducesoverridescontroller/multiplemediatypes/ProducesMultipleMediaTypesTestController.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,14 @@ | ||
package test.micronaut.produces.onclass.producesoverridescontroller.multiplemediatypes | ||
|
||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
import io.micronaut.http.annotation.Produces | ||
import test.micronaut.Todo | ||
|
||
@Controller("/todos", produces = ["text/plain", "application/xml"]) | ||
@Produces("application/json", "application/pdf") | ||
class ProducesMultipleMediaTypesTestController { | ||
|
||
@Get | ||
fun todos() = Todo() | ||
} |
15 changes: 15 additions & 0 deletions
15
...lass/producesoverridescontroller/singlemediatype/ProducesSingleMediaTypeTestController.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,15 @@ | ||
package test.micronaut.produces.onclass.producesoverridescontroller.singlemediatype | ||
|
||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
import io.micronaut.http.annotation.Produces | ||
import test.micronaut.Todo | ||
|
||
|
||
@Produces("application/xml") | ||
@Controller("/todos", produces = ["text/plain"]) | ||
class ProducesSingleMediaTypeTestController { | ||
|
||
@Get | ||
fun todos() = Todo() | ||
} |
15 changes: 15 additions & 0 deletions
15
...es/onfunction/onlyproduces/multiplemediatypes/ProducesMultipleMediaTypesTestController.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,15 @@ | ||
package test.micronaut.produces.onfunction.onlyproduces.multiplemediatypes | ||
|
||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
import io.micronaut.http.annotation.Post | ||
import io.micronaut.http.annotation.Produces | ||
import test.micronaut.Todo | ||
|
||
@Controller("/todos") | ||
class ProducesMultipleMediaTypesTestController { | ||
|
||
@Get | ||
@Produces("text/plain", "application/xml") | ||
fun todos() = Todo() | ||
} |
14 changes: 14 additions & 0 deletions
14
...produces/onfunction/onlyproduces/singlemediatype/ProducesSingleMediaTypeTestController.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,14 @@ | ||
package test.micronaut.produces.onfunction.onlyproduces.singlemediatype | ||
|
||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
import io.micronaut.http.annotation.Produces | ||
import test.micronaut.Todo | ||
|
||
@Controller("/todos") | ||
class ProducesSingleMediaTypeTestController { | ||
|
||
@Get | ||
@Produces("text/plain") | ||
fun todos() = Todo() | ||
} |
14 changes: 14 additions & 0 deletions
14
...roducesoverridescontroller/multiplemediatypes/ProducesMultipleMediaTypesTestController.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,14 @@ | ||
package test.micronaut.produces.onfunction.producesoverridescontroller.multiplemediatypes | ||
|
||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
import io.micronaut.http.annotation.Produces | ||
import test.micronaut.Todo | ||
|
||
@Controller("/todos", produces = ["text/plain", "application/xml"]) | ||
class ProducesMultipleMediaTypesTestController { | ||
|
||
@Get | ||
@Produces("application/json", "application/pdf") | ||
fun todos() = Todo() | ||
} |
Oops, something went wrong.