Search in sources :

Example 51 with UriComponents

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

the class MvcUriComponentsBuilderTests method fromMethodNameWithOptionalNamedParam.

// gh-22656
@Test
public void fromMethodNameWithOptionalNamedParam() {
    UriComponents uriComponents = fromMethodName(ControllerWithMethods.class, "methodWithOptionalNamedParam", Optional.of("foo")).build();
    assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/something/optional-param-with-name?search=foo");
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.jupiter.api.Test)

Example 52 with UriComponents

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

the class MvcUriComponentsBuilderTests method fromMethodNameTwoPathVariables.

@Test
public void fromMethodNameTwoPathVariables() {
    UriComponents uriComponents = fromMethodName(ControllerWithMethods.class, "methodWithTwoPathVariables", 1, "2009-10-31").build();
    assertThat(uriComponents.getPath()).isEqualTo("/something/1/foo/2009-10-31");
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.jupiter.api.Test)

Example 53 with UriComponents

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

the class MvcUriComponentsBuilderTests method fromMethodNameTypeLevelPathVariableWithoutArgumentValue.

// SPR-11391
@Test
public void fromMethodNameTypeLevelPathVariableWithoutArgumentValue() {
    UriComponents uriComponents = fromMethodName(UserContactController.class, "showCreate", 123).build();
    assertThat(uriComponents.getPath()).isEqualTo("/user/123/contacts/create");
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.jupiter.api.Test)

Example 54 with UriComponents

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

the class MvcUriComponentsBuilderTests method fromControllerWithCustomBaseUrlViaStaticCall.

@Test
public void fromControllerWithCustomBaseUrlViaStaticCall() {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base");
    UriComponents uriComponents = fromController(builder, PersonControllerImpl.class).build();
    assertThat(uriComponents.toString()).isEqualTo("https://example.org:9090/base/people");
    assertThat(builder.toUriString()).isEqualTo("https://example.org:9090/base");
}
Also used : UriComponents(org.springframework.web.util.UriComponents) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Test(org.junit.jupiter.api.Test)

Example 55 with UriComponents

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

the class MvcUriComponentsBuilderTests method usesForwardedHostAsHostIfHeaderIsSet.

@Test
public void usesForwardedHostAsHostIfHeaderIsSet() throws Exception {
    this.request.setScheme("https");
    this.request.addHeader("X-Forwarded-Host", "somethingDifferent");
    adaptRequestFromForwardedHeaders();
    UriComponents uriComponents = fromController(PersonControllerImpl.class).build();
    assertThat(uriComponents.toUriString()).startsWith("https://somethingDifferent");
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.jupiter.api.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