use of cn.taketoday.web.client.RestTemplate in project today-infrastructure by TAKETODAY.
the class ErrorHandlerIntegrationTests method emptyPathSegments.
@ParameterizedHttpServerTest
// SPR-15560
void emptyPathSegments(HttpServer httpServer) throws Exception {
startServer(httpServer);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER);
URI url = new URI("http://localhost:" + port + "//");
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
// Jetty 10+ rejects empty path segments, see https://github.com/eclipse/jetty.project/issues/6302,
// but an application can apply CompactPathRule via RewriteHandler:
// https://www.eclipse.org/jetty/documentation/jetty-11/programming_guide.php
HttpStatus expectedStatus = (httpServer instanceof JettyHttpServer ? HttpStatus.BAD_REQUEST : HttpStatus.OK);
assertThat(response.getStatusCode()).isEqualTo(expectedStatus);
}
use of cn.taketoday.web.client.RestTemplate in project today-infrastructure by TAKETODAY.
the class EchoHandlerIntegrationTests method echo.
@ParameterizedHttpServerTest
public void echo(HttpServer httpServer) throws Exception {
startServer(httpServer);
RestTemplate restTemplate = new RestTemplate();
byte[] body = randomBytes();
RequestEntity<byte[]> request = RequestEntity.post(new URI("http://localhost:" + port)).body(body);
ResponseEntity<byte[]> response = restTemplate.exchange(request, byte[].class);
assertThat(response.getBody()).isEqualTo(body);
}
use of cn.taketoday.web.client.RestTemplate in project today-infrastructure by TAKETODAY.
the class RandomHandlerIntegrationTests method random.
@ParameterizedHttpServerTest
void random(HttpServer httpServer) throws Exception {
startServer(httpServer);
// TODO: fix Reactor support
RestTemplate restTemplate = new RestTemplate();
byte[] body = randomBytes();
RequestEntity<byte[]> request = RequestEntity.post(new URI("http://localhost:" + port)).body(body);
ResponseEntity<byte[]> response = restTemplate.exchange(request, byte[].class);
assertThat(response.getBody()).isNotNull();
assertThat(response.getHeaders().getContentLength()).isEqualTo(RESPONSE_SIZE);
assertThat(response.getBody().length).isEqualTo(RESPONSE_SIZE);
}
use of cn.taketoday.web.client.RestTemplate in project today-infrastructure by TAKETODAY.
the class RootUriTemplateHandlerTests method applyShouldWrapExistingTemplate.
@Test
void applyShouldWrapExistingTemplate() {
given(this.delegate.expand(anyString(), any(Object[].class))).willReturn(this.uri);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setUriTemplateHandler(this.delegate);
this.handler = RootUriTemplateHandler.addTo(restTemplate, "https://example.com");
Object[] uriVariables = new Object[0];
URI expanded = this.handler.expand("/hello", uriVariables);
then(this.delegate).should().expand("https://example.com/hello", uriVariables);
assertThat(expanded).isEqualTo(this.uri);
}
use of cn.taketoday.web.client.RestTemplate in project today-infrastructure by TAKETODAY.
the class HeaderRequestMatchersIntegrationTests method setup.
@BeforeEach
public void setup() {
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new StringHttpMessageConverter());
converters.add(new MappingJackson2HttpMessageConverter());
this.restTemplate = new RestTemplate();
this.restTemplate.setMessageConverters(converters);
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
Aggregations