-
Notifications
You must be signed in to change notification settings - Fork 4
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
atavism
committed
Aug 29, 2023
1 parent
45cf2be
commit fd95536
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
android/app/src/test/kotlin/org/getlantern/lantern/util/LanternHttpClientTest.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,57 @@ | ||
package org.getlantern.lantern.util | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import io.mockk.MockKAnnotations | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import io.mockk.mockk | ||
import io.mockk.slot | ||
import io.mockk.verify | ||
import okhttp3.HttpUrl.Companion.toHttpUrl | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.Protocol | ||
import okhttp3.Request | ||
import okhttp3.RequestBody.Companion.toRequestBody | ||
import okhttp3.Response | ||
import okhttp3.ResponseBody.Companion.toResponseBody | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class LanternHttpClientTest { | ||
@Test | ||
fun `from raw http - normal`() { | ||
val statusOK = "HTTP/1.1 200 OK\r\n" + | ||
"Content-Type: application/json;charset=utf-8\r\n" + | ||
"X-Lantern-Device-Id: abc\r\n" + | ||
"X-Lantern-User-Id: 12345\r\n" + | ||
"\r\n" + | ||
"Some Content" | ||
|
||
statusOK.toVauInnerHttpResponse(mockk()).let { | ||
assertEquals(Protocol.HTTP_1_1, it.protocol) | ||
assertEquals(200, it.code) | ||
assertEquals("abc", it.headers["X-Lantern-Device-Id"]) | ||
assertEquals("12345", it.headers["X-Lantern-User-Id"]) | ||
assertEquals("application/json;charset=utf-8", it.body!!.contentType().toString()) | ||
assertEquals("Some Content", it.body!!.string()) | ||
} | ||
|
||
val notFound = "HTTP/1.1 400 NOT FOUND\r\n" + | ||
"Content-Type: application/json;charset=utf-8\r\n" + | ||
"X-Header: abc\r\n" + | ||
"Y-Header: 12345\r\n" + | ||
"\r\n" + | ||
"Some Content" | ||
|
||
notFound.toVauInnerHttpResponse(mockk()).let { | ||
assertEquals(Protocol.HTTP_1_1, it.protocol) | ||
assertEquals(400, it.code) | ||
assertEquals("abc", it.headers["X-Lantern-Device-Id"]) | ||
assertEquals("12345", it.headers["X-Lantern-User-Id"]) | ||
assertEquals("application/json;charset=utf-8", it.body!!.contentType().toString()) | ||
assertEquals("Some Content", it.body!!.string()) | ||
} | ||
} | ||
} |