Search in sources :

Example 1 with GET

use of cn.taketoday.http.HttpMethod.GET in project today-infrastructure by TAKETODAY.

the class RequestMappingInfoTests method compareToWithImpicitVsExplicitHttpMethodDeclaration.

@Test
void compareToWithImpicitVsExplicitHttpMethodDeclaration() {
    RequestMappingInfo noMethods = RequestMappingInfo.paths().build();
    RequestMappingInfo oneMethod = RequestMappingInfo.paths().methods(GET).build();
    RequestMappingInfo oneMethodOneParam = RequestMappingInfo.paths().methods(GET).params("foo").build();
    MockHttpServletRequest request = initRequest("GET", "/", false);
    Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, new ServletRequestContext(null, request, null));
    List<RequestMappingInfo> list = asList(noMethods, oneMethod, oneMethodOneParam);
    Collections.shuffle(list);
    list.sort(comparator);
    assertThat(list.get(0)).isEqualTo(oneMethodOneParam);
    assertThat(list.get(1)).isEqualTo(oneMethod);
    assertThat(list.get(2)).isEqualTo(noMethods);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) Test(org.junit.jupiter.api.Test) HttpMethod(cn.taketoday.http.HttpMethod) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) List(java.util.List) HttpHeaders(cn.taketoday.http.HttpHeaders) Stream(java.util.stream.Stream) GET(cn.taketoday.http.HttpMethod.GET) Arrays.asList(java.util.Arrays.asList) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest) HEAD(cn.taketoday.http.HttpMethod.HEAD) PathPatternParser(cn.taketoday.web.util.pattern.PathPatternParser) Comparator(java.util.Comparator) MediaType(cn.taketoday.http.MediaType) Collections(java.util.Collections) MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) Test(org.junit.jupiter.api.Test) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest)

Example 2 with GET

use of cn.taketoday.http.HttpMethod.GET in project today-infrastructure by TAKETODAY.

the class RequestMappingInfoTests method compareToWithHttpHeadMapping.

@Test
// SPR-14383
void compareToWithHttpHeadMapping() {
    MockHttpServletRequest request = initRequest("GET", "/", false);
    request.setMethod("HEAD");
    request.addHeader("Accept", "application/json");
    RequestMappingInfo noMethods = RequestMappingInfo.paths().build();
    RequestMappingInfo getMethod = RequestMappingInfo.paths().methods(GET).produces("application/json").build();
    RequestMappingInfo headMethod = RequestMappingInfo.paths().methods(HEAD).build();
    Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, new ServletRequestContext(null, request, null));
    List<RequestMappingInfo> list = asList(noMethods, getMethod, headMethod);
    Collections.shuffle(list);
    list.sort(comparator);
    assertThat(list.get(0)).isEqualTo(headMethod);
    assertThat(list.get(1)).isEqualTo(getMethod);
    assertThat(list.get(2)).isEqualTo(noMethods);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) Test(org.junit.jupiter.api.Test) HttpMethod(cn.taketoday.http.HttpMethod) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) List(java.util.List) HttpHeaders(cn.taketoday.http.HttpHeaders) Stream(java.util.stream.Stream) GET(cn.taketoday.http.HttpMethod.GET) Arrays.asList(java.util.Arrays.asList) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest) HEAD(cn.taketoday.http.HttpMethod.HEAD) PathPatternParser(cn.taketoday.web.util.pattern.PathPatternParser) Comparator(java.util.Comparator) MediaType(cn.taketoday.http.MediaType) Collections(java.util.Collections) MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) Test(org.junit.jupiter.api.Test) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest)

Example 3 with GET

use of cn.taketoday.http.HttpMethod.GET in project today-framework by TAKETODAY.

the class DefaultClientRequestBuilderTests method build.

@Test
public void build() {
    ClientRequest result = ClientRequest.create(GET, DEFAULT_URL).header("MyKey", "MyValue").cookie("foo", "bar").httpRequest(request -> {
        MockClientHttpRequest nativeRequest = request.getNativeRequest();
        nativeRequest.getHeaders().add("MyKey2", "MyValue2");
    }).build();
    MockClientHttpRequest request = new MockClientHttpRequest(GET, "/");
    ExchangeStrategies strategies = mock(ExchangeStrategies.class);
    result.writeTo(request, strategies).block();
    assertThat(request.getHeaders().getFirst("MyKey")).isEqualTo("MyValue");
    assertThat(request.getHeaders().getFirst("MyKey2")).isEqualTo("MyValue2");
    assertThat(request.getCookies().getFirst("foo").getValue()).isEqualTo("bar");
    StepVerifier.create(request.getBody()).expectComplete().verify();
}
Also used : StepVerifier(reactor.test.StepVerifier) URISyntaxException(java.net.URISyntaxException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArrayList(java.util.ArrayList) DELETE(cn.taketoday.http.HttpMethod.DELETE) MockClientHttpRequest(cn.taketoday.http.client.reactive.MockClientHttpRequest) BDDMockito.given(org.mockito.BDDMockito.given) CharSequenceEncoder(cn.taketoday.core.codec.CharSequenceEncoder) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) DefaultDataBufferFactory(cn.taketoday.core.io.buffer.DefaultDataBufferFactory) URI(java.net.URI) TypeReference(cn.taketoday.core.TypeReference) EncoderHttpMessageWriter(cn.taketoday.http.codec.EncoderHttpMessageWriter) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Publisher(org.reactivestreams.Publisher) OPTIONS(cn.taketoday.http.HttpMethod.OPTIONS) HttpMessageWriter(cn.taketoday.http.codec.HttpMessageWriter) Mono(reactor.core.publisher.Mono) Test(org.junit.jupiter.api.Test) List(java.util.List) POST(cn.taketoday.http.HttpMethod.POST) GET(cn.taketoday.http.HttpMethod.GET) ClientHttpRequest(cn.taketoday.http.client.reactive.ClientHttpRequest) BodyInserter(cn.taketoday.web.reactive.function.BodyInserter) Mockito.mock(org.mockito.Mockito.mock) MockClientHttpRequest(cn.taketoday.http.client.reactive.MockClientHttpRequest) Test(org.junit.jupiter.api.Test)

Example 4 with GET

use of cn.taketoday.http.HttpMethod.GET in project today-framework by TAKETODAY.

the class RequestMappingInfoTests method compareToWithHttpHeadMapping.

@Test
// SPR-14383
void compareToWithHttpHeadMapping() {
    MockHttpServletRequest request = initRequest("GET", "/", false);
    request.setMethod("HEAD");
    request.addHeader("Accept", "application/json");
    RequestMappingInfo noMethods = RequestMappingInfo.paths().build();
    RequestMappingInfo getMethod = RequestMappingInfo.paths().methods(GET).produces("application/json").build();
    RequestMappingInfo headMethod = RequestMappingInfo.paths().methods(HEAD).build();
    Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, new ServletRequestContext(null, request, null));
    List<RequestMappingInfo> list = asList(noMethods, getMethod, headMethod);
    Collections.shuffle(list);
    list.sort(comparator);
    assertThat(list.get(0)).isEqualTo(headMethod);
    assertThat(list.get(1)).isEqualTo(getMethod);
    assertThat(list.get(2)).isEqualTo(noMethods);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.jupiter.api.Test) HttpMethod(cn.taketoday.http.HttpMethod) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) List(java.util.List) HttpHeaders(cn.taketoday.http.HttpHeaders) Stream(java.util.stream.Stream) MockHttpServletRequest(cn.taketoday.web.testfixture.servlet.MockHttpServletRequest) GET(cn.taketoday.http.HttpMethod.GET) Arrays.asList(java.util.Arrays.asList) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest) HEAD(cn.taketoday.http.HttpMethod.HEAD) PathPatternParser(cn.taketoday.web.util.pattern.PathPatternParser) Comparator(java.util.Comparator) MediaType(cn.taketoday.http.MediaType) Collections(java.util.Collections) MockHttpServletRequest(cn.taketoday.web.testfixture.servlet.MockHttpServletRequest) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) Test(org.junit.jupiter.api.Test) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest)

Example 5 with GET

use of cn.taketoday.http.HttpMethod.GET in project today-framework by TAKETODAY.

the class RequestMappingInfoTests method compareToWithImpicitVsExplicitHttpMethodDeclaration.

@Test
void compareToWithImpicitVsExplicitHttpMethodDeclaration() {
    RequestMappingInfo noMethods = RequestMappingInfo.paths().build();
    RequestMappingInfo oneMethod = RequestMappingInfo.paths().methods(GET).build();
    RequestMappingInfo oneMethodOneParam = RequestMappingInfo.paths().methods(GET).params("foo").build();
    MockHttpServletRequest request = initRequest("GET", "/", false);
    Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, new ServletRequestContext(null, request, null));
    List<RequestMappingInfo> list = asList(noMethods, oneMethod, oneMethodOneParam);
    Collections.shuffle(list);
    list.sort(comparator);
    assertThat(list.get(0)).isEqualTo(oneMethodOneParam);
    assertThat(list.get(1)).isEqualTo(oneMethod);
    assertThat(list.get(2)).isEqualTo(noMethods);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.jupiter.api.Test) HttpMethod(cn.taketoday.http.HttpMethod) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) List(java.util.List) HttpHeaders(cn.taketoday.http.HttpHeaders) Stream(java.util.stream.Stream) MockHttpServletRequest(cn.taketoday.web.testfixture.servlet.MockHttpServletRequest) GET(cn.taketoday.http.HttpMethod.GET) Arrays.asList(java.util.Arrays.asList) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest) HEAD(cn.taketoday.http.HttpMethod.HEAD) PathPatternParser(cn.taketoday.web.util.pattern.PathPatternParser) Comparator(java.util.Comparator) MediaType(cn.taketoday.http.MediaType) Collections(java.util.Collections) MockHttpServletRequest(cn.taketoday.web.testfixture.servlet.MockHttpServletRequest) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) Test(org.junit.jupiter.api.Test) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest)

Aggregations

GET (cn.taketoday.http.HttpMethod.GET)8 List (java.util.List)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 Test (org.junit.jupiter.api.Test)8 TypeReference (cn.taketoday.core.TypeReference)4 CharSequenceEncoder (cn.taketoday.core.codec.CharSequenceEncoder)4 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)4 DefaultDataBufferFactory (cn.taketoday.core.io.buffer.DefaultDataBufferFactory)4 HttpHeaders (cn.taketoday.http.HttpHeaders)4 HttpMethod (cn.taketoday.http.HttpMethod)4 DELETE (cn.taketoday.http.HttpMethod.DELETE)4 HEAD (cn.taketoday.http.HttpMethod.HEAD)4 OPTIONS (cn.taketoday.http.HttpMethod.OPTIONS)4 POST (cn.taketoday.http.HttpMethod.POST)4 MediaType (cn.taketoday.http.MediaType)4 ClientHttpRequest (cn.taketoday.http.client.reactive.ClientHttpRequest)4 MockClientHttpRequest (cn.taketoday.http.client.reactive.MockClientHttpRequest)4 EncoderHttpMessageWriter (cn.taketoday.http.codec.EncoderHttpMessageWriter)4 HttpMessageWriter (cn.taketoday.http.codec.HttpMessageWriter)4 BodyInserter (cn.taketoday.web.reactive.function.BodyInserter)4