List of usage examples for org.springframework.hateoas Link Link
public Link(UriTemplate template, LinkRelation rel)
From source file:org.springframework.hateoas.hal.Jackson2HalIntegrationTest.java
/** * @see #137//w w w. j a va 2 s . c o m */ @Test public void rendersTemplate() throws Exception { ResourceSupport support = new ResourceSupport(); support.add(new Link("/foo{?bar}", "search")); assertThat(write(support), is(LINK_TEMPLATE)); }
From source file:org.springframework.hateoas.hal.Jackson2HalIntegrationTest.java
/** * @see #142/*from w w w . j a va2s .c o m*/ */ @Test public void rendersMultipleCuries() throws Exception { Resources<Object> resources = new Resources<Object>(Collections.emptySet()); resources.add(new Link("foo", "myrel")); CurieProvider provider = new DefaultCurieProvider("default", new UriTemplate("/doc{?rel}")) { @Override public Collection<? extends Object> getCurieInformation(Links links) { return Arrays.asList(new Curie("foo", "bar"), new Curie("bar", "foo")); } }; assertThat(getCuriedObjectMapper(provider).writeValueAsString(resources), is(MULTIPLE_CURIES_DOCUMENT)); }
From source file:org.springframework.hateoas.Link.java
/** * Turns the current template into a {@link Link} by expanding it using the given parameters. * * @param arguments/*from ww w. j a v a 2s . c o m*/ * @return */ public Link expand(Object... arguments) { return new Link(getUriTemplate().expand(arguments).toString(), getRel()); }
From source file:org.springframework.hateoas.Link.java
/** * Turns the current template into a {@link Link} by expanding it using the given parameters. * * @param arguments must not be {@literal null}. * @return/*from w ww . ja va2 s . co m*/ */ public Link expand(Map<String, ? extends Object> arguments) { return new Link(getUriTemplate().expand(arguments).toString(), getRel()); }
From source file:org.springframework.hateoas.Link.java
/** * Factory method to easily create {@link Link} instances from RFC-5988 compatible {@link String} representations of a * link. Will return {@literal null} if an empty or {@literal null} {@link String} is given. * * @param element an RFC-5899 compatible representation of a link. * @throws IllegalArgumentException if a non-empty {@link String} was given that does not adhere to RFC-5899. * @throws IllegalArgumentException if no {@code rel} attribute could be found. * @return// w w w.j a v a 2 s. c o m */ public static Link valueOf(String element) { if (!StringUtils.hasText(element)) { return null; } Pattern uriAndAttributes = Pattern.compile("<(.*)>;(.*)"); Matcher matcher = uriAndAttributes.matcher(element); if (matcher.find()) { Map<String, String> attributes = getAttributeMap(matcher.group(2)); if (!attributes.containsKey("rel")) { throw new IllegalArgumentException("Link does not provide a rel attribute!"); } return new Link(matcher.group(1), attributes.get("rel")); } else { throw new IllegalArgumentException( String.format("Given link header %s is not RFC5988 compliant!", element)); } }
From source file:org.springframework.hateoas.LinkUnitTest.java
@Test public void createsLinkFromRelAndHref() { Link link = new Link("foo", Link.REL_SELF); assertThat(link.getHref(), is("foo")); assertThat(link.getRel(), is(Link.REL_SELF)); }
From source file:org.springframework.hateoas.LinkUnitTest.java
@Test(expected = IllegalArgumentException.class) public void rejectsNullRel() { new Link("foo", null); }
From source file:org.springframework.hateoas.LinkUnitTest.java
@Test(expected = IllegalArgumentException.class) public void rejectsEmptyRel() { new Link("foo", ""); }
From source file:org.springframework.hateoas.LinkUnitTest.java
@Test public void sameRelAndHrefMakeSameLink() { Link left = new Link("foo", Link.REL_SELF); Link right = new Link("foo", Link.REL_SELF); TestUtils.assertEqualAndSameHashCode(left, right); }
From source file:org.springframework.hateoas.LinkUnitTest.java
@Test public void differentRelMakesDifferentLink() { Link left = new Link("foo", Link.REL_PREVIOUS); Link right = new Link("foo", Link.REL_NEXT); TestUtils.assertNotEqualAndDifferentHashCode(left, right); }