Class BaseWSTest

    • Constructor Detail

      • BaseWSTest

        public BaseWSTest()
    • Method Detail

      • doDirectDeleteRequest

        protected void doDirectDeleteRequest​(String wsPart,
                                             int expectedResponse)
        Executes a DELETE HTTP request, the wsPart is appended to the getOpenbravoURL().
        Parameters:
        wsPart - the actual webservice part of the url, is appended to the openbravo url ( getOpenbravoURL()), includes any query parameters
        expectedResponse - the expected HTTP response code
      • doContentRequest

        protected String doContentRequest​(String wsPart,
                                          String content,
                                          int expectedResponse,
                                          String expectedContent,
                                          String method)
        Execute a REST webservice HTTP request which posts/puts content and returns a XML result. The content is validated against the XML schema retrieved using the /ws/dal/schema webservice call.
        Parameters:
        wsPart - the actual webservice part of the url, is appended to the openbravo url ( getOpenbravoURL()), includes any query parameters
        content - the content (XML) to post or put
        expectedResponse - the expected HTTP response code
        expectedContent - the system check that the returned content contains this expectedContent
        method - POST or PUT
        Returns:
        the result from the rest request (i.e. the content of the response), most of the time an xml string
      • doContentRequest

        protected String doContentRequest​(String wsPart,
                                          String content,
                                          int expectedResponse,
                                          String expectedContent,
                                          String method,
                                          boolean validateXML)
        Execute a REST webservice HTTP request which posts/puts content and returns a result. If validateXML parameter is true, the content is validated against the XML schema retrieved using the /ws/dal/schema webservice call.
        Parameters:
        wsPart - the actual webservice part of the url, is appended to the openbravo url ( getOpenbravoURL()), includes any query parameters
        content - the content (XML) to post or put
        expectedResponse - the expected HTTP response code
        expectedContent - the system check that the returned content contains this expectedContent
        method - POST or PUT
        validateXML - should response be validated as XML
        Returns:
        the result from the rest request (i.e. the content of the response), most of the time an xml string
      • getTagValue

        protected String getTagValue​(String content,
                                     String tag)
        Convenience method to get a value of a specific XML element without parsing the whole xml
        Parameters:
        content - the xml
        tag - the element name
        Returns:
        the value
      • doTestGetRequest

        protected String doTestGetRequest​(String wsPart,
                                          String testContent,
                                          int responseCode)
        Executes a GET request and validates the return against the schema. The content is validated against the XML schema retrieved using the /ws/dal/schema webservice call.
        Parameters:
        wsPart - the actual webservice part of the url, is appended to the openbravo url ( getOpenbravoURL()), includes any query parameters
        testContent - the system check that the returned content contains this testContent. if null is passed for this parameter then this check is not done.
        responseCode - the expected HTTP response code
        Returns:
        the content returned from the GET request
      • doTestGetRequest

        protected String doTestGetRequest​(String wsPart,
                                          String testContent,
                                          int responseCode,
                                          boolean validate)
      • doTestGetRequest

        protected String doTestGetRequest​(String wsPart,
                                          String testContent,
                                          int responseCode,
                                          boolean validate,
                                          boolean logException)
        Executes a GET request. The content is validated against the XML schema retrieved using the /ws/dal/schema webservice call.
        Parameters:
        wsPart - the actual webservice part of the url, is appended to the openbravo url ( getOpenbravoURL()), includes any query parameters
        testContent - the system check that the returned content contains this testContent. if null is passed for this parameter then this check is not done.
        responseCode - the expected HTTP response code
        validate - if true then the response content is validated against the Openbravo XML Schema
        logException - indicates whether in case of Exception it should be logged, this param should be false when Exception is expected in order not to pollute the log
        Returns:
        the content returned from the GET request
      • createConnection

        protected HttpURLConnection createConnection​(String wsPart,
                                                     String method)
                                              throws Exception
        Creates a HTTP connection.
        Parameters:
        wsPart -
        method - POST, PUT, GET or DELETE
        Returns:
        the created connection
        Throws:
        Exception
      • getOpenbravoURL

        protected String getOpenbravoURL()
        Returns the url of the Openbravo instance. The default value is: OB_URL
        Returns:
        the url of the Openbravo instance.
      • getLogin

        protected String getLogin()
        Returns the login used to login for the webservice. The default value is LOGIN.
        Returns:
        the login name used to login for the webservice
      • getPassword

        protected String getPassword()
        Returns the password used to login into the webservice server. The default value is PWD.
        Returns:
        the password used to login into the webservice, the default is PWD
      • validateXML

        protected void validateXML​(String xml)
        Validates the xml against the generated schema.
        Parameters:
        xml - the xml to validate