Package org.springframework.hateoas

Examples of org.springframework.hateoas.Link


  }

  @Test
  public void usesCustomLinkProvided() {

    Link link = new Link("http://foo:9090", "rel");

    PagedResourcesAssembler<Person> assembler = new PagedResourcesAssembler<Person>(resolver, null);
    PagedResources<Resource<Person>> resources = assembler.toResource(createPage(1), link);

    assertThat(resources.getLink(Link.REL_PREVIOUS).getHref(), startsWith(link.getHref()));
    assertThat(resources.getLink(Link.REL_SELF), is(notNullValue()));
    assertThat(resources.getLink(Link.REL_NEXT).getHref(), startsWith(link.getHref()));
  }
View Full Code Here


  public void addsSelfLinkWithPaginationTemplateVariables() {

    PagedResourcesAssembler<Person> assembler = new PagedResourcesAssembler<Person>(resolver, null);
    PagedResources<Resource<Person>> resources = assembler.toResource(createPage(1));

    Link selfLink = resources.getLink(Link.REL_SELF);
    assertThat(selfLink.getHref(), endsWith("{?page,size,sort}"));
  }
View Full Code Here

  @Test
  public void appendsMissingTemplateParametersToLink() {

    PagedResourcesAssembler<Person> assembler = new PagedResourcesAssembler<Person>(resolver, null);

    Link link = new Link("/foo?page=0");
    assertThat(assembler.appendPaginationParameterTemplates(link), is(new Link("/foo?page=0{&size,sort}")));
  }
View Full Code Here

  @Test
  public void keepsExistingTemplateVariablesFromBaseLink() {

    PagedResourcesAssembler<Person> assembler = new PagedResourcesAssembler<Person>(resolver, null);

    Link link = new Link("/foo?page=0{&projection}");
    Link result = assembler.appendPaginationParameterTemplates(link);

    assertThat(result.getVariableNames(), hasSize(3));
    assertThat(result.getVariableNames(), hasItems("projection", "size", "sort"));
  }
View Full Code Here

  static class LinkedPageAdapter extends PageAdapter {

    @Override
    protected List<Link> getLinks(Page<?> source) {
      return Arrays.asList(new Link(Link.REL_NEXT, "next"), new Link(Link.REL_PREVIOUS, "previous"));
    }
View Full Code Here

   * (non-Javadoc)
   * @see org.springframework.hateoas.LinkBuilder#withRel(java.lang.String)
   */
  @Override
  public Link withRel(String rel) {
    return new Link(this.toString(), rel);
  }
View Full Code Here

   * (non-Javadoc)
   * @see org.springframework.hateoas.LinkBuilder#withSelfRel()
   */
  @Override
  public Link withSelfRel() {
    return new Link(this.toString());
  }
View Full Code Here

  }

  @Override
  public Resource<Movie> toResource(Movie movie) {
    Assert.notNull(movie);
    Link selfLink = linkBuilderFactory.linkTo(AbstractMovieController.class)
        .slash(movie.getId())
        .withRel(Relation.SELF.getName());
    Link moviesLink = linkBuilderFactory.linkTo(AbstractMovieController.class)
        .withRel(Relation.MOVIES.getName());
    Link deleteLink = linkBuilderFactory.linkTo(AbstractMovieController.class)
        .slash(movie.getId())
        .withRel(Relation.DELETE.getName());
    Link editLink = linkBuilderFactory.linkTo(AbstractMovieController.class)
        .slash(movie.getId())
        .slash(PathFragment.EDIT.getName())
        .withRel(Relation.EDIT.getName());
    Link commentsLink = linkBuilderFactory.linkTo(AbstractMovieController.class)
        .slash(movie.getId())
        .slash(PathFragment.COMMENTS.getName())
        .withRel(Relation.COMMENTS.getName());
    Link tagsLink = linkBuilderFactory.linkTo(AbstractMovieController.class)
        .slash(movie.getId())
        .slash(PathFragment.TAGS.getName())
        .withRel(Relation.TAGS.getName());
    return new Resource<Movie>(movie, selfLink, moviesLink, deleteLink, editLink, commentsLink, tagsLink);
  }
View Full Code Here

  }

  @Override
  public Resource<Tag> toResource(Tag tag) {
    Assert.notNull(tag);
    Link searchLink = null;
    searchLink = linkBuilderFactory.linkTo(AbstractMovieController.class)
      .addRequestParam(RequestParameter.SEARCH_STRING.getName(), "tag:'"+tag.getLabel()+"'").withRel(Relation.SEARCH.getName());
    return new Resource<Tag>(tag, searchLink);
  }
View Full Code Here

  }
 
  public Resource<Tag> toResource(Tag tag, UUID movieId){
    Assert.notNull(movieId);
    Resource<Tag> resourceTag = toResource(tag);
    Link deleteTagFromMovieLink = linkBuilderFactory.linkTo(AbstractMovieController.class).slash(movieId).slash(PathFragment.TAGS.getName()).slash(tag.getLabel()).withSelfRel();
    resourceTag.add(deleteTagFromMovieLink);
    return resourceTag;
  }
View Full Code Here

TOP

Related Classes of org.springframework.hateoas.Link

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.