Search in sources :

Example 6 with UriComponents

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

the class MvcUriComponentsBuilderTests method testFromMethodNamePathVariable.

@Test
public void testFromMethodNamePathVariable() throws Exception {
    UriComponents uriComponents = fromMethodName(ControllerWithMethods.class, "methodWithPathVariable", new Object[] { "1" }).build();
    assertThat(uriComponents.toUriString(), is("http://localhost/something/1/foo"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Example 7 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() {
    this.request.addHeader("X-Forwarded-Host", "somethingDifferent");
    UriComponents uriComponents = fromController(PersonControllerImpl.class).build();
    assertThat(uriComponents.toUriString(), startsWith("http://somethingDifferent"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Example 8 with UriComponents

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

the class MvcUriComponentsBuilderTests method testFromControllerNotMapped.

@Test
public void testFromControllerNotMapped() {
    UriComponents uriComponents = fromController(UnmappedController.class).build();
    assertThat(uriComponents.toUriString(), is("http://localhost/"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Example 9 with UriComponents

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

the class MvcUriComponentsBuilderTests method testFromMethodNameWithCustomBaseUrlViaInstance.

@Test
public void testFromMethodNameWithCustomBaseUrlViaInstance() throws Exception {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://example.org:9090/base");
    MvcUriComponentsBuilder mvcBuilder = MvcUriComponentsBuilder.relativeTo(builder);
    UriComponents uriComponents = mvcBuilder.withMethodName(ControllerWithMethods.class, "methodWithPathVariable", new Object[] { "1" }).build();
    assertEquals("http://example.org:9090/base/something/1/foo", uriComponents.toString());
    assertEquals("http://example.org:9090/base", builder.toUriString());
}
Also used : UriComponents(org.springframework.web.util.UriComponents) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) MvcUriComponentsBuilder(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder) MvcUriComponentsBuilder(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder) Test(org.junit.Test)

Example 10 with UriComponents

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

the class MvcUriComponentsBuilderTests method fromMethodNameWithBridgedMethod.

// SPR-12977
@Test
public void fromMethodNameWithBridgedMethod() throws Exception {
    UriComponents uriComponents = fromMethodName(PersonCrudController.class, "get", (long) 42).build();
    assertThat(uriComponents.toUriString(), is("http://localhost/42"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Aggregations

UriComponents (org.springframework.web.util.UriComponents)47 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 InsufficientAuthenticationException (org.springframework.security.authentication.InsufficientAuthenticationException)2 AuthenticationException (org.springframework.security.core.AuthenticationException)2 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.MockHttpServletRequest)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1