Class JAXRSCommonClient

java.lang.Object
ee.jakarta.tck.ws.rs.common.JAXRSCommonClient
Direct Known Subclasses:
DefaultExceptionMapperIT, JAXRSClient, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JAXRSClientIT, JaxrsCommonClient, JAXRSDelegateClient, JaxrsParamClient, JAXRSProvidersClientIT, UriInfo40ClientIT

public abstract class JAXRSCommonClient extends Object
Author:
dianne jiao, jan supol
  • Field Details

    • SERVLETHOSTPROP

      protected static final String SERVLETHOSTPROP
      TS Webserver host property
      See Also:
    • SERVLETPORTPROP

      protected static final String SERVLETPORTPROP
      TS Webserver port property
      See Also:
    • TSHOME

      protected static final String TSHOME
      TS home property
      See Also:
    • TEST_PROPS

      protected static final Hashtable<JAXRSCommonClient.Property,String> TEST_PROPS
      Test properties
    • STATUS_CODE

      protected static final String STATUS_CODE
      StatusCode property
      See Also:
    • REQUEST

      protected static final String REQUEST
      Request property
      See Also:
    • REQUEST_HEADERS

      protected static final String REQUEST_HEADERS
      Request headers property
      See Also:
    • GOLDENFILE

      protected static final String GOLDENFILE
      Goldenfile property
      See Also:
    • SEARCH_STRING

      protected static final String SEARCH_STRING
      Search string property
      See Also:
    • TESTDIR

      protected String TESTDIR
      Search string case insensitive property
    • GOLDENFILEDIR

      protected String GOLDENFILEDIR
      Goldenfile directory
    • GET

      protected static final String GET
      Default request method
      See Also:
    • HTTP10

      protected static final String HTTP10
      HTTP 1.0
      See Also:
    • HTTP11

      protected static final String HTTP11
      HTTP 1.1
      See Also:
    • SL

      protected static final String SL
      Forward slash
      See Also:
    • GF_SUFFIX

      protected static final String GF_SUFFIX
      Goldenfile suffix
      See Also:
    • _testName

      protected String _testName
      Current test name
    • _tsHome

      protected String _tsHome
      location of _tsHome
    • _contextRoot

      public String _contextRoot
      Context root of target tests
    • _generalURI

      protected String _generalURI
      General file/request URI for both gfiles and tests
    • _hostname

      protected String _hostname
      Target webserver hostname
    • _port

      protected int _port
      Target webserver port
    • _state

      protected org.apache.commons.httpclient.HttpState _state
      HttpState that may be used for multiple invocations requiring state.
    • _testCase

      protected WebTestCase _testCase
      Test case.
    • _useSavedState

      protected boolean _useSavedState
      Use saved state.
    • _saveState

      protected boolean _saveState
      Save state.
    • _redirect

      protected boolean _redirect
    • newline

      public static final String newline
    • servletAdaptor

      public static final String servletAdaptor
    • indent

      public static final String indent
      See Also:
    • _servlet

      protected String _servlet
  • Constructor Details

    • JAXRSCommonClient

      public JAXRSCommonClient()
  • Method Details

    • setTestDir

      public void setTestDir(String testDir)
      setTestDir sets the current test directory.
      Parameters:
      testDir - a String value
    • setContextRoot

      public void setContextRoot(String root)
    • getContextRoot

      public String getContextRoot()
    • setup

      public void setup()
      setup is by the test harness to initialize the tests.
      Parameters:
      args - a String[] value
      p - a Properties value
      Throws:
      JAXRSCommonClient.Fault - if an error occurs
    • cleanup

      public void cleanup() throws JAXRSCommonClient.Fault
      cleanup is called by the test harness to cleanup after text execution
      Throws:
      JAXRSCommonClient.Fault - if an error occurs
    • invoke

      protected void invoke() throws JAXRSCommonClient.Fault
       Invokes a test based on the properties
       stored in TEST_PROPS.  Once the test has completed,
       the properties in TEST_PROPS will be cleared.
       
      Throws:
      JAXRSCommonClient.Fault - If an error occurs during the test run
    • setTestProperties

      protected void setTestProperties(WebTestCase testCase)
       Sets the appropriate test properties based
       on the values stored in TEST_PROPS
       
    • setWebTestCaseRequest

      protected HttpRequest setWebTestCaseRequest(WebTestCase testCase, HttpRequest req)
    • setWebTestCaseProperties

      protected void setWebTestCaseProperties(WebTestCase testCase, HttpRequest req)
    • buildRequest

      protected String buildRequest(String type, String... path)
      Create request // HTTP/1.1. ContextRoot is defined in every client.
      Parameters:
      type - PUT, GET, POST, ...
      path - path defined in a servlet
      Returns:
      String representing HTTP request
    • buildRequest

      protected String buildRequest(JAXRSCommonClient.Request type, String... path)
    • buildRequest10

      protected String buildRequest10(JAXRSCommonClient.Request type, String... path)
    • buildAccept

      protected static String buildAccept(jakarta.ws.rs.core.MediaType type)
      Create counterpart to @Produces
      Parameters:
      type -
      Returns:
      Accept:type.Object.toString()
    • buildContentType

      protected static String buildContentType(jakarta.ws.rs.core.MediaType type)
      Create counterpart to @Consumes
      Parameters:
      type -
      Returns:
    • buildHeaderMediaType

      protected static String buildHeaderMediaType(String header, jakarta.ws.rs.core.MediaType type)
    • toString

      public static String toString(InputStream inStream) throws IOException
      Throws:
      IOException
    • editWebXmlString

      public static String editWebXmlString(InputStream inStream) throws IOException
      Throws:
      IOException
    • getResponseBody

      protected String getResponseBody() throws JAXRSCommonClient.Fault
      Returns:
      http response body as string
      Throws:
      JAXRSCommonClient.Fault - when an error occur
    • getResponseHeaders

      protected String[] getResponseHeaders() throws JAXRSCommonClient.Fault
      Returns:
      http response body as string
      Throws:
      JAXRSCommonClient.Fault - when an error occur
    • assertResponseHeadersContain

      protected void assertResponseHeadersContain(String s) throws JAXRSCommonClient.Fault
      Parameters:
      s - the header to search
      Throws:
      JAXRSCommonClient.Fault - when header not found
    • assertResponseBodyContain

      protected void assertResponseBodyContain(String s) throws JAXRSCommonClient.Fault
      Parameters:
      s - the entity to search
      Throws:
      JAXRSCommonClient.Fault - when entity not found
    • getResponseStatusCode

      protected jakarta.ws.rs.core.Response.Status getResponseStatusCode()
      get HttpResponse#statusCode
      Returns:
      JAXRS Response.Status equivalent of HttpResponse#statusCode
    • setProperty

      protected void setProperty(String key, String value)
      Set TEST_PROPS property value. If it already exists, the value is appended
    • setProperty

      protected void setProperty(JAXRSCommonClient.Property key, String... value)
    • setProperty

      protected void setProperty(JAXRSCommonClient.Property key, String value)
    • clearProperty

      protected void clearProperty(JAXRSCommonClient.Property key)
    • assertEquals

      public static <T> void assertEquals(T first, T second, Object... message)
      Asserts that two objects are equal. When instances of Comparable, such as String, compareTo is used.
      Parameters:
      first - first object
      second - second object
      message - a space separated message[i].toString() compilation for i=<0,message.length)
    • assertEqualsInt

      public static <T> void assertEqualsInt(int first, int second, Object... message)
    • assertEqualsLong

      public static <T> void assertEqualsLong(long first, long second, Object... message)
    • assertEqualsBool

      public static <T> void assertEqualsBool(boolean first, boolean second, Object... message)
    • assertNull

      public static void assertNull(Object object, Object... message)
      Asserts that an object is null.
      Parameters:
      object - Assert that object is not null
      message - a space separated message[i].toString() compilation for i=<0,message.length)
    • assertNotNull

      public static void assertNotNull(Object object, Object... message)
      Asserts that an object is not null.
      Parameters:
      object - Assert that object is not null
      message - a space separated message[i].toString() compilation for i=<0,message.length)
    • fault

      public static void fault(Object... objects) throws JAXRSCommonClient.Fault
      Throws Fault with space separated objects[1],object[2],...,object[n] message
      Parameters:
      objects - objects whose toString() results will be added to Fault message
      Throws:
      JAXRSCommonClient.Fault - fault with space separated objects.toString values
    • assertContains

      public static void assertContains(String string, String substring, Object... message)
      Assert that given substring is a substring of given string
      Parameters:
      string - the string to search substring in
      substring - the substring to be searched in a given string
      message - space separated message values to be thrown
    • assertContainsIgnoreCase

      public static void assertContainsIgnoreCase(String string, String substring, Object... message)
      Assert that given substring is a substring of given string, case insensitive
      Parameters:
      string - the string to search substring in
      substring - the substring to be searched in a given string
      message - space separated message values to be thrown
    • assertContains

      public static <T> void assertContains(T text, T subtext, Object... message)
      Assert that given subtext.toString() subject is a substring of given text
      Parameters:
      text - the text.toString() object to search subtext.toString() in
      subtext - the subtext.toString() to be searched in a given text.toString()
      message - space separated message values to be thrown
    • assertContainsIgnoreCase

      public static <T> void assertContainsIgnoreCase(T text, T subtext, Object... message)
      Assert that given subtext.toString() subject is a substring of given text, case insensitive
      Parameters:
      text - the text.toString() object to search subtext.toString() in
      subtext - the subtext.toString() to be searched in a given text.toString()
      message - space separated message values to be thrown
    • assertCause

      protected static <T extends Throwable> T assertCause(Throwable parent, Class<T> wrapped, Object... msg)
      Searches an encapsulated exception cause in parent exception
    • getStatusCode

      public static String getStatusCode(jakarta.ws.rs.core.Response.Status status)
    • logMsg

      public static void logMsg(Object... msg)
    • logTrace

      public static void logTrace(Object... msg)
    • objectsToString

      protected static String objectsToString(Object... objects)
      Use rather this method than JaxrsUtil.iterableToString(String, Iterable) since not all wars (for servlet vehicle, api) do contain JaxrsUtil
      Parameters:
      objects -
      Returns:
      objects in a single string , each object separated by " "
    • objectsToString

      protected static String objectsToString(String delimiter, Object... objects)
      Since:
      2.0.1
    • clearTestProperties

      protected void clearTestProperties()
      Clears the contents of TEST_PROPS
    • isNullOrEmpty

      protected boolean isNullOrEmpty(String val)
    • createHttpRequest

      protected HttpRequest createHttpRequest(String requestLine, String host, int port)
    • setServletName

      protected void setServletName(String servlet)
      Sets the name of the servlet to use when building a request for a single servlet API test.
      Parameters:
      servlet - - the name of the servlet
    • getServletName

      protected String getServletName()
    • getLocalInterfaceInfo

      protected String getLocalInterfaceInfo(boolean returnAddresses)
    • getAbsoluteUrl

      protected String getAbsoluteUrl()
    • getAbsoluteUrl

      protected String getAbsoluteUrl(String method)