-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
395 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,23 @@ | ||
|
||
plugins { | ||
base | ||
id("jacoco-report-aggregation") | ||
id("org.jetbrains.kotlinx.kover") | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
jacocoAggregation(project(":sunday-core")) | ||
jacocoAggregation(project(":sunday-jdk")) | ||
jacocoAggregation(project(":sunday-okhttp")) | ||
} | ||
|
||
reporting { | ||
reports { | ||
create<JacocoCoverageReport>("testCoverageReport") { | ||
testType.set(TestSuiteType.UNIT_TEST) | ||
reportTask { | ||
reports.xml.required.set(true) | ||
} | ||
} | ||
} | ||
kover(project(":sunday-core")) | ||
kover(project(":sunday-jdk")) | ||
kover(project(":sunday-okhttp")) | ||
} | ||
|
||
tasks { | ||
|
||
check { | ||
finalizedBy(named<JacocoReport>("testCoverageReport")) | ||
finalizedBy(named("koverXmlReport"), named("koverHtmlReport")) | ||
} | ||
|
||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2020 Outfox, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import io.outfoxx.sunday.MediaType | ||
import io.outfoxx.sunday.http.HeaderParameters | ||
import io.outfoxx.sunday.http.getAll | ||
import io.outfoxx.sunday.http.getFirst | ||
import io.outfoxx.sunday.http.toMultiMap | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.containsInAnyOrder | ||
import org.hamcrest.Matchers.equalTo | ||
import org.hamcrest.Matchers.`is` | ||
import org.hamcrest.Matchers.oneOf | ||
import org.junit.jupiter.api.Test | ||
|
||
class HeaderExtensionsTest { | ||
|
||
@Test | ||
fun `test getFirst`() { | ||
val headers = HeaderParameters.encode(mapOf("test" to arrayOf(MediaType.JSON, MediaType.CBOR))) | ||
|
||
assertThat( | ||
headers.getFirst("test"), | ||
`is`(oneOf(MediaType.JSON.value, MediaType.CBOR.value)), | ||
) | ||
} | ||
|
||
@Test | ||
fun `test getAll`() { | ||
val headers = HeaderParameters.encode(mapOf("test" to arrayOf(MediaType.JSON, MediaType.CBOR))) | ||
|
||
assertThat( | ||
headers.getAll("test"), | ||
containsInAnyOrder(MediaType.JSON.value, MediaType.CBOR.value), | ||
) | ||
} | ||
|
||
@Test | ||
fun `test toMultiMap`() { | ||
val headers = HeaderParameters.encode(mapOf("test" to arrayOf(MediaType.JSON, MediaType.CBOR))) | ||
|
||
assertThat( | ||
headers.toMultiMap(), | ||
equalTo(mapOf("test" to listOf(MediaType.JSON.value, MediaType.CBOR.value))), | ||
) | ||
} | ||
|
||
} |
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
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,64 @@ | ||
/* | ||
* Copyright 2020 Outfox, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import io.outfoxx.sunday.http.Headers | ||
import io.outfoxx.sunday.http.Request | ||
import io.outfoxx.sunday.http.Response | ||
import io.outfoxx.sunday.utils.Problems | ||
import okio.BufferedSource | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.equalTo | ||
import org.junit.jupiter.api.Test | ||
import org.zalando.problem.Status | ||
|
||
class ProblemsTest { | ||
|
||
@Test | ||
fun `test forResponse`() { | ||
val problem = Problems.forResponse(TestResponse(400, "Bad Request", listOf(), null)) | ||
|
||
assertThat(problem.status, equalTo(Status.BAD_REQUEST)) | ||
} | ||
|
||
@Test | ||
fun `test forStatus`() { | ||
val problem = Problems.forStatus(400, "Bad Request") | ||
|
||
assertThat(problem.status, equalTo(Status.BAD_REQUEST)) | ||
} | ||
|
||
@Test | ||
fun `test forStatus supports non-standard values`() { | ||
val problem = Problems.forStatus(195, "AI Thinking") | ||
|
||
assertThat(problem.status?.statusCode, equalTo(195)) | ||
assertThat(problem.status?.reasonPhrase, equalTo("AI Thinking")) | ||
} | ||
|
||
data class TestResponse( | ||
override val statusCode: Int, | ||
override val reasonPhrase: String?, | ||
override val headers: Headers, | ||
override val body: BufferedSource?, | ||
) : Response { | ||
|
||
override val trailers: Headers? | ||
get() = null | ||
override val request: Request | ||
get() = TODO("Not yet implemented") | ||
} | ||
|
||
} |
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
Oops, something went wrong.