Example usage for org.springframework.data.rest.webmvc.support Projector projectExcerpt

List of usage examples for org.springframework.data.rest.webmvc.support Projector projectExcerpt

Introduction

In this page you can find the example usage for org.springframework.data.rest.webmvc.support Projector projectExcerpt.

Prototype

Object projectExcerpt(Object source);

Source Link

Document

Creates a excerpt projection for the given source.

Usage

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

/**
 * @see DATAREST-609/*  w  ww.  j a v a 2s  . 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")));
}