/** * WebLinkingResponse can follow a link. * * @throws Exception If something goes wrong inside */ @Test public void followsLinksInHeaders() throws Exception { final WebLinkingResponse response = new WebLinkingResponse( new FakeRequest() .withHeader("Link", "</a>; rel=\"first\", <http://localhost/o>; rel=\"second\"") .uri() .set(new URI("http://localhost/test")) .back() .fetch()); MatcherAssert.assertThat( response.follow("first").uri().get(), Matchers.equalTo(new URI("http://localhost/a"))); MatcherAssert.assertThat( response.follow("second").uri().get(), Matchers.equalTo(new URI("http://localhost/o"))); }
/** * WebLinkingResponse can recognize Links in headers. * * @throws Exception If something goes wrong inside */ @Test @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public void parsesLinksInHeaders() throws Exception { final String[] headers = { "</hey/foo>; title=\"Hi!\"; rel=foo", "</hey/foo>; title=\"\u20ac\"; rel=\"foo\"; media=\"text/xml\"", }; for (final String header : headers) { final WebLinkingResponse response = new WebLinkingResponse(new FakeRequest().withHeader("Link", header).fetch()); final WebLinkingResponse.Link link = response.links().get("foo"); MatcherAssert.assertThat(link.uri(), Matchers.hasToString("/hey/foo")); MatcherAssert.assertThat(link, Matchers.hasKey("title")); MatcherAssert.assertThat(response.links(), Matchers.not(Matchers.hasKey("something else"))); } }