Search in sources :

Example 11 with HttpResponse

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);
}
Also used : HttpClientResponseException(io.micronaut.http.client.exceptions.HttpClientResponseException) MultipartBody(io.micronaut.http.client.multipart.MultipartBody) HttpResponse(io.micronaut.http.HttpResponse) Map(java.util.Map) Test(org.junit.Test)

Example 12 with HttpResponse

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());
}
Also used : MultipartBody(io.micronaut.http.client.multipart.MultipartBody) HttpResponse(io.micronaut.http.HttpResponse) Test(org.junit.Test)

Example 13 with HttpResponse

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());
}
Also used : HttpClientResponseException(io.micronaut.http.client.exceptions.HttpClientResponseException) HttpResponse(io.micronaut.http.HttpResponse) Map(java.util.Map) Test(org.junit.Test)

Example 14 with HttpResponse

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());
}
Also used : HashMap(java.util.HashMap) HttpResponse(io.micronaut.http.HttpResponse) UriTemplate(io.micronaut.http.uri.UriTemplate) Test(org.junit.Test)

Example 15 with HttpResponse

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"));
}
Also used : HttpResponse(io.micronaut.http.HttpResponse) Test(org.junit.Test)

Aggregations

HttpResponse (io.micronaut.http.HttpResponse)36 Test (org.junit.Test)18 MultipartBody (io.micronaut.http.client.multipart.MultipartBody)11 Map (java.util.Map)10 HttpClientResponseException (io.micronaut.http.client.exceptions.HttpClientResponseException)9 Test (org.junit.jupiter.api.Test)9 Nullable (io.micronaut.core.annotation.Nullable)6 HttpClient (io.micronaut.http.client.HttpClient)6 MemberProfile (com.objectcomputing.checkins.services.memberprofile.MemberProfile)5 MediaType (io.micronaut.http.MediaType)5 MutableHttpResponse (io.micronaut.http.MutableHttpResponse)5 EmbeddedServer (io.micronaut.runtime.server.EmbeddedServer)5 List (java.util.List)5 IOException (java.io.IOException)4 Publisher (org.reactivestreams.Publisher)4 Flux (reactor.core.publisher.Flux)4 Internal (io.micronaut.core.annotation.Internal)3 HttpRequest (io.micronaut.http.HttpRequest)3 URI (java.net.URI)3 Publishers (io.micronaut.core.async.publisher.Publishers)2