-
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 query parameter to MicronautConverter (#34)
- Loading branch information
Showing
5 changed files
with
87 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
50 changes: 50 additions & 0 deletions
50
...kotlin/de/codecentric/hikaku/converters/micronaut/MicronautConverterQueryParameterTest.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,50 @@ | ||
package de.codecentric.hikaku.converters.micronaut | ||
|
||
import de.codecentric.hikaku.endpoints.Endpoint | ||
import de.codecentric.hikaku.endpoints.HttpMethod.GET | ||
import de.codecentric.hikaku.endpoints.QueryParameter | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
|
||
class MicronautConverterQueryParameterTest { | ||
|
||
@Test | ||
fun `query parameter required`() { | ||
//given | ||
val specification = setOf( | ||
Endpoint( | ||
path = "/todos", | ||
httpMethod = GET, | ||
queryParameters = setOf( | ||
QueryParameter("filter", true) | ||
) | ||
) | ||
) | ||
|
||
//when | ||
val result = MicronautConverter("test.micronaut.queryparameter.required").conversionResult | ||
|
||
//then | ||
assertThat(result).containsExactlyInAnyOrderElementsOf(specification) | ||
} | ||
|
||
@Test | ||
fun `query parameter optional, because a default value exists`() { | ||
//given | ||
val specification = setOf( | ||
Endpoint( | ||
path = "/todos", | ||
httpMethod = GET, | ||
queryParameters = setOf( | ||
QueryParameter("filter", false) | ||
) | ||
) | ||
) | ||
|
||
//when | ||
val result = MicronautConverter("test.micronaut.queryparameter.optional").conversionResult | ||
|
||
//then | ||
assertThat(result).containsExactlyInAnyOrderElementsOf(specification) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ut/src/test/kotlin/test/micronaut/queryparameter/optional/QueryParameterTestController.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.queryparameter.optional | ||
|
||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
import io.micronaut.http.annotation.QueryValue | ||
|
||
@Controller("/todos") | ||
class QueryParameterTestController { | ||
|
||
@Get | ||
fun todos(@QueryValue("filter", defaultValue = "all") filter: String) { } | ||
} |
12 changes: 12 additions & 0 deletions
12
...ut/src/test/kotlin/test/micronaut/queryparameter/required/QueryParameterTestController.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.queryparameter.required | ||
|
||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
import io.micronaut.http.annotation.QueryValue | ||
|
||
@Controller("/todos") | ||
class QueryParameterTestController { | ||
|
||
@Get | ||
fun todos(@QueryValue("filter") filter: String) { } | ||
} |