[JAVA-9347] Split spring-rest-http module
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
## Spring REST HTTP 2
|
||||
|
||||
This module contains articles about HTTP in REST APIs with Spring
|
||||
This module contains articles about HTTP in REST APIs with Spring.
|
||||
|
||||
### The Course
|
||||
The "REST With Spring 2" Classes: http://bit.ly/restwithspring
|
||||
@@ -10,3 +10,5 @@ The "REST With Spring 2" Classes: http://bit.ly/restwithspring
|
||||
- [How to Turn Off Swagger-ui in Production](https://www.baeldung.com/swagger-ui-turn-off-in-production)
|
||||
- [Setting a Request Timeout for a Spring REST API](https://www.baeldung.com/spring-rest-timeout)
|
||||
- [Long Polling in Spring MVC](https://www.baeldung.com/spring-mvc-long-polling)
|
||||
- [Guide to UriComponentsBuilder in Spring](https://www.baeldung.com/spring-uricomponentsbuilder)
|
||||
- More articles: [[<-- prev]](../spring-rest-http)
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.baeldung.uribuilder;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SpringUriBuilderUnitTest {
|
||||
|
||||
@Test
|
||||
public void constructUri() {
|
||||
UriComponents uriComponents = UriComponentsBuilder.newInstance()
|
||||
.scheme("http").host("www.baeldung.com").path("/junit-5")
|
||||
.build();
|
||||
|
||||
assertEquals("http://www.baeldung.com/junit-5", uriComponents.toUriString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructUriEncoded() {
|
||||
UriComponents uriComponents = UriComponentsBuilder.newInstance()
|
||||
.scheme("http").host("www.baeldung.com").path("/junit 5")
|
||||
.build().encode();
|
||||
|
||||
assertEquals("http://www.baeldung.com/junit%205", uriComponents.toUriString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructUriFromTemplate() {
|
||||
UriComponents uriComponents = UriComponentsBuilder.newInstance()
|
||||
.scheme("http").host("www.baeldung.com").path("/{article-name}")
|
||||
.buildAndExpand("junit-5");
|
||||
|
||||
assertEquals("http://www.baeldung.com/junit-5", uriComponents.toUriString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructUriWithQueryParameter() {
|
||||
UriComponents uriComponents = UriComponentsBuilder.newInstance()
|
||||
.scheme("http").host("www.google.com").path("/").query("q={keyword}")
|
||||
.buildAndExpand("baeldung");
|
||||
|
||||
assertEquals("http://www.google.com/?q=baeldung", uriComponents.toUriString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expandWithRegexVar() {
|
||||
String template = "/myurl/{name:[a-z]{1,5}}/show";
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString(template).build();
|
||||
uriComponents = uriComponents.expand(Collections.singletonMap("name", "test"));
|
||||
|
||||
assertEquals("/myurl/test/show", uriComponents.getPath());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user