Package org.springframework.hateoas

Examples of org.springframework.hateoas.Link


      String href = JsonPath.read(content, String.format(CONTENT_LINK_JSONPATH, rel)).toString();
      assertThat("Expected to find a link with rel" + rel + " in the content section of the response!", href,
          is(expected ? notNullValue() : nullValue()));

      return new Link(href, rel);

    } catch (InvalidPathException o_O) {

      if (expected) {
        fail("Didn't find any content in the given response!");
View Full Code Here


  }

  protected void assertDoesNotHaveLinkWithRel(String rel, MockHttpServletResponse response) throws Exception {

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

    assertThat("Expected not to find link with rel " + rel + " but found " + link + "!", link, is(nullValue()));
  }
View Full Code Here

    MockHttpServletResponse response = request("/");

    for (String rel : expectedRootLinkRels()) {

      Link link = assertHasLinkWithRel(rel, response);

      // Resource
      request(link);

      // Schema - TODO:Improve by using hypermedia
      mvc.perform(get(link.expand().getHref() + "/schema").//
          accept(MediaType.parseMediaType("application/schema+json"))).//
          andExpect(status().isOk());
    }
  }
View Full Code Here

    MockHttpServletResponse response = request("/");

    for (String rel : expectedRootLinkRels()) {

      Link link = assertHasLinkWithRel(rel, response);
      String rootResourceRepresentation = request(link).getContentAsString();
      Link searchLink = getDiscoverer(response).findLinkWithRel("search", rootResourceRepresentation);

      if (searchLink != null) {
        request(searchLink);
      }
    }
View Full Code Here

      String payload = payloads.get(rel);

      if (payload != null) {

        Link link = assertHasLinkWithRel(rel, response);
        String target = link.expand().getHref();

        MockHttpServletRequestBuilder request = post(target).//
            content(payload).//
            contentType(MediaType.APPLICATION_JSON);
View Full Code Here

    MockHttpServletResponse rootResource = request("/");

    for (Entry<String, List<String>> linked : getRootAndLinkedResources().entrySet()) {

      Link resourceLink = assertHasLinkWithRel(linked.getKey(), rootResource);
      MockHttpServletResponse resource = request(resourceLink);

      for (String linkedRel : linked.getValue()) {

        // Find URIs pointing to linked resources
View Full Code Here

  public void exposesDescriptionAsAlpsDocuments() throws Exception {

    MediaType ALPS_MEDIA_TYPE = MediaType.valueOf("application/alps+json");

    MockHttpServletResponse response = request("/");
    Link profileLink = assertHasLinkWithRel("profile", response);

    mvc.perform(//
        get(profileLink.expand().getHref()).//
            accept(ALPS_MEDIA_TYPE)).//
        andExpect(status().isOk()).//
        andExpect(content().contentType(ALPS_MEDIA_TYPE));
  }
View Full Code Here

    PersistentEntity<?, ?> persistentEntity = repositories.getPersistentEntity(Person.class);
    Person person = people.save(new Person("John", "Doe"));

    PersistentEntityResource resource = PersistentEntityResource.build(person, persistentEntity).//
        withLink(new Link("/person/" + person.getId())).build();

    StringWriter writer = new StringWriter();
    mapper.writeValue(writer, resource);

    String s = writer.toString();

    Link fatherLink = linkDiscoverer.findLinkWithRel("father", s);
    assertThat(fatherLink.getHref(), endsWith(new UriTemplate("/{id}/father").expand(person.getId()).toString()));

    Link siblingLink = linkDiscoverer.findLinkWithRel("siblings", s);
    assertThat(siblingLink.getHref(), endsWith(new UriTemplate("/{id}/siblings").expand(person.getId()).toString()));
  }
View Full Code Here

    user.address = new Address();
    user.address.street = "Street";

    PersistentEntityResource userResource = PersistentEntityResource.//
        build(user, repositories.getPersistentEntity(User.class)).//
        withLink(new Link("/users/1")).//
        build();

    PagedResources<PersistentEntityResource> persistentEntityResource = new PagedResources<PersistentEntityResource>(
        Arrays.asList(userResource), new PageMetadata(1, 0, 10));
View Full Code Here

    order.add(new LineItem("first"));
    order.add(new LineItem("second"));

    PersistentEntityResource orderResource = PersistentEntityResource.//
        build(order, repositories.getPersistentEntity(Order.class)).//
        withLink(new Link("/orders/1")).//
        build();

    PagedResources<PersistentEntityResource> persistentEntityResource = new PagedResources<PersistentEntityResource>(
        Arrays.asList(orderResource), new PageMetadata(1, 0, 10));
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.