Class RESTWebServiceTest

    • Constructor Detail

      • RESTWebServiceTest

        public RESTWebServiceTest()
    • Method Detail

      • reloadAdminCaches

        public void reloadAdminCaches()
      • getTableCreationScript

        protected String getTableCreationScript()
        Gets the SQL script file in the classpath that contains statements to create table(s) specific to this test.
        Returns:
        the path in the classpath of a SQL script file (or empty if no such SQL script).
      • getDataSetScript

        protected String getDataSetScript()
        Gets the SQL script file in the classpath that contains statements to prepare the database used by this test with a data set.
        Returns:
        the path in the classpath of a SQL script file (or empty if no such SQL script)
      • getExistingComponentInstances

        public abstract String[] getExistingComponentInstances()
        Gets the component instances to take into account in tests. Theses component instances will be considered as existing. Others than those will be rejected with an HTTP error 404 (NOT FOUND).
        Returns:
        an array with the identifier of the component instances to take into account in tests. The array cannot be null, but it can be empty.
      • getExistingTools

        public String[] getExistingTools()
        Gets tools to take into account in tests. These tools will be considered as existing. Others than those will be rejected with an HTTP error 404 (NOT FOUND).
        Returns:
        an array with the identifier of tools to take into account in tests. The array cannot be null, but it can be empty.
      • resource

        public javax.ws.rs.client.WebTarget resource()
        Gets an initialized web target resource instance for tests.
        Returns:
        the WebTarget instance.
      • getBaseURI

        protected URI getBaseURI()
      • getWebResourceBaseURIBuilder

        protected javax.ws.rs.core.UriBuilder getWebResourceBaseURIBuilder()
        Gets a URI builder initialized with the base URI at which are exposed by default all the REST web resources in Silverpeas. This is to be used for checking URIs in returned entities in the tests.
        Returns:
        an initialized UriBuilder
      • getTokenKeyOf

        public String getTokenKeyOf​(User theUser)

        Gets (and initializes if necessary) the token key of the given user.
        The user must exist into database (use SilverpeasTestEnvironment.createDefaultUser() to add a user, and use getSilverpeasEnvironmentTest() to get the silverpeas environment manager instance).

        For example:

        getTokenKeyOf(get().createUser());

        Parameters:
        theUser - the user to authenticate.
        Returns:
        the key of the opened session.
      • denyAuthorizationToUsers

        public void denyAuthorizationToUsers()
        Denies the access to the silverpeas resources to all users. It sets no public both the dummy component and all the existing component instances on which the test is working. All the user roles are removed from all the component instances as well as from all of their parent spaces.
      • denySpaceAuthorizationToUsers

        public void denySpaceAuthorizationToUsers()
        Denies the access to the silverpeas spaces to all users.
      • authenticate

        public String authenticate​(User user)
        Authenticates the specified user through the REST-based Web API and returns the opened session identifier. The returned session identifier can then be used in the subsequent requests sent during a test. Once the session is opened for the given user, the session cache service is then get to be set for the local thread of the current running test, so that the data prepared for the test and cached in the session cache of the user will be accessible within the thread of the tested web service.

        Warning: the authentication is performed by the corresponding REST-based web service and as such this one is required to be included in the deployment archive as well as all of its dependencies.

        Parameters:
        user - the user to authenticate.
        Returns:
        the opened user session identifier.
      • applyQueryParameters

        protected javax.ws.rs.client.WebTarget applyQueryParameters​(String parameterQueryPart,
                                                                    javax.ws.rs.client.WebTarget resource)
      • withAsAuthId

        protected AuthId withAsAuthId​(AuthId credential)
      • setUserIdent

        protected javax.ws.rs.client.Invocation.Builder setUserIdent​(AuthId authId,
                                                                     javax.ws.rs.client.Invocation.Builder http)
      • setUpHTTPRequest

        protected javax.ws.rs.client.Invocation.Builder setUpHTTPRequest​(String uri,
                                                                         String mediaType,
                                                                         AuthId authId)