Skip to content

Commit

Permalink
#1152 - Allow adding path segments to links created via WebFluxLinkBu…
Browse files Browse the repository at this point in the history
…ilder.

WebFluxLinkBuilder now allows to call ….slash(…) in symmetry to other LinkBuilder implementations.
  • Loading branch information
odrotbohm committed Dec 9, 2019
1 parent 8e96eaf commit 26c44dc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ public static class WebFluxBuilder {

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}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void linkToRouteWithExplictExchangeBeingNullShouldFallbackToRelativeUris() {
});
}

@Test
@Test // #1150
void considersContextPath() {

MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost:8080/context/api") //
Expand All @@ -201,6 +201,19 @@ void considersContextPath() {
});
}

@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();
Expand Down

0 comments on commit 26c44dc

Please sign in to comment.