Skip to content

Commit 26c44dc

Browse files
committed
#1152 - Allow adding path segments to links created via WebFluxLinkBuilder.
WebFluxLinkBuilder now allows to call ….slash(…) in symmetry to other LinkBuilder implementations.
1 parent 8e96eaf commit 26c44dc

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/main/java/org/springframework/hateoas/server/reactive/WebFluxLinkBuilder.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ public static class WebFluxBuilder {
116116

117117
private final Mono<WebFluxLinkBuilder> builder;
118118

119+
/**
120+
* Creates a new {@link WebFluxBuilder} appending the given path to the currently to be built link.
121+
*
122+
* @param path must not be {@literal null}.
123+
* @return
124+
* @since 1.1
125+
*/
126+
public WebFluxBuilder slash(String path) {
127+
128+
Assert.notNull(path, "Path must not be null!");
129+
130+
return new WebFluxBuilder(builder.map(it -> it.slash(path)));
131+
}
132+
119133
/**
120134
* Creates a new {@link WebFluxLink} for the {@link Link} with the given {@link LinkRelation}
121135
*

src/test/java/org/springframework/hateoas/server/reactive/WebFluxLinkBuilderTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void linkToRouteWithExplictExchangeBeingNullShouldFallbackToRelativeUris() {
187187
});
188188
}
189189

190-
@Test
190+
@Test // #1150
191191
void considersContextPath() {
192192

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

204+
@Test // #1152
205+
void allowsAppendingPathSegments() {
206+
207+
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost:8080/api") //
208+
.build();
209+
210+
WebFluxLink link = linkTo(methodOn(TestController.class).deep()).slash("foo").withSelfRel();
211+
212+
verify(request, link, result -> {
213+
assertThat(result.getHref()).endsWith("/api/employees/foo");
214+
});
215+
}
216+
204217
private void verify(@Nullable MockServerHttpRequest request, WebFluxLink link, Consumer<Link> verifications) {
205218

206219
Mono<Link> mono = link.toMono();

0 commit comments

Comments
 (0)