Class TestRestTemplate
java.lang.Object
com.codename1.backend.test.TestRestTemplate
An HTTP client for a BackendTest served on a port -- webEnvironment = RANDOM_PORT -- through the backend's own outbound client, so a compiled test
sends real requests from the native binary too.
A path is relative to the server; an absolute URL is sent as it is. A 4xx or
5xx is a response to assert on, not an exception. Bodies convert to and from
String, byte[], and Map or List as JSON.
The Java SE client behind cn1:backend cannot send PATCH (its HTTP client has
a fixed set of verbs); use MockMvc for a PATCH route, or a compiled run.
-
Constructor Summary
ConstructorsConstructorDescriptionTestRestTemplate(String rootUri) A client for the server atrootUri, such ashttp://127.0.0.1:8080. -
Method Summary
Modifier and TypeMethodDescriptionvoid<T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) Sends any method with any body and headers.<T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Object... uriVariables) <T> TgetForObject(String url, Class<T> responseType, Object... uriVariables) <T> ResponseEntity<T> postForEntity(String url, Object request, Class<T> responseType, Object... uriVariables) <T> TpostForObject(String url, Object request, Class<T> responseType, Object... uriVariables) voidwithBasicAuth(String username, String password) This client, sending HTTP Basic credentials with every request.
-
Constructor Details
-
TestRestTemplate
A client for the server atrootUri, such ashttp://127.0.0.1:8080.
-
-
Method Details
-
getRootUri
-
withBasicAuth
This client, sending HTTP Basic credentials with every request. -
getForEntity
public <T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Object... uriVariables) throws IOException - Throws:
IOException
-
getForObject
public <T> T getForObject(String url, Class<T> responseType, Object... uriVariables) throws IOException - Throws:
IOException
-
postForEntity
public <T> ResponseEntity<T> postForEntity(String url, Object request, Class<T> responseType, Object... uriVariables) throws IOException - Throws:
IOException
-
postForObject
public <T> T postForObject(String url, Object request, Class<T> responseType, Object... uriVariables) throws IOException - Throws:
IOException
-
put
- Throws:
IOException
-
delete
- Throws:
IOException
-
exchange
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) throws IOException Sends any method with any body and headers.- Throws:
IOException
-