use of cn.taketoday.web.client.RestTemplate in project today-infrastructure by TAKETODAY.
the class ErrorPageFilterIntegrationTests method doTest.
private void doTest(AnnotationConfigServletWebServerApplicationContext context, String resourcePath, HttpStatus status) throws Exception {
int port = context.getWebServer().getPort();
RestTemplate template = new RestTemplate();
ResponseEntity<String> entity = template.getForEntity(new URI("http://localhost:" + port + resourcePath), String.class);
assertThat(entity.getBody()).isEqualTo("Hello World");
assertThat(entity.getStatusCode()).isEqualTo(status);
}
use of cn.taketoday.web.client.RestTemplate in project today-infrastructure by TAKETODAY.
the class ServletComponentScanIntegrationTests method indexedComponentsAreRegistered.
@ParameterizedTest(name = "{0}")
@MethodSource("testConfiguration")
void indexedComponentsAreRegistered(String serverName, Class<?> configuration) throws IOException {
writeIndex(this.temp);
this.context = new AnnotationConfigServletWebServerApplicationContext();
try (URLClassLoader classLoader = new URLClassLoader(new URL[] { this.temp.toURI().toURL() }, getClass().getClassLoader())) {
this.context.setClassLoader(classLoader);
this.context.register(configuration);
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();
String port = this.context.getEnvironment().getProperty("local.server.port");
String response = new RestTemplate().getForObject("http://localhost:" + port + "/test", String.class);
assertThat(response).isEqualTo("alpha bravo charlie");
}
}
use of cn.taketoday.web.client.RestTemplate in project today-infrastructure by TAKETODAY.
the class TomcatServletWebServerFactoryTests method nonExistentUploadDirectoryIsCreatedUponMultipartUpload.
@Test
void nonExistentUploadDirectoryIsCreatedUponMultipartUpload() throws IOException, URISyntaxException {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0);
AtomicReference<ServletContext> servletContextReference = new AtomicReference<>();
factory.addInitializers((servletContext) -> {
servletContextReference.set(servletContext);
Dynamic servlet = servletContext.addServlet("upload", new HttpServlet() {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.getParts();
}
});
servlet.addMapping("/upload");
servlet.setMultipartConfig(new MultipartConfigElement((String) null));
});
this.webServer = factory.getWebServer();
this.webServer.start();
File temp = (File) servletContextReference.get().getAttribute(ServletContext.TEMPDIR);
FileSystemUtils.deleteRecursively(temp);
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = HttpHeaders.create();
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", new ByteArrayResource(new byte[1024 * 1024]));
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
ResponseEntity<String> response = restTemplate.postForEntity(getLocalUrl("/upload"), requestEntity, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}
use of cn.taketoday.web.client.RestTemplate in project today-infrastructure by TAKETODAY.
the class RestTemplateBuilderTests method messageConvertersShouldApply.
@Test
void messageConvertersShouldApply() {
RestTemplate template = this.builder.messageConverters(this.messageConverter).build();
assertThat(template.getMessageConverters()).containsOnly(this.messageConverter);
}
use of cn.taketoday.web.client.RestTemplate in project today-infrastructure by TAKETODAY.
the class RestTemplateBuilderTests method defaultMessageConvertersShouldClearExisting.
@Test
void defaultMessageConvertersShouldClearExisting() {
RestTemplate template = new RestTemplate(Collections.singletonList(new StringHttpMessageConverter()));
this.builder.additionalMessageConverters(this.messageConverter).defaultMessageConverters().configure(template);
assertThat(template.getMessageConverters()).hasSameSizeAs(new RestTemplate().getMessageConverters());
}
Aggregations