-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[kotlin] add testFolder configuration for kotlin #2975
Merged
wing328
merged 12 commits into
OpenAPITools:master
from
fj-roman:feature/kotlin_testfolder
May 26, 2019
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3ae910c
add apiSuffix configuration
5c01b15
refactor the global option apiSuffix to kotlin specific feature
fj-roman c819b86
add testcase
fj-roman b008328
add testFolder for kotlin gen
fj-roman f6b75a1
add basic api_test.mustache template
fj-roman d4fb35f
add api_test,mustache
fj-roman e588ba5
add tests
fj-roman 159c331
improve usage of file separators
fj-roman 03586ba
replace defined file separator into os specific separators
fj-roman 15ab47b
improve test templates and kotlin-springboot sample
fj-roman c47ca83
add test dependecies into gradle template
fj-roman 2c17b14
add newline into template file
fj-roman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
33 changes: 33 additions & 0 deletions
33
modules/openapi-generator/src/main/resources/kotlin-spring/api_test.mustache
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,33 @@ | ||
package {{package}} | ||
|
||
{{#imports}}import {{import}} | ||
{{/imports}} | ||
import org.junit.jupiter.api.Test | ||
|
||
import org.springframework.http.ResponseEntity | ||
|
||
class {{classname}}Test { | ||
|
||
{{#serviceInterface}}private val service: {{classname}}Service = {{classname}}ServiceImpl(){{/serviceInterface}} | ||
private val api: {{classname}}Controller = {{classname}}Controller({{#serviceInterface}}service{{/serviceInterface}}) | ||
|
||
{{#operations}}{{#operation}} | ||
/** | ||
* {{summary}} | ||
* | ||
* {{notes}} | ||
* | ||
* @throws ApiException | ||
* if the Api call fails | ||
*/ | ||
@Test | ||
fun {{operationId}}Test() { | ||
{{#allParams}} | ||
val {{paramName}}:{{{dataType}}}? = null | ||
{{/allParams}} | ||
val response: ResponseEntity<{{>returnTypes}}> = api.{{operationId}}({{#allParams}}{{paramName}}!!{{#hasMore}}, {{/hasMore}}{{/allParams}}) | ||
|
||
// TODO: test validations | ||
} | ||
{{/operation}}{{/operations}} | ||
} | ||
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
148 changes: 148 additions & 0 deletions
148
samples/server/petstore/kotlin-springboot/src/test/kotlin/org/openapitools/api/PetApiTest.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,148 @@ | ||
package org.openapitools.api | ||
|
||
import org.openapitools.model.ModelApiResponse | ||
import org.openapitools.model.Pet | ||
import org.junit.jupiter.api.Test | ||
|
||
import org.springframework.http.ResponseEntity | ||
|
||
class PetApiTest { | ||
|
||
private val service: PetApiService = PetApiServiceImpl() | ||
private val api: PetApiController = PetApiController(service) | ||
|
||
|
||
/** | ||
* Add a new pet to the store | ||
* | ||
* | ||
* | ||
* @throws ApiException | ||
* if the Api call fails | ||
*/ | ||
@Test | ||
fun addPetTest() { | ||
val body:Pet? = null | ||
val response: ResponseEntity<Unit> = api.addPet(body!!) | ||
|
||
// TODO: test validations | ||
} | ||
|
||
/** | ||
* Deletes a pet | ||
* | ||
* | ||
* | ||
* @throws ApiException | ||
* if the Api call fails | ||
*/ | ||
@Test | ||
fun deletePetTest() { | ||
val petId:Long? = null | ||
val apiKey:String? = null | ||
val response: ResponseEntity<Unit> = api.deletePet(petId!!, apiKey!!) | ||
|
||
// TODO: test validations | ||
} | ||
|
||
/** | ||
* Finds Pets by status | ||
* | ||
* Multiple status values can be provided with comma separated strings | ||
* | ||
* @throws ApiException | ||
* if the Api call fails | ||
*/ | ||
@Test | ||
fun findPetsByStatusTest() { | ||
val status:List<String>? = null | ||
val response: ResponseEntity<List<Pet>> = api.findPetsByStatus(status!!) | ||
|
||
// TODO: test validations | ||
} | ||
|
||
/** | ||
* Finds Pets by tags | ||
* | ||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. | ||
* | ||
* @throws ApiException | ||
* if the Api call fails | ||
*/ | ||
@Test | ||
fun findPetsByTagsTest() { | ||
val tags:List<String>? = null | ||
val response: ResponseEntity<List<Pet>> = api.findPetsByTags(tags!!) | ||
|
||
// TODO: test validations | ||
} | ||
|
||
/** | ||
* Find pet by ID | ||
* | ||
* Returns a single pet | ||
* | ||
* @throws ApiException | ||
* if the Api call fails | ||
*/ | ||
@Test | ||
fun getPetByIdTest() { | ||
val petId:Long? = null | ||
val response: ResponseEntity<Pet> = api.getPetById(petId!!) | ||
|
||
// TODO: test validations | ||
} | ||
|
||
/** | ||
* Update an existing pet | ||
* | ||
* | ||
* | ||
* @throws ApiException | ||
* if the Api call fails | ||
*/ | ||
@Test | ||
fun updatePetTest() { | ||
val body:Pet? = null | ||
val response: ResponseEntity<Unit> = api.updatePet(body!!) | ||
|
||
// TODO: test validations | ||
} | ||
|
||
/** | ||
* Updates a pet in the store with form data | ||
* | ||
* | ||
* | ||
* @throws ApiException | ||
* if the Api call fails | ||
*/ | ||
@Test | ||
fun updatePetWithFormTest() { | ||
val petId:Long? = null | ||
val name:String? = null | ||
val status:String? = null | ||
val response: ResponseEntity<Unit> = api.updatePetWithForm(petId!!, name!!, status!!) | ||
|
||
// TODO: test validations | ||
} | ||
|
||
/** | ||
* uploads an image | ||
* | ||
* | ||
* | ||
* @throws ApiException | ||
* if the Api call fails | ||
*/ | ||
@Test | ||
fun uploadFileTest() { | ||
val petId:Long? = null | ||
val additionalMetadata:String? = null | ||
val file:org.springframework.core.io.Resource? = null | ||
val response: ResponseEntity<ModelApiResponse> = api.uploadFile(petId!!, additionalMetadata!!, file!!) | ||
|
||
// TODO: test validations | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
...es/server/petstore/kotlin-springboot/src/test/kotlin/org/openapitools/api/StoreApiTest.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,77 @@ | ||
package org.openapitools.api | ||
|
||
import org.openapitools.model.Order | ||
import org.junit.jupiter.api.Test | ||
|
||
import org.springframework.http.ResponseEntity | ||
|
||
class StoreApiTest { | ||
|
||
private val service: StoreApiService = StoreApiServiceImpl() | ||
private val api: StoreApiController = StoreApiController(service) | ||
|
||
|
||
/** | ||
* Delete purchase order by ID | ||
* | ||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors | ||
* | ||
* @throws ApiException | ||
* if the Api call fails | ||
*/ | ||
@Test | ||
fun deleteOrderTest() { | ||
val orderId:String? = null | ||
val response: ResponseEntity<Unit> = api.deleteOrder(orderId!!) | ||
|
||
// TODO: test validations | ||
} | ||
|
||
/** | ||
* Returns pet inventories by status | ||
* | ||
* Returns a map of status codes to quantities | ||
* | ||
* @throws ApiException | ||
* if the Api call fails | ||
*/ | ||
@Test | ||
fun getInventoryTest() { | ||
val response: ResponseEntity<Map<String, Int>> = api.getInventory() | ||
|
||
// TODO: test validations | ||
} | ||
|
||
/** | ||
* Find purchase order by ID | ||
* | ||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions | ||
* | ||
* @throws ApiException | ||
* if the Api call fails | ||
*/ | ||
@Test | ||
fun getOrderByIdTest() { | ||
val orderId:Long? = null | ||
val response: ResponseEntity<Order> = api.getOrderById(orderId!!) | ||
|
||
// TODO: test validations | ||
} | ||
|
||
/** | ||
* Place an order for a pet | ||
* | ||
* | ||
* | ||
* @throws ApiException | ||
* if the Api call fails | ||
*/ | ||
@Test | ||
fun placeOrderTest() { | ||
val body:Order? = null | ||
val response: ResponseEntity<Order> = api.placeOrder(body!!) | ||
|
||
// TODO: test validations | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please add an empty newline here ?