Package fr.gouv.vitam.common.client
Class VitamRestTestClient
java.lang.Object
fr.gouv.vitam.common.client.DefaultClient
fr.gouv.vitam.common.client.VitamRestTestClient
- All Implemented Interfaces:
BasicClient,MockOrRestClient,VitamAutoCloseable,AutoCloseable
Vitam Restassured like client for Junit test
Example:
GET http://host:port/service/v1/resource/path1/monid1/path2/monid2
Header: X-Request-Id = abcd
Body = Json(body)
Expected: OK
int statusCode = testClient.given().accept(MediaType.APPLICATION_JSON_TYPE)
.addHeader("X-Request-Id", "abcd")
.addPathParameter("path1", "monid1").addPathParameter("path2", "monid2")
.body(body, MediaType.APPLICATION_JSON_TYPE)
.status(Status.OK).get("resource");
POST http://host:port/service/v1/resource/path1/monid1/path2/monid2
Header: X-Request-Id = abcd
Body = Json(body)
Expected: OK + Body: InputStream
InputStream stream = testClient.given().accept(MediaType.APPLICATION_OCTET_STREAM_TYPE)
.addHeader("X-Request-Id", "abcd")
.addPathParameter("path1", "monid1").addPathParameter("path2", "monid2")
.body(body, MediaType.APPLICATION_JSON_TYPE)
.status(Status.OK).get("resource", InputStream.class);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classVItam Rest Test: mimic of Restassured.RequestSpecification -
Field Summary
Fields inherited from interface fr.gouv.vitam.common.client.BasicClient
STATUS_URL -
Constructor Summary
ConstructorsConstructorDescriptionVitamRestTestClient(VitamClientFactoryInterface<?> factory) Constructor using given scheme (http) and allowing multipart but no chunk -
Method Summary
Modifier and TypeMethodDescriptionvoidCheck the status from the servicevoidcheckStatus(javax.ws.rs.core.MultivaluedHashMap<String, Object> headers) Check the status from the service used to passe "X-SSL-CLIENT-CERT" header that contain a pem certificatevoidclose()Close the underneath http clientfinal voidconsumeAnyEntityAndClose(javax.ws.rs.core.Response response) Helper when an error occurs on client usage side to consume response howeverjavax.ws.rs.client.Clientjavax.ws.rs.client.ClientGet the resource path of the server.Get the service URLgiven()javax.ws.rs.core.Responsemake(VitamRequestBuilder request) javax.ws.rs.core.ResponsemakeSpecifyingUrl(VitamRequestBuilder request) static voidstaticConsumeAnyEntityAndClose(javax.ws.rs.core.Response response) This method consume everything (in particular InputStream) and close the response.toString()
-
Constructor Details
-
VitamRestTestClient
Constructor using given scheme (http) and allowing multipart but no chunk- Parameters:
factory- The client factory
-
-
Method Details
-
given
- Returns:
- a VitamRestTest using this client
-
staticConsumeAnyEntityAndClose
public static void staticConsumeAnyEntityAndClose(javax.ws.rs.core.Response response) This method consume everything (in particular InputStream) and close the response.- Parameters:
response-
-
consumeAnyEntityAndClose
public final void consumeAnyEntityAndClose(javax.ws.rs.core.Response response) Description copied from interface:MockOrRestClientHelper when an error occurs on client usage side to consume response however- Specified by:
consumeAnyEntityAndClosein interfaceMockOrRestClient
-
checkStatus
Description copied from interface:MockOrRestClientCheck the status from the service- Specified by:
checkStatusin interfaceMockOrRestClient- Throws:
VitamApplicationServerException- if the Server is unavailable
-
checkStatus
public void checkStatus(javax.ws.rs.core.MultivaluedHashMap<String, Object> headers) throws VitamApplicationServerExceptionDescription copied from interface:MockOrRestClientCheck the status from the service used to passe "X-SSL-CLIENT-CERT" header that contain a pem certificate- Specified by:
checkStatusin interfaceMockOrRestClient- Throws:
VitamApplicationServerException- if the Server is unavailable
-
getResourcePath
Description copied from interface:MockOrRestClientGet the resource path of the server.- Specified by:
getResourcePathin interfaceMockOrRestClient- Returns:
- the resource path as string
-
getServiceUrl
Description copied from interface:MockOrRestClientGet the service URL- Specified by:
getServiceUrlin interfaceMockOrRestClient- Returns:
- the service URL
-
close
public void close()Description copied from interface:MockOrRestClientClose the underneath http client- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceMockOrRestClient- Specified by:
closein interfaceVitamAutoCloseable
-
toString
-
makeSpecifyingUrl
public javax.ws.rs.core.Response makeSpecifyingUrl(VitamRequestBuilder request) throws VitamClientInternalException - Throws:
VitamClientInternalException
-
make
public javax.ws.rs.core.Response make(VitamRequestBuilder request) throws VitamClientInternalException - Throws:
VitamClientInternalException
-
getClientFactory
-
getClient
public javax.ws.rs.client.Client getClient() -
getChunkedClient
public javax.ws.rs.client.Client getChunkedClient()
-