use of io.micronaut.http.HttpResponse in project micronaut-core by micronaut-projects.
the class UploadControllerSpec method testCompletedFileUploadNoNameWithBytes.
@Test
public void testCompletedFileUploadNoNameWithBytes() {
MultipartBody body = MultipartBody.builder().addPart("file", "", MediaType.APPLICATION_JSON_TYPE, "{\"title\":\"Foo\"}".getBytes()).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 testCompletedFileUpload.
@Test
public void testCompletedFileUpload() {
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/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 PersonControllerSpec method testPersonNotFound.
@Test
public void testPersonNotFound() {
HttpClientResponseException e = Assertions.assertThrows(HttpClientResponseException.class, () -> Flux.from(client.exchange("/people/Sally", Map.class)).blockFirst());
HttpResponse<Map> response = (HttpResponse<Map>) e.getResponse();
assertEquals("Person Not Found", response.getBody().get().get("message"));
assertEquals(HttpStatus.NOT_FOUND, response.getStatus());
}
use of io.micronaut.http.HttpResponse in project micronaut-core by micronaut-projects.
the class BookmarkControllerSpec method testBindingPagination.
@Test
public void testBindingPagination() {
UriTemplate template = new UriTemplate("/api/bookmarks/list{?offset,max,sort,order}");
Map<String, Object> params = new HashMap<>();
params.put("offset", 0);
params.put("max", 10);
HttpResponse response = client.toBlocking().exchange(template.expand(params));
assertEquals(HttpStatus.OK, response.status());
}
use of io.micronaut.http.HttpResponse in project micronaut-core by micronaut-projects.
the class TraceFilterSpec method testTraceFilter.
@Test
public void testTraceFilter() {
HttpResponse response = client.toBlocking().exchange(HttpRequest.GET("/hello"));
assertEquals("true", response.getHeaders().get("X-Trace-Enabled"));
}
Aggregations