Package org.alfresco.rest.core
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 Summary
Fields Modifier and Type Field Description protected RestPropertiesrestProperties
-
Constructor Summary
Constructors Constructor Description RestWrapper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RestWrapperassertHeaderValueContains(java.lang.String headerName, java.lang.String expectedHeaderValue)Verify response header contains a specific value Example: assertHeaderValueContains("Content-Disposition", "filename=\"myfile.txt\"");RestErrorModelassertLastError()RestWrapperassertLastExceptionContains(java.lang.String exception)org.alfresco.utility.model.StatusModelassertLastStatus()RestWrapperassertStatusCodeIs(org.springframework.http.HttpStatus statusCode)Assert that a specific status code is returnedRestWrapperauthenticateUser(org.alfresco.utility.model.UserModel userModel)Authenticate specific user to Alfresco REST APIRestWrapperclearBasePath()just clear the base pathvoidclearParameters()Just clear the parameters sentio.restassured.builder.RequestSpecBuilderconfigureRequestSpec()You can handle the request sent to server by calling this method.voidconfigureServerEndpoint()voidconfigureSolrEndPoint()voidconfigureSyncServiceEndPoint()io.restassured.http.ContentTypegetDefaultContentType()org.alfresco.utility.model.StatusModelgetLastStatus()java.lang.StringgetParameters()io.restassured.http.HeadersgetResponseHeaders()java.lang.StringgetStatusCode()voidinitializeRequestSpecBuilder()RestWrappernoAuthentication()protected io.restassured.specification.RequestSpecificationonRequest()Request sent to serverRestResponseonResponse()RestResponseprocess(RestRequest restRequest)Generic REST API call on aRestRequestvoidprocessEmptyModel(RestRequest restRequest)Process a response that has no body - basically will need only the status code from itRestHtmlResponseprocessHtmlResponse(RestRequest restRequest)Process a response that returns a htmlorg.json.JSONObjectprocessJson(RestRequest restRequest)Process responses for a single model asRestSiteModel<T> TprocessModel(java.lang.Class<T> classz, RestRequest restRequest)Process responses for a single model asRestSiteModel<T> TprocessModels(java.lang.Class<T> classz, RestRequest restRequest)Process responses for a collection of models asRestSiteModelsCollection<T> TprocessModelWithoutEntryObject(java.lang.Class<T> classz, RestRequest restRequest)Process responses for a single model asRestSyncSetRequestModelNotice thatRestSyncSetRequestModeldoesn't have one "entry" field as any other rest request modeljava.util.List<java.lang.Object>processRelationsJson(RestRequest restRequest)Process responses for site relations models, such as {@link RestSiteModel, RestSiteContainerModelsCollection, RestSiteMemberModelsCollection}java.util.List<java.util.List<java.lang.Object>>processSitesRelationsJson(RestRequest restRequest)Process responses for site relations models, such as {@link RestSiteModel, RestSiteContainerModelsCollection, RestSiteMemberModelsCollection}RestTextResponseprocessTextResponse(RestRequest restRequest)protected io.restassured.response.ResponsesendRequest(RestRequest restRequest)Send REST request based on HTTP methodvoidsetLastError(RestErrorModel errorModel)voidsetLastStatus(org.alfresco.utility.model.StatusModel lastStatusModel)Set the status code for the latest REST callvoidsetParameters(java.lang.String parameters)Define the entire string of parameters that will be send to request Don't forget to callgetParameters()in the request to enable this.voidsetResponseHeaders(io.restassured.http.Headers responseHeaders)voidsetServerPort(int serverPort)voidsetServerURI(java.lang.String serverURI)voidsetStatusCode(java.lang.String statusCode)RestWrapperusingContentType(io.restassured.http.ContentType defaultContentType)TenantusingTenant()Provides DSL on creating Tenant users<T> voidvalidateJsonModelSchema(java.lang.Class<T> classz, java.lang.Object classzInstance)Check that REST response has returned all required fieldsRestWrapperwhere(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.AdminConsolewithAdminConsole()RestAosAPIwithAosAPI()Perform AOS browser binding calls ("alfresco/aos") with Rest APIRestAuthAPIwithAuthAPI()RestCmisAPIwithCMISApi()Perform CMIS browser binding calls ("alfresco/api/-default-/public/cmis/versions/1.1/browser") with Rest APIRestCoreAPIwithCoreAPI()RestDiscoveryAPIwithDiscoveryAPI()RestWrapperwithParams(java.lang.String... parameters)Send key=value parameters All of them will be automatically passed to url.RestPrivateAPIwithPrivateAPI()SearchAPIwithSearchAPI()SearchSQLAPIwithSearchSqlAPI()SearchSQLJDBCwithSearchSqlViaJDBC()ShardInfoAPIwithShardInfoAPI()SolrAPIwithSolrAPI()RestWorkflowAPIwithWorkflowAPI()
-
-
-
Field Detail
-
restProperties
@Autowired protected RestProperties restProperties
-
-
Method Detail
-
setServerURI
public void setServerURI(java.lang.String serverURI)
- Parameters:
serverURI- in format of "http://localhost", without port. Set port viasetServerPort(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(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 responseexpectedHeaderValue- 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(java.lang.String exception)
-
processModels
public <T> T processModels(java.lang.Class<T> classz, RestRequest restRequest) throws EmptyJsonResponseException, JsonToModelConversionExceptionProcess responses for a collection of models asRestSiteModelsCollection- 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(java.lang.Class<T> classz, RestRequest restRequest) throws EmptyJsonResponseException, JsonToModelConversionExceptionProcess responses for a single model asRestSiteModel- 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 asRestSiteModel- Throws:
JsonToModelConversionException- If the response cannot be converted to the given model.EmptyJsonResponseException- If there is no response from the server.
-
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}
-
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 aRestRequest- 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 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.InstantiationExceptionCheck that REST response has returned all required fields- Parameters:
classz-classzInstance-- Throws:
java.lang.IllegalAccessExceptionjava.lang.IllegalArgumentExceptionjava.lang.reflect.InvocationTargetExceptionjava.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 callgetParameters()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:
RestCoreAPIusing the rest Core API as prefix: {@link /alfresco/api/-default-/public/alfresco/versions/1}
-
withWorkflowAPI
public RestWorkflowAPI withWorkflowAPI()
- Returns:
RestWorkflowAPIusing the rest Workflow API with prefix: {@link /alfresco/api/-default-/public/workflow/versions/1 }
-
withAuthAPI
public RestAuthAPI withAuthAPI()
- Returns:
RestAuthAPIusing the rest Auth API with prefix: {@link /alfresco/api/-default-/public/authentication/versions/1 }
-
withSearchAPI
public SearchAPI withSearchAPI()
-
withSearchSqlAPI
public SearchSQLAPI withSearchSqlAPI()
-
withSearchSqlViaJDBC
public SearchSQLJDBC withSearchSqlViaJDBC()
-
withShardInfoAPI
public ShardInfoAPI withShardInfoAPI()
-
withSolrAPI
public SolrAPI withSolrAPI()
-
withDiscoveryAPI
public RestDiscoveryAPI withDiscoveryAPI()
- Returns:
RestDiscoveryAPIusing the rest Discovery API as prefix: {@link /alfresco/api/discovery}
-
withAdminConsole
public AdminConsole withAdminConsole()
- Returns:
AdminConsoleusing the Admin Console API as prefix: {@link /alfresco/service/api/server}
-
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:
RestPrivateAPIusing the rest Private API as prefix: {@link /alfresco/api/-default-/private/alfresco/versions/1}
-
onResponse
public RestResponse onResponse()
-
processModelWithoutEntryObject
public <T> T processModelWithoutEntryObject(java.lang.Class<T> classz, RestRequest restRequest) throws EmptyJsonResponseException, JsonToModelConversionExceptionProcess responses for a single model asRestSyncSetRequestModelNotice thatRestSyncSetRequestModeldoesn'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()
-
-