Search in sources :

Example 36 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 37 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 38 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 39 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 40 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)48 Test (org.junit.Test)32 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)10 MvcUriComponentsBuilder (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder)6 HttpRequest (org.springframework.http.HttpRequest)2 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 InsufficientAuthenticationException (org.springframework.security.authentication.InsufficientAuthenticationException)2 AuthenticationException (org.springframework.security.core.AuthenticationException)2 JsonParseException (com.google.gson.JsonParseException)1 URI (java.net.URI)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 MethodParameter (org.springframework.core.MethodParameter)1 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1