-
Notifications
You must be signed in to change notification settings - Fork 37
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
1 parent
f8cc75a
commit 16dbd5f
Showing
2 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
...es/junit-tests/src/test/java/com/yelp/codegen/generatecodesamples/PostFileEndpointTest.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,82 @@ | ||
package com.yelp.codegen.generatecodesamples | ||
|
||
import com.yelp.codegen.generatecodesamples.apis.FileApi | ||
import com.yelp.codegen.generatecodesamples.models.MultiPartInfo | ||
import com.yelp.codegen.generatecodesamples.tools.MockServerApiRule | ||
import com.yelp.codegen.generatecodesamples.tools.setFileApiStatsDispatcher | ||
import okhttp3.MediaType | ||
import okhttp3.RequestBody | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertNotNull | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class PostFileEndpointTest { | ||
|
||
@get:Rule | ||
val rule = MockServerApiRule() | ||
|
||
@Test | ||
fun sendFileTest() { | ||
rule.server.setFileApiStatsDispatcher() | ||
|
||
val returned = rule.getApi<FileApi>().postFile( | ||
clientFile = RequestBody.create(MediaType.parse("application/json"), "{}") | ||
).blockingGet() | ||
|
||
assertNotNull(returned.boundary) | ||
assertEquals(returned.errors?.size, 0) | ||
assertEquals( | ||
returned.parts, | ||
listOf( | ||
MultiPartInfo( | ||
contentDisposition = "form-data; name=\"client_file\"; filename=\"client_file\"", | ||
contentType = "application/json; charset=utf-8", | ||
contentLength = "2", | ||
content = "{}" | ||
) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun sendMultipleFilesTest() { | ||
rule.server.setFileApiStatsDispatcher() | ||
|
||
val returned = rule.getApi<FileApi>().postMultipleFiles( | ||
clientFile = RequestBody.create(MediaType.parse("application/json"), "{}"), | ||
certificateFile = RequestBody.create(MediaType.parse("text/plain"), "Some Text") | ||
).blockingGet() | ||
|
||
assertNotNull(returned.boundary) | ||
assertEquals(returned.errors?.size, 0) | ||
assertEquals( | ||
returned.parts, | ||
listOf( | ||
MultiPartInfo( | ||
contentDisposition = "form-data; name=\"client_file\"; filename=\"client_file\"", | ||
contentType = "application/json; charset=utf-8", | ||
contentLength = "2", | ||
content = "{}" | ||
), | ||
MultiPartInfo( | ||
contentDisposition = "form-data; name=\"certificate_file\"; filename=\"certificate_file\"", | ||
contentType = "text/plain; charset=utf-8", | ||
contentLength = "9", | ||
content = "Some Text" | ||
) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun ensureThatEndpointsWithFileAndNotMultipartFormDataAreMarkedAsDeprecated() { | ||
assertTrue( | ||
FileApi::class.java.methods | ||
.first { it.name == "postFileWithoutMultipartFormData" } | ||
.getAnnotationsByType(Deprecated::class.java) | ||
.isNotEmpty() | ||
) | ||
} | ||
} |
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