Search in sources :

Example 76 with HttpStatus

use of org.springframework.http.HttpStatus in project spring-framework by spring-projects.

the class RestTemplateTests method varArgsNullTemplateVariable.

@Test
public void varArgsNullTemplateVariable() throws Exception {
    given(requestFactory.createRequest(new URI("http://example.com/-foo"), HttpMethod.GET)).willReturn(request);
    given(request.execute()).willReturn(response);
    given(errorHandler.hasError(response)).willReturn(false);
    HttpStatus status = HttpStatus.OK;
    given(response.getStatusCode()).willReturn(status);
    given(response.getStatusText()).willReturn(status.getReasonPhrase());
    template.execute("http://example.com/{first}-{last}", HttpMethod.GET, null, null, null, "foo");
    verify(response).close();
}
Also used : HttpStatus(org.springframework.http.HttpStatus) URI(java.net.URI) Test(org.junit.Test)

Example 77 with HttpStatus

use of org.springframework.http.HttpStatus in project spring-framework by spring-projects.

the class RestTemplateTests method put.

@Test
public void put() throws Exception {
    given(converter.canWrite(String.class, null)).willReturn(true);
    given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.PUT)).willReturn(request);
    String helloWorld = "Hello World";
    converter.write(helloWorld, null, request);
    given(request.execute()).willReturn(response);
    given(errorHandler.hasError(response)).willReturn(false);
    HttpStatus status = HttpStatus.OK;
    given(response.getStatusCode()).willReturn(status);
    given(response.getStatusText()).willReturn(status.getReasonPhrase());
    template.put("http://example.com", helloWorld);
    verify(response).close();
}
Also used : HttpStatus(org.springframework.http.HttpStatus) URI(java.net.URI) Test(org.junit.Test)

Example 78 with HttpStatus

use of org.springframework.http.HttpStatus in project spring-framework by spring-projects.

the class RestTemplateTests method uriTemplateWithTrailingSlash.

// SPR-15201
@Test
public void uriTemplateWithTrailingSlash() throws Exception {
    String url = "http://example.com/spring/";
    given(requestFactory.createRequest(new URI(url), HttpMethod.GET)).willReturn(request);
    given(request.execute()).willReturn(response);
    given(errorHandler.hasError(response)).willReturn(false);
    HttpStatus status = HttpStatus.OK;
    given(response.getStatusCode()).willReturn(status);
    given(response.getStatusText()).willReturn(status.getReasonPhrase());
    template.execute(url, HttpMethod.GET, null, null);
    verify(response).close();
}
Also used : HttpStatus(org.springframework.http.HttpStatus) URI(java.net.URI) Test(org.junit.Test)

Example 79 with HttpStatus

use of org.springframework.http.HttpStatus in project spring-framework by spring-projects.

the class RestTemplateTests method mapTemplateVariables.

@Test
public void mapTemplateVariables() throws Exception {
    given(requestFactory.createRequest(new URI("http://example.com/hotels/42/bookings/42"), HttpMethod.GET)).willReturn(request);
    given(request.execute()).willReturn(response);
    given(errorHandler.hasError(response)).willReturn(false);
    HttpStatus status = HttpStatus.OK;
    given(response.getStatusCode()).willReturn(status);
    given(response.getStatusText()).willReturn(status.getReasonPhrase());
    Map<String, String> vars = Collections.singletonMap("hotel", "42");
    template.execute("http://example.com/hotels/{hotel}/bookings/{hotel}", HttpMethod.GET, null, null, vars);
    verify(response).close();
}
Also used : HttpStatus(org.springframework.http.HttpStatus) URI(java.net.URI) Test(org.junit.Test)

Example 80 with HttpStatus

use of org.springframework.http.HttpStatus in project spring-framework by spring-projects.

the class RestTemplateTests method varArgsTemplateVariables.

@Test
public void varArgsTemplateVariables() throws Exception {
    given(requestFactory.createRequest(new URI("http://example.com/hotels/42/bookings/21"), HttpMethod.GET)).willReturn(request);
    given(request.execute()).willReturn(response);
    given(errorHandler.hasError(response)).willReturn(false);
    HttpStatus status = HttpStatus.OK;
    given(response.getStatusCode()).willReturn(status);
    given(response.getStatusText()).willReturn(status.getReasonPhrase());
    template.execute("http://example.com/hotels/{hotel}/bookings/{booking}", HttpMethod.GET, null, null, "42", "21");
    verify(response).close();
}
Also used : HttpStatus(org.springframework.http.HttpStatus) URI(java.net.URI) Test(org.junit.Test)

Aggregations

HttpStatus (org.springframework.http.HttpStatus)165 ResponseEntity (org.springframework.http.ResponseEntity)43 HttpHeaders (org.springframework.http.HttpHeaders)38 Test (org.junit.jupiter.api.Test)26 MediaType (org.springframework.http.MediaType)17 Mono (reactor.core.publisher.Mono)17 IOException (java.io.IOException)16 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)15 Collections (java.util.Collections)13 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 URI (java.net.URI)12 List (java.util.List)11 Optional (java.util.Optional)11 Test (org.junit.Test)11 Map (java.util.Map)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 ClassPathResource (org.springframework.core.io.ClassPathResource)9 Resource (org.springframework.core.io.Resource)9 HashMap (java.util.HashMap)8