Class CompositeContractTemplate

  • All Implemented Interfaces:
    ContractTemplate

    public class CompositeContractTemplate
    extends Object
    implements ContractTemplate
    For backward compatibility when assertions take place, first checks the custom setup. Writes in a new format, can read the old format.
    Since:
    2.1.0
    Author:
    Marcin Grzejszczak
    • Constructor Detail

      • CompositeContractTemplate

        public CompositeContractTemplate()
    • Method Detail

      • startsWithTemplate

        public boolean startsWithTemplate​(String text)
        Specified by:
        startsWithTemplate in interface ContractTemplate
        Parameters:
        text - text to assert
        Returns:
        asserts whether the given text starts with proper opening template.
      • startsWithEscapedTemplate

        public boolean startsWithEscapedTemplate​(String text)
        Specified by:
        startsWithEscapedTemplate in interface ContractTemplate
        Parameters:
        text - text to assert
        Returns:
        asserts whether the given text starts with proper opening template for escaped value.
      • openingTemplate

        public String openingTemplate()
        Description copied from interface: ContractTemplate
        Handlebars is using the Mustache template thus it looks like this {{ Mustache }}. In this case the opening template would return {{
        Specified by:
        openingTemplate in interface ContractTemplate
        Returns:
        opening template for a variable
      • closingTemplate

        public String closingTemplate()
        Description copied from interface: ContractTemplate
        Handlebars is using the Mustache template thus it looks like this {{ Mustache }}. In this case the closing template would return }}
        Specified by:
        closingTemplate in interface ContractTemplate
        Returns:
        closing template for a variable
      • escapedOpeningTemplate

        public String escapedOpeningTemplate()
        Description copied from interface: ContractTemplate
        Handlebars is using the Mustache template thus it looks like this {{{ Mustache }}}. In this case the opening template would return {{{
        Specified by:
        escapedOpeningTemplate in interface ContractTemplate
        Returns:
        escaped opening template for a variable
      • escapedClosingTemplate

        public String escapedClosingTemplate()
        Description copied from interface: ContractTemplate
        Handlebars is using the Mustache template thus it looks like this {{{ Mustache }}}. In this case the closing template would return }}}
        Specified by:
        escapedClosingTemplate in interface ContractTemplate
        Returns:
        escaped closing template for a variable
      • url

        public String url()
        Specified by:
        url in interface ContractTemplate
        Returns:
        returns the template for retrieving a URL path and query from request
      • query

        public String query​(String key)
        Specified by:
        query in interface ContractTemplate
        Parameters:
        key - query parameter key
        Returns:
        the template for retrieving first value of a query parameter e.g. {{ request.query.search }}
      • query

        public String query​(String key,
                            int index)
        Specified by:
        query in interface ContractTemplate
        Parameters:
        key - query parameter key
        index - query parameter index
        Returns:
        the template for retrieving nth value of a query parameter (zero indexed) e.g. {{ request.query.search.[5] }}
      • path

        public String path​(int index)
        Specified by:
        path in interface ContractTemplate
        Parameters:
        index - request path index
        Returns:
        the template for retrieving nth value of a URL path (zero indexed) e.g. {{ request.path.[2] }}
      • header

        public String header​(String key)
        Specified by:
        header in interface ContractTemplate
        Parameters:
        key - headers key
        Returns:
        the template for retrieving the first value of a request header e.g. {{ request.headers.X-Request-Id }}
      • header

        public String header​(String key,
                             int index)
        Specified by:
        header in interface ContractTemplate
        Parameters:
        key - headers key
        index - headers index
        Returns:
        the template for retrieving the nth value of a request header (zero indexed) e.g. {{ request.headers.X-Request-Id.[5] }}
      • cookie

        public String cookie​(String key)
        Specified by:
        cookie in interface ContractTemplate
        Parameters:
        key - cookie key
        Returns:
        the template for retrieving the first value of a cookie with certain key
      • body

        public String body()
        Specified by:
        body in interface ContractTemplate
        Returns:
        request body text (avoid for non-text bodies) e.g. {{ request.body }} . The body will not be escaped so you won't be able to directly embed it in a JSON for example.
      • escapedBody

        public String escapedBody()
        Specified by:
        escapedBody in interface ContractTemplate
        Returns:
        request body text (avoid for non-text bodies) e.g. {{{ request.body }}} . The body will not be escaped so you won't be able to directly embed it in a JSON for example.
      • escapedBody

        public String escapedBody​(String jsonPath)
        Specified by:
        escapedBody in interface ContractTemplate
        Parameters:
        jsonPath - json path value
        Returns:
        request body text for the given JsonPath. e.g. {{{ jsonPath request.body '$.a.b.c' }}}
      • body

        public String body​(String jsonPath)
        Specified by:
        body in interface ContractTemplate
        Parameters:
        jsonPath - json path value
        Returns:
        request body text for the given JsonPath. e.g. {{ jsonPath request.body '$.a.b.c' }}
      • escapedUrl

        public String escapedUrl()
        Specified by:
        escapedUrl in interface ContractTemplate
        Returns:
        the template for retrieving a escaped URL path and query from request
      • escapedQuery

        public String escapedQuery​(String key)
        Specified by:
        escapedQuery in interface ContractTemplate
        Parameters:
        key - query parameter key
        Returns:
        the template for retrieving escaped first value of a query parameter e.g. {{{ request.query.search }}}
      • escapedQuery

        public String escapedQuery​(String key,
                                   int index)
        Specified by:
        escapedQuery in interface ContractTemplate
        Parameters:
        key - query parameter key
        index - query parameter index
        Returns:
        the template for retrieving esacped nth value of a query parameter (zero indexed) e.g. {{{ request.query.search.[5] }}}
      • escapedPath

        public String escapedPath​(int index)
        Specified by:
        escapedPath in interface ContractTemplate
        Parameters:
        index - path index
        Returns:
        the template for retrieving escaped nth value of a URL path (zero indexed) e.g. {{{ request.path.[2] }}}
      • escapedHeader

        public String escapedHeader​(String key)
        Specified by:
        escapedHeader in interface ContractTemplate
        Parameters:
        key - headers key
        Returns:
        the template for retrieving the escaped first value of a request header e.g. {{{ request.headers.X-Request-Id }}}
      • escapedHeader

        public String escapedHeader​(String key,
                                    int index)
        Specified by:
        escapedHeader in interface ContractTemplate
        Parameters:
        key - headers key
        index - headers index
        Returns:
        the template for retrieving the esacaped nth value of a request header (zero indexed) e.g. {{{ request.headers.X-Request-Id.[5] }}}
      • escapedCookie

        public String escapedCookie​(String key)
        Specified by:
        escapedCookie in interface ContractTemplate
        Parameters:
        key - cookie key
        Returns:
        the template for retrieving the escaped first value of a cookie with certain key