Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
PruthiviRaj27 committed Nov 22, 2022
1 parent 6d847ec commit cf842ac
Showing 1 changed file with 17 additions and 130 deletions.
147 changes: 17 additions & 130 deletions player/src/test/java/com/tpstream/player/NetworkTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ class NetworkTest {
}

@Test
fun isErrorReceiveOnGetAsyncRequest() {
val successResponse = MockResponse().setResponseCode(400)
mockWebServer.enqueue(successResponse)
fun isErrorReceiveOnGetSyncRequest(){
val errorResponse = MockResponse().setResponseCode(400)
mockWebServer.enqueue(errorResponse)
try {
val response = network.get(mockWebServer.url("/").toString())
network.get(mockWebServer.url("/").toString())
mockWebServer.takeRequest()
} catch (exception: TPException) {
} catch (exception: TPException){
assertEquals(exception.response?.code, 400)
}
}
Expand All @@ -88,135 +88,22 @@ class NetworkTest {
}
assertEquals(callbackResult.data, "foo")
}
//
// @Test
// fun testGetVideoInfoWithAsyncRequestOnFailure() {
// val successResponse = MockResponse().setResponseCode(401)
// mockWebServer.enqueue(successResponse)
// var tpException: TPException? = null
// runBlocking {
// withContext(Dispatchers.IO) {
// val response = networkVideoInfo.get(mockWebServer.url("/").toString(),
// object : Network.TPResponse<VideoInfo> {
// override fun onSuccess(result: VideoInfo) {
//
// }
//
// override fun onFailure(exception: TPException) {
// tpException = exception
// }
//
// })
// Thread.sleep(500)
// }
// mockWebServer.takeRequest()
// }
// assertEquals(tpException?.response?.code, 401)
// assertEquals(tpException?.isUnauthenticated(), true)
//
// }
//
// @Test
// fun testPostDRmLicenseWithSyncRequestOnSuccess() {
// val successResponse = MockResponse().setResponseCode(200).setBody(getDRMLicenseJSON())
// mockWebServer.enqueue(successResponse)
// val response = networkLicense.post(mockWebServer.url("/").toString(), EMPTY_REQUEST)
// mockWebServer.takeRequest()
// assertEquals(
// response?.licenseUrl,
// "https://drm.testpress.in/api/v2.5/chapter_contents/drm_license_key/?path=wv/eyJjb250ZW50QXV0aCI6ImV5SmpiMjUwWlc1MFNXUWlPaUkyT1dVeU1qTTRNV00xWXpRMFpqbGxZVGt6WldRNE1qaG1NekZtWWprM01TSXNJbVY0Y0dseVpYTWlPakUyTmpnd056VTVOemg5Iiwic2lnbmF0dXJlIjoiVm9oVWJRR1g2d1p0ZWxhSjoyMDIyMTExMFQwOTI2MTg5ODlaOmh5cV8yNmFRcm13a1lvN3ZJdVJad2M2U2dVSE9OOWFwTzVrTW5KOTR6aTg9In0=&v=1"
// )
//
// }
//
// @Test
// fun testPostDRmLicenseWithSyncRequestOnFailure() {
// val successResponse = MockResponse().setResponseCode(401)
// mockWebServer.enqueue(successResponse)
// try {
// val response = networkLicense.post(mockWebServer.url("/").toString(), EMPTY_REQUEST)
// mockWebServer.takeRequest()
// } catch (exception: TPException) {
// assertEquals(exception.isUnauthenticated(), true)
// assertEquals(exception.response?.code, 401)
// }
// }
//
// @Test
// fun testPostDRmLicenseWithAsyncRequestOnSuccess() {
// val successResponse = MockResponse().setResponseCode(200).setBody(getDRMLicenseJSON())
// mockWebServer.enqueue(successResponse)
// var response: DRMLicenseURL?
// runBlocking {
// withContext(Dispatchers.IO) {
// response = networkLicense.post(mockWebServer.url("/").toString(), EMPTY_REQUEST,
// object : Network.TPResponse<DRMLicenseURL> {
// override fun onSuccess(result: DRMLicenseURL) {
// response = result
// }
//
// override fun onFailure(exception: TPException) {
//
// }
//
// })
// Thread.sleep(500)
// }
// mockWebServer.takeRequest()
// }
// assertEquals(
// response?.licenseUrl,
// "https://drm.testpress.in/api/v2.5/chapter_contents/drm_license_key/?path=wv/eyJjb250ZW50QXV0aCI6ImV5SmpiMjUwWlc1MFNXUWlPaUkyT1dVeU1qTTRNV00xWXpRMFpqbGxZVGt6WldRNE1qaG1NekZtWWprM01TSXNJbVY0Y0dseVpYTWlPakUyTmpnd056VTVOemg5Iiwic2lnbmF0dXJlIjoiVm9oVWJRR1g2d1p0ZWxhSjoyMDIyMTExMFQwOTI2MTg5ODlaOmh5cV8yNmFRcm13a1lvN3ZJdVJad2M2U2dVSE9OOWFwTzVrTW5KOTR6aTg9In0=&v=1"
// )
// }
//
// @Test
// fun testPostDRmLicenseWithAsyncRequestOnFailure() {
// val successResponse = MockResponse().setResponseCode(401)
// mockWebServer.enqueue(successResponse)
// var tpException: TPException? = null
// runBlocking {
// withContext(Dispatchers.IO) {
// val response = networkLicense.post(mockWebServer.url("/").toString(), EMPTY_REQUEST,
// object : Network.TPResponse<DRMLicenseURL> {
// override fun onSuccess(result: DRMLicenseURL) {
// }
//
// override fun onFailure(exception: TPException) {
// tpException = exception
// }
//
// })
// Thread.sleep(500)
// }
// mockWebServer.takeRequest()
// }
// assertEquals(tpException?.isUnauthenticated(), true)
// assertEquals(tpException?.response?.code, 401)
// }
//
// private fun getVideoInfoJSON(): String {
// return """
// {
// "title": "Big bunny video",
// "thumbnail": null,
// "thumbnail_small": null,
// "thumbnail_medium": null,
// "url": "https://dyik8aq8drlno.cloudfront.net/institute/drm/courses/drm-encrypted-video/videos/transcoded/97912f63a2ad4e059bddbe2eb51fe3f6/",
// "dash_url": "https://dyik8aq8drlno.cloudfront.net/institute/drm/courses/drm-encrypted-video/videos/transcoded/97912f63a2ad4e059bddbe2eb51fe3f6/video.mpd",
// "hls_url": "https://dyik8aq8drlno.cloudfront.net/institute/drm/courses/drm-encrypted-video/videos/transcoded/97912f63a2ad4e059bddbe2eb51fe3f6/video.m3u8",
// "duration": "0:10:34",
// "description": "",
// "transcoding_status": 4
//}
// """.trimIndent()
//
// }

@Test
fun isErrorReceiveOnGetAsyncRequest() {
val errorResponse = MockResponse().setResponseCode(400)
mockWebServer.enqueue(errorResponse)
try {
network.get(mockWebServer.url("/").toString())
mockWebServer.takeRequest()
} catch (exception: TPException) {
assertEquals(exception.response?.code, 400)
}
}

private fun getDataJSON(): String {
return """
{"data":"foo"}
""".trimIndent()
}

}

0 comments on commit cf842ac

Please sign in to comment.