-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verify sending Content-Type and custom object body via POST (#1897)
* Verify sending Content-Type and custom object body via POST Close #997, #1127 * Verify string can be sent with json feature Close #1265 * Fix exception message for #997 * Remove obsolete check
- Loading branch information
Showing
10 changed files
with
95 additions
and
68 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
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
10 changes: 0 additions & 10 deletions
10
ktor-client/ktor-client-tests/common/src/io/ktor/client/tests/utils/PlatformDetection.kt
This file was deleted.
Oops, something went wrong.
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
67 changes: 67 additions & 0 deletions
67
ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/features/SerializationTest.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,67 @@ | ||
/* | ||
* Copyright 2014-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.client.tests.features | ||
|
||
import io.ktor.client.features.* | ||
import io.ktor.client.features.json.* | ||
import io.ktor.client.request.* | ||
import io.ktor.client.tests.utils.* | ||
import io.ktor.http.* | ||
import kotlinx.serialization.Serializable | ||
import kotlin.test.* | ||
|
||
@Serializable | ||
class MyCustomObject(val message: String) | ||
|
||
class SerializationTest : ClientLoader() { | ||
@Test | ||
fun testSendCustomObject() = clientTests { | ||
config { | ||
install(JsonFeature) | ||
} | ||
|
||
test { client -> | ||
assertFailsWith<ClientRequestException> { | ||
client.post { | ||
url("https://google.com") | ||
header(HttpHeaders.ContentType, ContentType.Application.Json) | ||
body = MyCustomObject(message = "Hello World") | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun testSendStringWithSerialization() = clientTests { | ||
config { | ||
install(JsonFeature) | ||
} | ||
|
||
test { client -> | ||
assertFailsWith<ClientRequestException> { | ||
client.post { | ||
url("https://google.com") | ||
header(HttpHeaders.ContentType, ContentType.Application.Json) | ||
body = "Hello, world" | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun testSendObjectWithoutContentType() = clientTests { | ||
config { | ||
install(JsonFeature) | ||
} | ||
|
||
test { client -> | ||
assertFailsWith<IllegalStateException> { | ||
client.post("$TEST_SERVER/json/object") { | ||
body = MyCustomObject("Foo") | ||
} | ||
} | ||
} | ||
} | ||
} |
12 changes: 0 additions & 12 deletions
12
ktor-client/ktor-client-tests/js/src/io/ktor/client/tests/utils/PlatformDetection.kt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
ktor-client/ktor-client-tests/jvm/src/io/ktor/client/tests/utils/PlatformDetection.kt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
ktor-client/ktor-client-tests/posix/src/io/ktor/client/tests/utils/PlatformDetection.kt
This file was deleted.
Oops, something went wrong.