Skip to content

Commit 6ce294b

Browse files
izeyeodrotbohm
authored andcommitted
#419 - Polish reference documentation.
Fixed references to constants in samples for Link. Also use endsWith(…) matcher in sample tests.
1 parent bd6cc94 commit 6ce294b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/main/asciidoc/index.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The `Link` value object follows the Atom link definition and consists of a `rel`
3030
----
3131
Link link = new Link("http://localhost:8080/something");
3232
assertThat(link.getHref(), is("http://localhost:8080/something"));
33-
assertThat(link.getRel(), is(Link.SELF));
33+
assertThat(link.getRel(), is(Link.REL_SELF));
3434
3535
Link link = new Link("http://localhost:8080/something", "my-rel");
3636
assertThat(link.getHref(), is("http://localhost:8080/something"));
@@ -88,7 +88,7 @@ You can also easily access links contained in that resource:
8888
----
8989
Link selfLink = new Link("http://myhost/people");
9090
assertThat(resource.getId(), is(selfLink));
91-
assertThat(resource.getLink(Link.SELF), is(selfLink));
91+
assertThat(resource.getLink(Link.REL_SELF), is(selfLink));
9292
----
9393
[[fundamentals.obtaining-links]]
9494
=== Obtaining links
@@ -136,7 +136,7 @@ The `ControllerLinkBuilder` uses Spring's `ServletUriComponentsBuilder` under th
136136
Person person = new Person(1L, "Dave", "Matthews");
137137
// /person / 1
138138
Link link = linkTo(PersonController.class).slash(person.getId()).withSelfRel();
139-
assertThat(link.getRel(), is(Link.SELF));
139+
assertThat(link.getRel(), is(Link.REL_SELF));
140140
assertThat(link.getHref(), endsWith("/people/1"));
141141
----
142142

@@ -169,15 +169,15 @@ As of version 0.4 you can even easily build links pointing to methods or creatin
169169
Method method = PersonController.class.getMethod("show", Long.class);
170170
Link link = linkTo(method, 2L).withSelfRel();
171171
172-
assertThat(link.getHref(), is("/people/2")));
172+
assertThat(link.getHref(), endsWith("/people/2")));
173173
----
174174

175175
This is still a bit dissatisfying as we have to get a `Method` instance first, which throws an exception and is generally quite cumbersome. At least we don't repeat the mapping. An even better approach is to have a dummy method invocation of the target method on a controller proxy we can create easily using the `methodOn(…)` helper.
176176

177177
[source, java]
178178
----
179179
Link link = linkTo(methodOn(PersonController.class).show(2L)).withSelfRel();
180-
assertThat(link.getHref(), is("/people/2")));
180+
assertThat(link.getHref(), endsWith("/people/2")));
181181
----
182182

183183
`methodOn(…)` creates a proxy of the controller class that is recording the method invocation and exposes it in a proxy created for the return type of the method. This allows the fluent expression of the method we want to obtain the mapping for. However there are a few constraints on the methods that can be obtained using this technique:

0 commit comments

Comments
 (0)