Class RestWrapper


  • @Service
    @Scope("prototype")
    public class RestWrapper
    extends org.alfresco.utility.dsl.DSLWrapper<RestWrapper>
    • Field Detail

    • Constructor Detail

      • RestWrapper

        public RestWrapper()
    • Method Detail

      • setServerPort

        public void setServerPort​(int serverPort)
      • setResponseHeaders

        public void setResponseHeaders​(io.restassured.http.Headers responseHeaders)
      • getResponseHeaders

        public io.restassured.http.Headers getResponseHeaders()
      • assertHeaderValueContains

        public RestWrapper assertHeaderValueContains​(java.lang.String headerName,
                                                     java.lang.String expectedHeaderValue)
        Verify response header contains a specific value Example: assertHeaderValueContains("Content-Disposition", "filename=\"myfile.txt\"");
        Parameters:
        headerName - the header name from response
        expectedHeaderValue - the header property value to be checked
        Returns:
      • initializeRequestSpecBuilder

        @PostConstruct
        public void initializeRequestSpecBuilder()
      • authenticateUser

        public RestWrapper authenticateUser​(org.alfresco.utility.model.UserModel userModel)
        Authenticate specific user to Alfresco REST API
        Parameters:
        userModel -
        Returns:
      • noAuthentication

        public RestWrapper noAuthentication()
      • onRequest

        protected io.restassured.specification.RequestSpecification onRequest()
        Request sent to server
      • setLastError

        public void setLastError​(RestErrorModel errorModel)
      • assertLastStatus

        public org.alfresco.utility.model.StatusModel assertLastStatus()
      • assertLastExceptionContains

        public RestWrapper assertLastExceptionContains​(java.lang.String exception)
      • processRelationsJson

        public java.util.List<java.lang.Object> processRelationsJson​(RestRequest restRequest)
        Process responses for site relations models, such as {@link RestSiteModel, RestSiteContainerModelsCollection, RestSiteMemberModelsCollection}
      • processSitesRelationsJson

        public java.util.List<java.util.List<java.lang.Object>> processSitesRelationsJson​(RestRequest restRequest)
        Process responses for site relations models, such as {@link RestSiteModel, RestSiteContainerModelsCollection, RestSiteMemberModelsCollection}
      • getLastStatus

        public org.alfresco.utility.model.StatusModel getLastStatus()
      • setLastStatus

        public void setLastStatus​(org.alfresco.utility.model.StatusModel lastStatusModel)
        Set the status code for the latest REST call
        Parameters:
        lastStatusModel -
      • getStatusCode

        public java.lang.String getStatusCode()
      • setStatusCode

        public void setStatusCode​(java.lang.String statusCode)
      • sendRequest

        protected io.restassured.response.Response sendRequest​(RestRequest restRequest)
        Send REST request based on HTTP method
        Parameters:
        restRequest -
        Returns:
      • assertStatusCodeIs

        public RestWrapper assertStatusCodeIs​(org.springframework.http.HttpStatus statusCode)
        Assert that a specific status code is returned
        Parameters:
        statusCode -
        Returns:
        ;
      • validateJsonModelSchema

        public <T> void validateJsonModelSchema​(java.lang.Class<T> classz,
                                                java.lang.Object classzInstance)
                                         throws java.lang.IllegalAccessException,
                                                java.lang.IllegalArgumentException,
                                                java.lang.reflect.InvocationTargetException,
                                                java.lang.InstantiationException
        Check that REST response has returned all required fields
        Parameters:
        classz -
        classzInstance -
        Throws:
        java.lang.IllegalAccessException
        java.lang.IllegalArgumentException
        java.lang.reflect.InvocationTargetException
        java.lang.InstantiationException
      • getParameters

        public java.lang.String getParameters()
        Returns:
        parameters that you could pass on the request ?param=value
      • setParameters

        public void setParameters​(java.lang.String parameters)
        Define the entire string of parameters that will be send to request Don't forget to call getParameters() in the request to enable this.
        Parameters:
        parameters -
      • clearParameters

        public void clearParameters()
        Just clear the parameters sent
      • clearBasePath

        public RestWrapper clearBasePath()
        just clear the base path
        Returns:
      • withParams

        public RestWrapper withParams​(java.lang.String... parameters)
        Send key=value parameters All of them will be automatically passed to url. Example: "maxItems=10000"
        Parameters:
        parameters -
        Returns:
      • withCoreAPI

        public RestCoreAPI withCoreAPI()
        Returns:
        RestCoreAPI using the rest Core API as prefix: {@link /alfresco/api/-default-/public/alfresco/versions/1}
      • withWorkflowAPI

        public RestWorkflowAPI withWorkflowAPI()
        Returns:
        RestWorkflowAPI using the rest Workflow API with prefix: {@link /alfresco/api/-default-/public/workflow/versions/1 }
      • withAuthAPI

        public RestAuthAPI withAuthAPI()
        Returns:
        RestAuthAPI using the rest Auth API with prefix: {@link /alfresco/api/-default-/public/authentication/versions/1 }
      • withSearchAPI

        public SearchAPI withSearchAPI()
      • withSearchSqlViaJDBC

        public SearchSQLJDBC withSearchSqlViaJDBC()
      • withSolrAPI

        public SolrAPI withSolrAPI()
      • withDiscoveryAPI

        public RestDiscoveryAPI withDiscoveryAPI()
        Returns:
        RestDiscoveryAPI using the rest Discovery API as prefix: {@link /alfresco/api/discovery}
      • withAdminConsole

        public AdminConsole withAdminConsole()
        Returns:
        AdminConsole using the Admin Console API as prefix: {@link /alfresco/service/api/server}
      • usingTenant

        public Tenant usingTenant()
        Provides DSL on creating Tenant users
        Returns:
        Tenant
      • where

        public RestWrapper where​(java.lang.String whereExpression)
        Construct the Where clause of any REST API call You can use the where parameter to restrict the list in the response to entries of a specific kind. The where parameter takes a value.
      • getDefaultContentType

        public io.restassured.http.ContentType getDefaultContentType()
      • usingContentType

        public RestWrapper usingContentType​(io.restassured.http.ContentType defaultContentType)
      • configureRequestSpec

        public io.restassured.builder.RequestSpecBuilder configureRequestSpec()
        You can handle the request sent to server by calling this method. If for example you want to sent multipart form data you can use: restClient.configureRequestSpec() .addMultiPart("filedata", Utility.getResourceTestDataFile("restapi-resource")) .addFormParam("renditions", "doclib") .addFormParam("autoRename", true); restClient.withCoreAPI().usingNode(ContentModel.my()).createNode(); This will create the node using the multipart data defined.
        Returns:
      • withCMISApi

        public RestCmisAPI withCMISApi()
        Perform CMIS browser binding calls ("alfresco/api/-default-/public/cmis/versions/1.1/browser") with Rest API
        Returns:
        RestCmisAPI
      • withAosAPI

        public RestAosAPI withAosAPI()
        Perform AOS browser binding calls ("alfresco/aos") with Rest API
        Returns:
        RestAosAPI
      • withPrivateAPI

        public RestPrivateAPI withPrivateAPI()
        Returns:
        RestPrivateAPI using the rest Private API as prefix: {@link /alfresco/api/-default-/private/alfresco/versions/1}
      • configureSyncServiceEndPoint

        public void configureSyncServiceEndPoint()
      • configureSolrEndPoint

        public void configureSolrEndPoint()
      • configureAlfrescoEndpoint

        public void configureAlfrescoEndpoint()
        Adding new method to configure Alfresco Endpoint. Reconfiguration is required when restClient is used to executed apis on different : e.g. solr api followed by search api