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
FieldsFields inherited from class org.alfresco.utility.dsl.DSLWrapper
contentService, dataContent, jmxBuilder -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionassertHeaderValueContains(String headerName, String expectedHeaderValue) Verify response header contains a specific value Example: assertHeaderValueContains("Content-Disposition", "filename=\"myfile.txt\"");assertLastExceptionContains(String exception) org.alfresco.utility.model.StatusModelassertStatusCodeIs(org.springframework.http.HttpStatus statusCode) Assert that a specific status code is returnedauthenticateUser(org.alfresco.utility.model.UserModel userModel) Authenticate specific user to Alfresco REST APIjust clear the base pathvoidJust clear the parameters sentvoidAdding new method to configure Alfresco Endpoint.io.restassured.builder.RequestSpecBuilderYou can handle the request sent to server by calling this method.voidvoidvoidio.restassured.http.ContentTypeorg.alfresco.utility.model.StatusModelGet and clear the stored parameters.io.restassured.http.Headersvoidprotected io.restassured.specification.RequestSpecificationRequest sent to serverprocess(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 itprocessHtmlResponse(RestRequest restRequest) Process a response that returns a htmlorg.json.JSONObjectprocessJson(RestRequest restRequest) Process responses for a single model asRestSiteModel<T> TprocessModel(Class<T> classz, RestRequest restRequest) Process responses for a single model asRestSiteModel<T> TprocessModels(Class<T> classz, RestRequest restRequest) Process responses for a collection of models asRestSiteModelsCollection<T> TprocessModelWithoutEntryObject(Class<T> classz, RestRequest restRequest) Process responses for a single model asRestSyncSetRequestModelNotice thatRestSyncSetRequestModeldoesn't have one "entry" field as any other rest request modelprocessRelationsJson(RestRequest restRequest) Process responses for site relations models, such as {@link RestSiteModel, RestSiteContainerModelsCollection, RestSiteMemberModelsCollection}processSitesRelationsJson(RestRequest restRequest) Process responses for site relations models, such as {@link RestSiteModel, RestSiteContainerModelsCollection, RestSiteMemberModelsCollection}processTextResponse(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(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(String serverURI) voidsetStatusCode(String statusCode) usingContentType(io.restassured.http.ContentType defaultContentType) Provides DSL on creating Tenant users<T> voidvalidateJsonModelSchema(Class<T> classz, Object classzInstance) Check that REST response has returned all required fieldsConstruct 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.Perform AOS browser binding calls ("alfresco/aos") with Rest APIPerform CMIS browser binding calls ("alfresco/api/-default-/public/cmis/versions/1.1/browser") with Rest APIwithParams(String... parameters) Send key=value parameters.Methods inherited from class org.alfresco.utility.dsl.DSLWrapper
getDataContentService, getTestUser, setTestUser
-
Field Details
-
restProperties
-
-
Constructor Details
-
RestWrapper
public RestWrapper()
-
-
Method Details
-
setServerURI
- 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
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
Authenticate specific user to Alfresco REST API- Parameters:
userModel-- Returns:
-
noAuthentication
-
onRequest
protected io.restassured.specification.RequestSpecification onRequest()Request sent to server -
setLastError
-
assertLastError
-
assertLastStatus
public org.alfresco.utility.model.StatusModel assertLastStatus() -
assertLastExceptionContains
-
processModels
public <T> T processModels(Class<T> classz, RestRequest restRequest) throws EmptyJsonResponseException, JsonToModelConversionException Process 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(Class<T> classz, 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.
-
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
Process responses for site relations models, such as {@link RestSiteModel, RestSiteContainerModelsCollection, RestSiteMemberModelsCollection} -
processSitesRelationsJson
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
Generic REST API call on aRestRequest- Parameters:
restRequest-- Returns:
-
processTextResponse
-
processEmptyModel
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
-
setStatusCode
-
sendRequest
Send REST request based on HTTP method- Parameters:
restRequest-- Returns:
-
assertStatusCodeIs
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:
IllegalAccessExceptionIllegalArgumentExceptionInvocationTargetExceptionInstantiationException
-
getParameters
Get and clear the stored parameters.- Returns:
- parameters that you could pass on the request ?param=value
-
setParameters
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
just clear the base path- Returns:
-
withParams
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
- Returns:
RestCoreAPIusing the rest Core API as prefix: {@link /alfresco/api/-default-/public/alfresco/versions/1}
-
withWorkflowAPI
- Returns:
RestWorkflowAPIusing the rest Workflow API with prefix: {@link /alfresco/api/-default-/public/workflow/versions/1 }
-
withAuthAPI
- Returns:
RestAuthAPIusing the rest Auth API with prefix: {@link /alfresco/api/-default-/public/authentication/versions/1 }
-
withModelAPI
-
withSearchAPI
-
withSearchSqlAPI
-
withSearchSqlViaJDBC
-
withShardInfoAPI
-
withSolrAPI
-
withSolrAdminAPI
-
withDiscoveryAPI
- Returns:
RestDiscoveryAPIusing the rest Discovery API as prefix: {@link /alfresco/api/discovery}
-
withAdminConsole
- Returns:
AdminConsoleusing the Admin Console API as prefix: {@link /alfresco/service/api/server}
-
usingTenant
Provides DSL on creating Tenant users- Returns:
Tenant
-
where
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
-
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
Perform CMIS browser binding calls ("alfresco/api/-default-/public/cmis/versions/1.1/browser") with Rest API- Returns:
RestCmisAPI
-
withAosAPI
Perform AOS browser binding calls ("alfresco/aos") with Rest API- Returns:
RestAosAPI
-
withPrivateAPI
- Returns:
RestPrivateAPIusing the rest Private API as prefix: {@link /alfresco/api/-default-/private/alfresco/versions/1}
-
onResponse
-
processModelWithoutEntryObject
public <T> T processModelWithoutEntryObject(Class<T> classz, RestRequest restRequest) throws EmptyJsonResponseException, JsonToModelConversionException Process 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() -
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
-