-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(type-safe-api): generate handler tests (#640)
* feat(type-safe-api): generate handler tests for java * feat(type-safe-api): generate handler tests for python * feat(type-safe-api): generate handler tests for typescript Additionally add lombok builder to generated Java input classes for easier construction in tests, and update default pattern for using the logger in Java handlers Fixes #570
- Loading branch information
Showing
39 changed files
with
1,036 additions
and
388 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
57 changes: 57 additions & 0 deletions
57
...safe-api/scripts/type-safe-api/generators/java-lambda-handlers/templates/tests.handlebars
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 @@ | ||
###TSAPI_SPLIT_FILE### | ||
{{#apiInfo ~}} | ||
{{#apis ~}} | ||
{{#operations ~}} | ||
{{#operation ~}} | ||
{{#if vendorExtensions.x-handler}} | ||
{{#startsWith vendorExtensions.x-handler.language 'java'}} | ||
###TSAPI_WRITE_FILE### | ||
{ | ||
"id": "{{operationIdCamelCase}}HandlerTest", | ||
"dir": ".", | ||
"name": "{{operationIdCamelCase}}HandlerTest", | ||
"ext": ".java", | ||
"generateConditionallyId": "{{operationIdCamelCase}}Handler" | ||
} | ||
###/TSAPI_WRITE_FILE###package {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-handlers-package}}{{/apis.0}}{{/apiInfo}}; | ||
|
||
import {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-package}}{{/apis.0}}{{/apiInfo}}.api.handlers.{{operationIdSnakeCase}}.{{operationIdCamelCase}}Input; | ||
import {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-package}}{{/apis.0}}{{/apiInfo}}.api.handlers.{{operationIdSnakeCase}}.{{operationIdCamelCase}}500Response; | ||
import {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-package}}{{/apis.0}}{{/apiInfo}}.api.handlers.{{operationIdSnakeCase}}.{{operationIdCamelCase}}RequestInput; | ||
import {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-package}}{{/apis.0}}{{/apiInfo}}.api.handlers.{{operationIdSnakeCase}}.{{operationIdCamelCase}}RequestParameters; | ||
import {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-package}}{{/apis.0}}{{/apiInfo}}.api.handlers.{{operationIdSnakeCase}}.{{operationIdCamelCase}}Response; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.HashMap; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* Tests for {{operationIdCamelCase}}Handler | ||
*/ | ||
public class {{operationIdCamelCase}}HandlerTest { | ||
@Test | ||
public void shouldReturnNotImplementedError() { | ||
// TODO: Update the test as appropriate when you implement your handler | ||
{{operationIdCamelCase}}Response response = new {{operationIdCamelCase}}Handler().handle({{operationIdCamelCase}}RequestInput.builder() | ||
.interceptorContext(new HashMap<>()) | ||
.input({{operationIdCamelCase}}Input.builder() | ||
.requestParameters({{operationIdCamelCase}}RequestParameters.builder() | ||
// Add request parameters here... | ||
.build()) | ||
// If the request has a body you can add it here... | ||
.build()) | ||
.build()); | ||
assertEquals(500, response.getStatusCode()); | ||
|
||
// Cast to the particular type of response returned to access the typed response body | ||
assertEquals("Not Implemented!", (({{operationIdCamelCase}}500Response) response).getTypedBody().getMessage()); | ||
} | ||
} | ||
|
||
{{~/startsWith}} | ||
{{~/if}} | ||
{{~/operation}} | ||
{{~/operations}} | ||
{{~/apis}} | ||
{{~/apiInfo}} |
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
Oops, something went wrong.