use of io.micronaut.http.client.multipart.MultipartBody in project micronaut-core by micronaut-projects.
the class UploadControllerSpec method testFileUploadOutputStream.
@Test
public void testFileUploadOutputStream() {
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/outputStream", 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.client.multipart.MultipartBody 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.client.multipart.MultipartBody 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.client.multipart.MultipartBody 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.client.multipart.MultipartBody 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);
}
Aggregations