Search in sources :

Example 51 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder 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 52 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder 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 53 with UriComponentsBuilder

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

the class MvcUriComponentsBuilderTests method fromMappingNameWithCustomBaseUrl.

@Test
public void fromMappingNameWithCustomBaseUrl() {
    initWebApplicationContext(WebConfig.class);
    UriComponentsBuilder baseUrl = UriComponentsBuilder.fromUriString("https://example.org:9999/base");
    MvcUriComponentsBuilder mvcBuilder = relativeTo(baseUrl);
    String url = mvcBuilder.withMappingName("PAC#getAddressesForCountry").arg(0, "DE").buildAndExpand(123);
    assertThat(url).isEqualTo("https://example.org:9999/base/people/123/addresses/DE");
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Test(org.junit.jupiter.api.Test)

Example 54 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder 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 55 with UriComponentsBuilder

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

the class MvcUriComponentsBuilderTests method fromMethodCallWithCustomBaseUrlViaStaticCall.

@Test
public void fromMethodCallWithCustomBaseUrlViaStaticCall() {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base");
    UriComponents uriComponents = fromMethodCall(builder, on(ControllerWithMethods.class).myMethod(null)).build();
    assertThat(uriComponents.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)

Aggregations

UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)131 Test (org.junit.Test)34 UriComponents (org.springframework.web.util.UriComponents)23 ServletUriComponentsBuilder (org.springframework.web.servlet.support.ServletUriComponentsBuilder)12 URI (java.net.URI)9 Test (org.junit.jupiter.api.Test)9 SearchRequest (org.nzbhydra.searching.searchrequests.SearchRequest)8 MvcUriComponentsBuilder (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder)8 ArrayList (java.util.ArrayList)7 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)7 List (java.util.List)6 User (com.serotonin.m2m2.vo.User)5 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 HashMap (java.util.HashMap)5 HttpEntity (org.springframework.http.HttpEntity)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)5 IOException (java.io.IOException)4 Map (java.util.Map)4