Search in sources :

Example 56 with UriComponents

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

the class MvcUriComponentsBuilderTests method fromMethodCallWithCustomBaseUrlViaInstance.

@Test
public void fromMethodCallWithCustomBaseUrlViaInstance() {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base");
    MvcUriComponentsBuilder mvcBuilder = relativeTo(builder);
    UriComponents result = mvcBuilder.withMethodCall(on(ControllerWithMethods.class).myMethod(null)).build();
    assertThat(result.toString()).isEqualTo("https://example.org:9090/base/something/else");
    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 57 with UriComponents

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

the class MvcUriComponentsBuilderTests method fromMethodNamePathVariable.

@Test
public void fromMethodNamePathVariable() {
    UriComponents uriComponents = fromMethodName(ControllerWithMethods.class, "methodWithPathVariable", "1").build();
    assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/something/1/foo");
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.jupiter.api.Test)

Example 58 with UriComponents

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

the class MvcUriComponentsBuilderTests method fromControllerPlain.

@Test
public void fromControllerPlain() {
    UriComponents uriComponents = fromController(PersonControllerImpl.class).build();
    assertThat(uriComponents.toUriString()).endsWith("/people");
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.jupiter.api.Test)

Example 59 with UriComponents

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

the class MvcUriComponentsBuilderTests method fromMethodNameWithCustomBaseUrlViaInstance.

@Test
public void fromMethodNameWithCustomBaseUrlViaInstance() {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base");
    MvcUriComponentsBuilder mvcBuilder = relativeTo(builder);
    UriComponents uriComponents = mvcBuilder.withMethodName(ControllerWithMethods.class, "methodWithPathVariable", "1").build();
    assertThat(uriComponents.toString()).isEqualTo("https://example.org:9090/base/something/1/foo");
    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 60 with UriComponents

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

the class MvcUriComponentsBuilderTests method fromMethodCallOnSubclass.

@Test
public void fromMethodCallOnSubclass() {
    UriComponents uriComponents = fromMethodCall(on(ExtendedController.class).myMethod(null)).build();
    assertThat(uriComponents.toUriString()).startsWith("http://localhost");
    assertThat(uriComponents.toUriString()).endsWith("/extended/else");
}
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