Package org.springframework.hateoas

Examples of org.springframework.hateoas.Link


   * @see DATAREST-221
   */
  @Test
  public void returnsProjectionIfRequested() throws Exception {

    Link orders = discoverUnique("orders");

    MockHttpServletResponse response = request(orders);
    Link orderLink = assertContentLinkWithRel("self", response, true).expand();

    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(orderLink.getHref());
    String uri = builder.queryParam("projection", "summary").build().toUriString();

    response = mvc.perform(get(uri)). //
        andExpect(status().isOk()). //
        andExpect(jsonPath("$.price", is(2.5))).//
View Full Code Here


   * @see DATAREST-311
   */
  @Test
  public void onlyLinksShouldAppearWhenExecuteSearchCompact() throws Exception {

    Link peopleLink = discoverUnique("people");
    Person daenerys = new Person("Daenerys", "Targaryen");
    String daenerysString = mapper.writeValueAsString(daenerys);

    MockHttpServletResponse createdPerson = postAndGet(peopleLink, daenerysString, MediaType.APPLICATION_JSON);
    Link daenerysLink = assertHasLinkWithRel("self", createdPerson);
    assertJsonPathEquals("$.firstName", "Daenerys", createdPerson);

    Link searchLink = discoverUnique(peopleLink, "search");
    Link byFirstNameLink = discoverUnique(searchLink, "findFirstPersonByFirstName");

    MockHttpServletResponse response = request(byFirstNameLink.expand("Daenerys"),
        MediaType.parseMediaType("application/x-spring-data-compact+json"));

    String responseBody = response.getContentAsString();

    JSONArray personLinks = JsonPath.<JSONArray> read(responseBody, "$.links[?(@.rel=='person')].href");
View Full Code Here

   * @see DATAREST-317
   */
  @Test
  public void rendersExcerptProjectionsCorrectly() throws Exception {

    Link authorsLink = discoverUnique("authors");

    MockHttpServletResponse response = request(authorsLink);
    String firstAuthorPath = "$._embedded.authors[0]";

    // Has main content
    assertHasJsonPathValue(firstAuthorPath.concat(".name"), response);

    // Embeddes content of related entity but no link to it
    assertHasJsonPathValue(firstAuthorPath.concat("._embedded.books[0].title"), response);
    assertJsonPathDoesntExist(firstAuthorPath.concat("._links.books"), response);

    // Access item resource and expect link to related resource present
    String content = response.getContentAsString();
    String href = JsonPath.read(content, firstAuthorPath.concat("._links.self.href"));

    follow(new Link(href)).andExpect(hasLinkWithRel("books"));
  }
View Full Code Here

   * @see DATAREST-353
   */
  @Test
  public void returns404WhenTryingToDeleteANonExistingResource() throws Exception {

    Link authorsLink = discoverUnique("authors");

    mvc.perform(delete(authorsLink.getHref().concat("/{id}"), 4711)).//
        andExpect(status().isNotFound());
  }
View Full Code Here

   * @see DATAREST-384
   */
  @Test
  public void execturesSearchThatTakesASort() throws Exception {

    Link booksLink = discoverUnique("books");
    Link searchLink = discoverUnique(booksLink, "search");
    Link findBySortedLink = discoverUnique(searchLink, "find-by-sorted");

    // Assert sort options advertised
    assertThat(findBySortedLink.isTemplated(), is(true));
    assertThat(findBySortedLink.getVariableNames(), contains("sort"));

    // Assert results returned as specified
    follow(findBySortedLink.expand("title,desc")).//
        andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data (Second Edition)")).//
        andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data"));

    follow(findBySortedLink.expand("title,asc")).//
        andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data")).//
        andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data (Second Edition)"));
  }
View Full Code Here

    Object john = JsonPath.read(response.getContentAsString(), jsonPath);
    assertThat(john, is(notNullValue()));
    assertThat(JsonPath.read(john, "$.firstName"), is(notNullValue()));

    // Assert sibling link exposed in resource pointed to
    Link selfLink = new Link(JsonPath.<String> read(john, "$._links.self.href"));
    follow(selfLink).//
        andExpect(status().isOk()).//
        andExpect(jsonPath("$._links.siblings", is(notNullValue())));
  }
View Full Code Here

        variables = variables.concat(new TemplateVariable(metadata.getName(), VariableType.REQUEST_PARAM));
      }

      String href = builder.slash(mapping.getPath()).toString().concat(variables.toString());

      Link link = new Link(href, mapping.getRel());

      if (mapping.isPagingResource()) {
        link = assembler.appendPaginationParameterTemplates(link);
      } else if (mapping.isSortableResource()) {

        TemplateVariables sortVariable = sortResolver.getSortTemplateVariables(null, UriComponentsBuilder
            .fromUriString(link.expand().getHref()).build());
        link = new Link(new UriTemplate(link.getHref()).with(sortVariable), link.getRel());
      }

      links.add(link);
    }
View Full Code Here

    PersistentProperty<?> property = exposeProperty("property");
    List<Link> associationLinks = links.getLinksFor(property.getAssociation(), new Path("/base"));

    assertThat(associationLinks, hasSize(1));
    assertThat(associationLinks, hasItem(new Link("/base/property", "property")));
  }
View Full Code Here

  protected ResultActions follow(String href) throws Exception {
    return mvc.perform(get(href));
  }

  protected List<Link> discover(String rel) throws Exception {
    return discover(new Link("/"), rel);
  }
View Full Code Here

  }

  protected Link assertHasLinkWithRel(String rel, MockHttpServletResponse response) throws Exception {

    String content = response.getContentAsString();
    Link link = getDiscoverer(response).findLinkWithRel(rel, content);

    assertThat("Expected to find link with rel " + rel + " but found none in " + content + "!", link,
        is(notNullValue()));

    return link;
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.