#1152 - Allow adding path segments to links created via WebFluxLinkBuilder.

WebFluxLinkBuilder now allows to call ….slash(…) in symmetry to other LinkBuilder implementations.
This commit is contained in:
Oliver Drotbohm
2019-12-09 12:07:41 +01:00
parent 8e96eafb37
commit 26c44dcc98
2 changed files with 28 additions and 1 deletions

View File

@@ -116,6 +116,20 @@ public class WebFluxLinkBuilder extends TemplateVariableAwareLinkBuilderSupport<
private final Mono<WebFluxLinkBuilder> builder;
/**
* Creates a new {@link WebFluxBuilder} appending the given path to the currently to be built link.
*
* @param path must not be {@literal null}.
* @return
* @since 1.1
*/
public WebFluxBuilder slash(String path) {
Assert.notNull(path, "Path must not be null!");
return new WebFluxBuilder(builder.map(it -> it.slash(path)));
}
/**
* Creates a new {@link WebFluxLink} for the {@link Link} with the given {@link LinkRelation}
*

View File

@@ -187,7 +187,7 @@ class WebFluxLinkBuilderTest {
});
}
@Test
@Test // #1150
void considersContextPath() {
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost:8080/context/api") //
@@ -201,6 +201,19 @@ class WebFluxLinkBuilderTest {
});
}
@Test // #1152
void allowsAppendingPathSegments() {
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost:8080/api") //
.build();
WebFluxLink link = linkTo(methodOn(TestController.class).deep()).slash("foo").withSelfRel();
verify(request, link, result -> {
assertThat(result.getHref()).endsWith("/api/employees/foo");
});
}
private void verify(@Nullable MockServerHttpRequest request, WebFluxLink link, Consumer<Link> verifications) {
Mono<Link> mono = link.toMono();