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);
}
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);
}
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();
}
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);
}
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);
}
Aggregations