apex.api_test.mustache Maven / Gradle / Ivy
@isTest
private class {{classname}}Test {
{{#operations}}
{{#operation}}
/**
* {{summary}}
*
* {{notes}}
*/
@isTest
private static void {{operationId}}Test() {
HttpResponse res = new HttpResponse();
{{#restfulCreate}}
res.setStatusCode(201);
res.setStatus('Created');
{{/restfulCreate}}
{{^restfulCreate}}
res.setStatusCode(200);
res.setStatus('OK');
{{/restfulCreate}}
Test.setMock(HttpCalloutMock.class, new SwaggerResponseMock(res));
{{#hasParams}}
Map params = new Map{
{{#allParams}}
'{{paramName}}' => {{{example}}}{{#hasMore}},{{/hasMore}}
{{/allParams}}
};
{{/hasParams}}
{{classPrefix}}Client client;
{{classname}} api;
{{#returnType}}
{{{returnType}}} response;
{{{returnType}}} expectedResponse;
{{/returnType}}
{{#authMethods}}
client = new {{classPrefix}}Client();
api = new {{classname}}(client);{{#isApiKey}}
((Swagger.ApiKeyAuth){{/isApiKey}} client.getAuthentication('{{name}}');
{{#isApiKey}}
client.setApiKey('foo-bar-api-key');
{{/isApiKey}}
{{#examples}}
res.setHeader('Content-Type', '{{contentType}}');
res.setBody('{{{example}}}');
expectedResponse = {{{deserializedExample}}};
response = ({{{returnType}}}) api.{{operationId}}({{#hasParams}}params{{/hasParams}});
System.assertEquals(expectedResponse, response);
{{/examples}}
{{^examples}}
api.{{operationId}}({{#hasParams}}params{{/hasParams}});
{{/examples}}
{{/authMethods}}
{{^authMethods}}
api = new {{classname}}(new {{classPrefix}}Client());
{{#examples}}
res.setHeader('Content-Type', '{{contentType}}');
res.setBody('{{{example}}}');
expectedResponse = {{{deserializedExample}}};
response = ({{{returnType}}}) api.{{operationId}}({{#hasParams}}params{{/hasParams}});
System.assertEquals(expectedResponse, response);
{{/examples}}
{{^examples}}
api.{{operationId}}({{#hasParams}}params{{/hasParams}});
{{/examples}}
{{/authMethods}}
}
{{#hasMore}}
{{/hasMore}}
{{/operation}}
{{/operations}}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy