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 OASResponseMock(res));
{{#hasParams}}
Map params = new Map{
{{#allParams}}
'{{paramName}}' => {{{example}}}{{#hasMore}},{{/hasMore}}
{{/allParams}}
};
{{/hasParams}}
{{classPrefix}}Client client;
{{classname}} api;
{{#returnType}}
{{{returnType}}} response;
{{{returnType}}} expectedResponse;
{{/returnType}}
String js = '';
{{#authMethods}}
client = new {{classPrefix}}Client();
api = new {{classname}}(client);{{#isApiKey}}
((OAS.ApiKeyAuth)client.getAuthentication('{{name}}')).setApiKey('foo-bar-api-key');
{{/isApiKey}}
{{#examples}}
js = JSON.serialize({{{deserializedExample}}});
res.setHeader('Content-Type', '{{contentType}}');
res.setBody(js);
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}}
js = JSON.serialize({{{deserializedExample}}});
res.setHeader('Content-Type', '{{contentType}}');
res.setBody(js);
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}}
}