Search in sources :

Example 76 with UriComponents

use of org.springframework.web.util.UriComponents in project spring-framework by spring-projects.

the class MvcUriComponentsBuilderTests method testFromMethodCallWithPathVarAndRequestParams.

@Test
public void testFromMethodCallWithPathVarAndRequestParams() {
    UriComponents uriComponents = fromMethodCall(on(ControllerWithMethods.class).methodForNextPage("1", 10, 5)).build();
    assertThat(uriComponents.getPath(), is("/something/1/foo"));
    MultiValueMap<String, String> queryParams = uriComponents.getQueryParams();
    assertThat(queryParams.get("limit"), contains("5"));
    assertThat(queryParams.get("offset"), contains("10"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Example 77 with UriComponents

use of org.springframework.web.util.UriComponents in project spring-framework by spring-projects.

the class MvcUriComponentsBuilderTests method testFromMethodNameWithPathVarAndRequestParam.

@Test
public void testFromMethodNameWithPathVarAndRequestParam() throws Exception {
    UriComponents uriComponents = fromMethodName(ControllerWithMethods.class, "methodForNextPage", "1", 10, 5).build();
    assertThat(uriComponents.getPath(), is("/something/1/foo"));
    MultiValueMap<String, String> queryParams = uriComponents.getQueryParams();
    assertThat(queryParams.get("limit"), contains("5"));
    assertThat(queryParams.get("offset"), contains("10"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Example 78 with UriComponents

use of org.springframework.web.util.UriComponents in project spring-framework by spring-projects.

the class MvcUriComponentsBuilderTests method testFromMethodCallWithPathVar.

@Test
public void testFromMethodCallWithPathVar() {
    UriComponents uriComponents = fromMethodCall(on(ControllerWithMethods.class).methodWithPathVariable("1")).build();
    assertThat(uriComponents.toUriString(), startsWith("http://localhost"));
    assertThat(uriComponents.toUriString(), endsWith("/something/1/foo"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Example 79 with UriComponents

use of org.springframework.web.util.UriComponents in project spring-framework by spring-projects.

the class MvcUriComponentsBuilderTests method testFromMethodCallWithPathVarAndMultiValueRequestParams.

@Test
public void testFromMethodCallWithPathVarAndMultiValueRequestParams() {
    UriComponents uriComponents = fromMethodCall(on(ControllerWithMethods.class).methodWithMultiValueRequestParams("1", Arrays.asList(3, 7), 5)).build();
    assertThat(uriComponents.getPath(), is("/something/1/foo"));
    MultiValueMap<String, String> queryParams = uriComponents.getQueryParams();
    assertThat(queryParams.get("limit"), contains("5"));
    assertThat(queryParams.get("items"), containsInAnyOrder("3", "7"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Example 80 with UriComponents

use of org.springframework.web.util.UriComponents in project spring-framework by spring-projects.

the class MvcUriComponentsBuilderTests method testFromMethodCall.

@Test
public void testFromMethodCall() {
    UriComponents uriComponents = fromMethodCall(on(ControllerWithMethods.class).myMethod(null)).build();
    assertThat(uriComponents.toUriString(), startsWith("http://localhost"));
    assertThat(uriComponents.toUriString(), endsWith("/something/else"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Aggregations

UriComponents (org.springframework.web.util.UriComponents)133 Test (org.junit.jupiter.api.Test)43 Test (org.junit.Test)37 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)26 MvcUriComponentsBuilder (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder)7 URI (java.net.URI)5 HashMap (java.util.HashMap)5 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 MvcResult (org.springframework.test.web.servlet.MvcResult)4 ServletUriComponentsBuilder (org.springframework.web.servlet.support.ServletUriComponentsBuilder)4 MethodParameter (org.springframework.core.MethodParameter)3 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Matchers.anyString (org.mockito.Matchers.anyString)2