use of io.micronaut.http.HttpResponse in project micronaut-core by micronaut-projects.
the class UploadControllerSpec method testCompletedFileUploadWithNoFileNameAndNoBytes.
@Test
public void testCompletedFileUploadWithNoFileNameAndNoBytes() {
MultipartBody body = MultipartBody.builder().addPart("file", "", MediaType.APPLICATION_JSON_TYPE, new byte[0]).build();
Flux<HttpResponse<String>> flowable = Flux.from(client.exchange(HttpRequest.POST("/upload/completed", body).contentType(MediaType.MULTIPART_FORM_DATA).accept(MediaType.TEXT_PLAIN_TYPE), String.class));
HttpClientResponseException ex = Assertions.assertThrows(HttpClientResponseException.class, () -> flowable.blockFirst());
Map<String, Object> embedded = (Map<String, Object>) ex.getResponse().getBody(Map.class).get().get("_embedded");
Object message = ((Map<String, Object>) ((List) embedded.get("errors")).get(0)).get("message");
assertEquals("Required argument [CompletedFileUpload file] not specified", message);
}
use of io.micronaut.http.HttpResponse in project micronaut-core by micronaut-projects.
the class UploadControllerSpec method testCompletedFileUploadWithFilenameButNoBytes.
@Test
public void testCompletedFileUploadWithFilenameButNoBytes() {
MultipartBody body = MultipartBody.builder().addPart("file", "file.json", MediaType.APPLICATION_JSON_TYPE, new byte[0]).build();
Flux<HttpResponse<String>> flowable = Flux.from(client.exchange(HttpRequest.POST("/upload/completed", body).contentType(MediaType.MULTIPART_FORM_DATA).accept(MediaType.TEXT_PLAIN_TYPE), String.class));
HttpResponse<String> response = flowable.blockFirst();
assertEquals(HttpStatus.OK.getCode(), response.code());
assertEquals("Uploaded", response.getBody().get());
}
use of io.micronaut.http.HttpResponse in project micronaut-core by micronaut-projects.
the class UploadControllerSpec method testFileUpload.
@Test
public void testFileUpload() {
MultipartBody body = MultipartBody.builder().addPart("file", "file.json", MediaType.APPLICATION_JSON_TYPE, "{\"title\":\"Foo\"}".getBytes()).build();
Flux<HttpResponse<String>> flowable = Flux.from(client.exchange(HttpRequest.POST("/upload", body).contentType(MediaType.MULTIPART_FORM_DATA).accept(MediaType.TEXT_PLAIN_TYPE), String.class));
HttpResponse<String> response = flowable.blockFirst();
assertEquals(HttpStatus.OK.getCode(), response.code());
assertEquals("Uploaded", response.getBody().get());
}
use of io.micronaut.http.HttpResponse in project micronaut-core by micronaut-projects.
the class UploadControllerSpec method testCompletedFileUploadWithNoPart.
@Test
public void testCompletedFileUploadWithNoPart() {
MultipartBody body = MultipartBody.builder().addPart("filex", "", MediaType.APPLICATION_JSON_TYPE, new byte[0]).build();
Flux<HttpResponse<String>> flowable = Flux.from(client.exchange(HttpRequest.POST("/upload/completed", body).contentType(MediaType.MULTIPART_FORM_DATA).accept(MediaType.TEXT_PLAIN_TYPE), String.class));
HttpClientResponseException ex = Assertions.assertThrows(HttpClientResponseException.class, () -> flowable.blockFirst());
Map<String, Object> embedded = (Map<String, Object>) ex.getResponse().getBody(Map.class).get().get("_embedded");
Object message = ((Map<String, Object>) ((List) embedded.get("errors")).get(0)).get("message");
assertEquals("Required argument [CompletedFileUpload file] not specified", message);
}
use of io.micronaut.http.HttpResponse in project micronaut-core by micronaut-projects.
the class MovieTicketControllerSpec method testBindingBean.
@Test
public void testBindingBean() {
UriTemplate template = new UriTemplate("/api/movie/ticket/terminator{?minPrice,maxPrice}");
Map<String, Object> params = new HashMap<>();
params.put("minPrice", 5.0);
params.put("maxPrice", 20.0);
HttpResponse response = client.toBlocking().exchange(template.expand(params));
assertEquals(HttpStatus.OK, response.status());
}
Aggregations