Class RestWrapper

java.lang.Object
org.alfresco.utility.dsl.DSLWrapper<RestWrapper>
org.alfresco.rest.core.RestWrapper

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

  • Constructor Details

    • RestWrapper

      public RestWrapper()
  • Method Details

    • setServerURI

      public void setServerURI(String serverURI)
      Parameters:
      serverURI - in format of "http://localhost", without port. Set port via setServerPort(int)
    • 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(String headerName, 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)
    • assertLastError

      public RestErrorModel assertLastError()
    • assertLastStatus

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

      public RestWrapper assertLastExceptionContains(String exception)
    • processModels

      public <T> T processModels(Class<T> classz, RestRequest restRequest) throws EmptyJsonResponseException, JsonToModelConversionException
      Process responses for a collection of models as RestSiteModelsCollection
      Throws:
      JsonToModelConversionException - If the response cannot be converted to the given model.
      EmptyJsonResponseException - If there is no response from the server.
    • processModel

      public <T> T processModel(Class<T> classz, RestRequest restRequest) throws EmptyJsonResponseException, JsonToModelConversionException
      Process responses for a single model as RestSiteModel
      Throws:
      JsonToModelConversionException - If the response cannot be converted to the given model.
      EmptyJsonResponseException - If there is no response from the server.
    • processJson

      public org.json.JSONObject processJson(RestRequest restRequest) throws EmptyJsonResponseException, JsonToModelConversionException
      Process responses for a single model as RestSiteModel
      Throws:
      JsonToModelConversionException - If the response cannot be converted to the given model.
      EmptyJsonResponseException - If there is no response from the server.
    • processRelationsJson

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

      public List<List<Object>> processSitesRelationsJson(RestRequest restRequest)
      Process responses for site relations models, such as {@link RestSiteModel, RestSiteContainerModelsCollection, RestSiteMemberModelsCollection}
    • processHtmlResponse

      public RestHtmlResponse processHtmlResponse(RestRequest restRequest) throws EmptyJsonResponseException
      Process a response that returns a html
      Parameters:
      restRequest -
      Returns:
      Throws:
      EmptyJsonResponseException - If there is no response from the server.
    • process

      public RestResponse process(RestRequest restRequest)
      Generic REST API call on a RestRequest
      Parameters:
      restRequest -
      Returns:
    • processTextResponse

      public RestTextResponse processTextResponse(RestRequest restRequest)
    • processEmptyModel

      public void processEmptyModel(RestRequest restRequest) throws EmptyJsonResponseException
      Process a response that has no body - basically will need only the status code from it
      Parameters:
      restRequest -
      Throws:
      EmptyJsonResponseException
    • 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 String getStatusCode()
    • setStatusCode

      public void setStatusCode(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(Class<T> classz, Object classzInstance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException
      Check that REST response has returned all required fields
      Parameters:
      classz -
      classzInstance -
      Throws:
      IllegalAccessException
      IllegalArgumentException
      InvocationTargetException
      InstantiationException
    • getParameters

      public String getParameters()
      Get and clear the stored parameters.
      Returns:
      parameters that you could pass on the request ?param=value
    • setParameters

      public void setParameters(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(String... parameters)
      Send key=value parameters.

      Note that this will replace any existing parameters.

      Parameters:
      parameters - A list of URL query parameters - e.g. "maxItems=10000"
      Returns:
      The RestWrapper
    • 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 }
    • withModelAPI

      public RestModelAPI withModelAPI()
    • withSearchAPI

      public SearchAPI withSearchAPI()
    • withSearchSqlAPI

      public SearchSQLAPI withSearchSqlAPI()
    • withSearchSqlViaJDBC

      public SearchSQLJDBC withSearchSqlViaJDBC()
    • withShardInfoAPI

      public ShardInfoAPI withShardInfoAPI()
    • withSolrAPI

      public SolrAPI withSolrAPI()
    • withSolrAdminAPI

      public SolrAdminAPI withSolrAdminAPI()
    • 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(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}
    • onResponse

      public RestResponse onResponse()
    • processModelWithoutEntryObject

      public <T> T processModelWithoutEntryObject(Class<T> classz, RestRequest restRequest) throws EmptyJsonResponseException, JsonToModelConversionException
      Process responses for a single model as RestSyncSetRequestModel Notice that RestSyncSetRequestModel doesn't have one "entry" field as any other rest request model
      Throws:
      JsonToModelConversionException - If the response cannot be converted to the given model.
      EmptyJsonResponseException - If there is no response from the server.
    • configureSyncServiceEndPoint

      public void configureSyncServiceEndPoint()
    • configureSolrEndPoint

      public void configureSolrEndPoint()
    • configureServerEndpoint

      public void configureServerEndpoint()
    • 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