All Downloads are FREE. Search and download functionalities are using the official Maven repository.

apex.api_test.mustache Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
@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}}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy