Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class TestRestTemplate
- Object
- 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.
Constructors
public TestRestTemplate(String rootUri) | A client for the server at rootUri, such as http://127.0.0.1:8080. |
Methods
Inherited methods
Constructor details
TestRestTemplate
public TestRestTemplate(String rootUri)A client for the server at
rootUri, such as http://127.0.0.1:8080.Method details
getRootUri
public String getRootUri()withBasicAuth
public TestRestTemplate withBasicAuth(String username, String password)This client, sending HTTP Basic credentials with every request.
getForEntity
public <T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Object... uriVariables)
throws IOExceptionThrows
getForObject
public <T> T getForObject(String url, Class<T> responseType, Object... uriVariables)
throws IOExceptionThrows
postForEntity
public <T> ResponseEntity<T> postForEntity(String url, Object request, Class<T> responseType, Object... uriVariables)
throws IOExceptionThrows
postForObject
public <T> T postForObject(String url, Object request, Class<T> responseType, Object... uriVariables)
throws IOExceptionThrows
put
public void put(String url, Object request, Object... uriVariables)
throws IOExceptionThrows
delete
public void delete(String url, Object... uriVariables)
throws IOExceptionThrows
exchange
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables)
throws IOExceptionSends any method with any body and headers.