Example usage for org.springframework.hateoas Links Links

List of usage examples for org.springframework.hateoas Links Links

Introduction

In this page you can find the example usage for org.springframework.hateoas Links Links.

Prototype

private Links(Link... links) 

Source Link

Usage

From source file:example.springdata.rest.stores.StarbucksClient.java

@Test
public void accessServiceUsingRestTemplate() {

    // Access root resource

    URI uri = URI.create(String.format(SERVICE_URI, port));
    RequestEntity<Void> request = RequestEntity.get(uri).accept(HAL_JSON).build();
    Resource<Object> rootLinks = restOperations.exchange(request, new ResourceType<Object>() {
    }).getBody();// ww w  .jav  a 2 s  .c om
    Links links = new Links(rootLinks.getLinks());

    // Follow stores link

    Link storesLink = links.getLink("stores").expand();
    request = RequestEntity.get(URI.create(storesLink.getHref())).accept(HAL_JSON).build();
    Resources<Store> stores = restOperations.exchange(request, new ResourcesType<Store>() {
    }).getBody();

    stores.getContent().forEach(store -> log.info("{} - {}", store.name, store.address));
}

From source file:org.springframework.data.rest.webmvc.PersistentEntityResourceAssemblerIntegrationTests.java

/**
 * @see DATAREST-609//  w  ww .j av a2s.c om
 */
@Test
public void addsSelfAndSingleResourceLinkToResourceByDefault() throws Exception {

    Projector projector = mock(Projector.class);

    when(projector.projectExcerpt(anyObject())).thenAnswer(new ReturnsArgumentAt(0));

    PersistentEntityResourceAssembler assembler = new PersistentEntityResourceAssembler(entities, projector,
            associations,
            new DefaultSelfLinkProvider(entities, entityLinks, Collections.<EntityLookup<?>>emptyList()));

    User user = new User();
    user.id = BigInteger.valueOf(4711);

    PersistentEntityResource resource = assembler.toResource(user);

    Links links = new Links(resource.getLinks());

    assertThat(links, is(Matchers.<Link>iterableWithSize(2)));
    assertThat(links.getLink("self").getVariables(), is(Matchers.empty()));
    assertThat(links.getLink("user").getVariableNames(), is(hasItem("projection")));
}