Package org.openbravo.test.webservice
Class BaseWSTest
- java.lang.Object
-
- org.openbravo.test.base.MockableBaseTest
-
- org.openbravo.test.base.OBBaseTest
-
- org.openbravo.test.webservice.BaseWSTest
-
- Direct Known Subclasses:
JSONWebServices
,JSONWebServicesWhereParameter
,PerformanceTest
,WebServicesWithNoActiveFilterTest
,WSAddRecordWithComputedColumns
,WSReadableClientsTest
,WSReadTest
,WSUpdateTest
,WSWithNoActiveDalObjects
public class BaseWSTest extends OBBaseTest
Base class for webservice tests. Provides several methods to do HTTP REST requests.- Author:
- mtaal
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BaseWSTest.SimpleErrorHandler
-
Field Summary
Fields Modifier and Type Field Description protected static String
LOGIN
protected static String
PWD
-
Fields inherited from class org.openbravo.test.base.OBBaseTest
DOLLAR, DOLLAR_ID, EURO, EURO_ID, QA_TEST_ADMIN_USER_ID, QA_TEST_CLIENT_ID, QA_TEST_ORG_ID, TEST_BP_CATEGORY_ID, TEST_CLIENT_ID, TEST_INVOICE_ID, TEST_LOCATION_ID, TEST_ORDER_ID, TEST_ORG_ID, TEST_ORG_TREE, TEST_PRODUCT_ID, TEST_ROLE_ID, TEST_US_ORG_ID, TEST_USER_ID, TEST_WAREHOUSE_ID, TEST2_USER_ID, userIds, watchFailures
-
-
Constructor Summary
Constructors Constructor Description BaseWSTest()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected HttpURLConnection
createConnection(String wsPart, String method)
Creates a HTTP connection.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.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.protected void
doDirectDeleteRequest(String wsPart, int expectedResponse)
Executes a DELETE HTTP request, the wsPart is appended to thegetOpenbravoURL()
.protected String
doTestGetRequest(String wsPart, String testContent, int responseCode)
Executes a GET request and validates the return against the schema.protected String
doTestGetRequest(String wsPart, String testContent, int responseCode, boolean validate)
protected String
doTestGetRequest(String wsPart, String testContent, int responseCode, boolean validate, boolean logException)
Executes a GET request.protected String
getLogin()
Returns the login used to login for the webservice.protected String
getOpenbravoURL()
Returns the url of the Openbravo instance.protected String
getPassword()
Returns the password used to login into the webservice server.protected String
getTagValue(String content, String tag)
Convenience method to get a value of a specific XML element without parsing the whole xmlprotected void
validateXML(String xml)
Validates the xml against the generated schema.-
Methods inherited from class org.openbravo.test.base.OBBaseTest
addReadWriteAccess, classSetUp, commitTransaction, count, getConnectionProvider, getOneInstance, getRandomUser, getTestLogAppender, initializeDalLayer, initializeDisabledTestCases, initializeTestLogAppender, isErrorOccured, reportException, rollback, setLogStackTraces, setQAAdminContext, setSystemAdministratorContext, setTestAdminContext, setTestLogAppenderLevel, setTestUserContext, setUp, setUserContext, shouldMockServletContext, staticInitializeDalLayer, testDone
-
Methods inherited from class org.openbravo.test.base.MockableBaseTest
mockStatic
-
-
-
-
Field Detail
-
LOGIN
protected static final String LOGIN
- See Also:
- Constant Field Values
-
PWD
protected static final String PWD
- See Also:
- Constant Field Values
-
-
Method Detail
-
doDirectDeleteRequest
protected void doDirectDeleteRequest(String wsPart, int expectedResponse)
Executes a DELETE HTTP request, the wsPart is appended to thegetOpenbravoURL()
.- Parameters:
wsPart
- the actual webservice part of the url, is appended to the openbravo url (getOpenbravoURL()
), includes any query parametersexpectedResponse
- 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 parameterscontent
- the content (XML) to post or putexpectedResponse
- the expected HTTP response codeexpectedContent
- the system check that the returned content contains this expectedContentmethod
- 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 istrue
, 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 parameterscontent
- the content (XML) to post or putexpectedResponse
- the expected HTTP response codeexpectedContent
- the system check that the returned content contains this expectedContentmethod
- POST or PUTvalidateXML
- 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 xmltag
- 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 parameterstestContent
- 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 parameterstestContent
- 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 codevalidate
- if true then the response content is validated against the Openbravo XML SchemalogException
- 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 isLOGIN
.- 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 isPWD
.- 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
-
-