public class VitamRestTestClient extends DefaultClient
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);
| Modifier and Type | Class and Description |
|---|---|
static class |
VitamRestTestClient.VitamRestTest
VItam Rest Test: mimic of Restassured.RequestSpecification
|
| Modifier and Type | Field and Description |
|---|---|
protected static String |
INTERNAL_SERVER_ERROR |
STATUS_URL| Constructor and Description |
|---|
VitamRestTestClient(VitamClientFactoryInterface<?> factory)
Constructor using given scheme (http) and allowing multipart but no chunk
|
| Modifier and Type | Method and Description |
|---|---|
void |
checkStatus()
Check the status from the service
|
void |
checkStatus(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 certificate
|
void |
close()
Close the underneath http client
|
void |
consumeAnyEntityAndClose(javax.ws.rs.core.Response response)
Helper when an error occurs on client usage side to consume response however
|
protected VitamClientException |
createExceptionFromResponse(javax.ws.rs.core.Response response)
Handle all errors and throw a VitamClientException in case the response does not contains a vitamError type
result.
|
protected javax.ws.rs.client.Client |
getClient(boolean chunked) |
String |
getResourcePath()
Get the resource path of the server.
|
String |
getServiceUrl()
Get the service URL
|
VitamClientFactory<?> |
getVitamClientFactory() |
VitamRestTestClient.VitamRestTest |
given() |
protected Future<javax.ws.rs.core.Response> |
performAsyncRequest(String httpMethod,
String path,
javax.ws.rs.core.MultivaluedHashMap<String,Object> headers,
Object body,
javax.ws.rs.core.MediaType contentType,
javax.ws.rs.core.MediaType accept)
Perform an Async HTTP request to the server with full control of action on caller
|
protected <T> Future<T> |
performAsyncRequest(String httpMethod,
String path,
javax.ws.rs.core.MultivaluedHashMap<String,Object> headers,
Object body,
javax.ws.rs.core.MediaType contentType,
javax.ws.rs.core.MediaType accept,
javax.ws.rs.client.InvocationCallback<T> callback)
Perform an Async HTTP request to the server with callback
|
protected javax.ws.rs.core.Response |
performRequest(String httpMethod,
String path,
javax.ws.rs.core.MultivaluedHashMap<String,Object> headers,
javax.ws.rs.core.MediaType accept)
Perform a HTTP request to the server for synchronous call
|
protected javax.ws.rs.core.Response |
performRequest(String httpMethod,
String path,
javax.ws.rs.core.MultivaluedHashMap<String,Object> headers,
Object body,
javax.ws.rs.core.MediaType contentType,
javax.ws.rs.core.MediaType accept)
Perform a HTTP request to the server for synchronous call
|
protected javax.ws.rs.core.Response |
performRequest(String httpMethod,
String path,
javax.ws.rs.core.MultivaluedHashMap<String,Object> headers,
Object body,
javax.ws.rs.core.MediaType contentType,
javax.ws.rs.core.MediaType accept,
boolean chunkedMode)
Perform a HTTP request to the server for synchronous call
|
static void |
staticConsumeAnyEntityAndClose(javax.ws.rs.core.Response response)
This method consume everything (in particular InpuStream) and close the response.
|
String |
toString() |
protected static final String INTERNAL_SERVER_ERROR
public VitamRestTestClient(VitamClientFactoryInterface<?> factory)
factory - The client factorypublic VitamRestTestClient.VitamRestTest given()
protected javax.ws.rs.client.Client getClient(boolean chunked)
throws IllegalStateException
IllegalStateExceptionpublic final void consumeAnyEntityAndClose(javax.ws.rs.core.Response response)
MockOrRestClientconsumeAnyEntityAndClose in interface MockOrRestClientpublic static final void staticConsumeAnyEntityAndClose(javax.ws.rs.core.Response response)
response - public void checkStatus()
throws VitamApplicationServerException
MockOrRestClientcheckStatus in interface MockOrRestClientVitamApplicationServerException - if the Server is unavailablepublic void checkStatus(javax.ws.rs.core.MultivaluedHashMap<String,Object> headers) throws VitamApplicationServerException
MockOrRestClientcheckStatus in interface MockOrRestClientVitamApplicationServerException - if the Server is unavailableprotected javax.ws.rs.core.Response performRequest(String httpMethod, String path, javax.ws.rs.core.MultivaluedHashMap<String,Object> headers, javax.ws.rs.core.MediaType accept) throws VitamClientInternalException
httpMethod - HTTP method to use for requestpath - URL to requestheaders - headers HTTP to add to request, may be nullaccept - asked type of responseVitamClientInternalExceptionprotected javax.ws.rs.core.Response performRequest(String httpMethod, String path, javax.ws.rs.core.MultivaluedHashMap<String,Object> headers, Object body, javax.ws.rs.core.MediaType contentType, javax.ws.rs.core.MediaType accept) throws VitamClientInternalException
httpMethod - HTTP method to use for requestpath - URL to requestheaders - headers HTTP to add to request, may be nullbody - body content of type contentType, may be nullcontentType - the media type of the body to send, null if body is nullaccept - asked type of responseVitamClientInternalExceptionprotected javax.ws.rs.core.Response performRequest(String httpMethod, String path, javax.ws.rs.core.MultivaluedHashMap<String,Object> headers, Object body, javax.ws.rs.core.MediaType contentType, javax.ws.rs.core.MediaType accept, boolean chunkedMode) throws VitamClientInternalException
httpMethod - HTTP method to use for requestpath - URL to requestheaders - headers HTTP to add to request, may be nullbody - body content of type contentType, may be nullcontentType - the media type of the body to send, null if body is nullaccept - asked type of responsechunkedMode - True use default client, else False use non Chunked mode clientVitamClientInternalExceptionprotected <T> Future<T> performAsyncRequest(String httpMethod, String path, javax.ws.rs.core.MultivaluedHashMap<String,Object> headers, Object body, javax.ws.rs.core.MediaType contentType, javax.ws.rs.core.MediaType accept, javax.ws.rs.client.InvocationCallback<T> callback) throws VitamClientInternalException
T - the type of the Future result (generally Response)httpMethod - HTTP method to use for requestpath - URL to requestheaders - headers HTTP to add to request, may be nullbody - body content of type contentType, may be nullcontentType - the media type of the body to send, null if body is nullaccept - asked type of responsecallback - VitamClientInternalExceptionprotected Future<javax.ws.rs.core.Response> performAsyncRequest(String httpMethod, String path, javax.ws.rs.core.MultivaluedHashMap<String,Object> headers, Object body, javax.ws.rs.core.MediaType contentType, javax.ws.rs.core.MediaType accept) throws VitamClientInternalException
httpMethod - HTTP method to use for requestpath - URL to requestheaders - headers HTTP to add to request, may be nullbody - body content of type contentType, may be nullcontentType - the media type of the body to send, null if body is nullaccept - asked type of responseVitamClientInternalExceptionprotected VitamClientException createExceptionFromResponse(javax.ws.rs.core.Response response)
response - responsepublic String getResourcePath()
MockOrRestClientgetResourcePath in interface MockOrRestClientpublic String getServiceUrl()
MockOrRestClientgetServiceUrl in interface MockOrRestClientpublic void close()
MockOrRestClientclose in interface MockOrRestClientclose in interface VitamAutoCloseableclose in interface AutoCloseablepublic VitamClientFactory<?> getVitamClientFactory()
Copyright © 2018 Vitam. All rights reserved.