Example usage for org.springframework.data.rest.tests.mongodb User User

List of usage examples for org.springframework.data.rest.tests.mongodb User User

Introduction

In this page you can find the example usage for org.springframework.data.rest.tests.mongodb User User.

Prototype

User

Source Link

Usage

From source file:org.springframework.data.rest.webmvc.config.JsonPatchHandlerUnitTests.java

@Before
public void setUp() {

    MongoMappingContext context = new MongoMappingContext();
    context.getPersistentEntity(User.class);

    PersistentEntities entities = new PersistentEntities(Arrays.asList(context));

    Associations associations = new Associations(mappings, mock(RepositoryRestConfiguration.class));

    this.handler = new JsonPatchHandler(new ObjectMapper(), new DomainObjectReader(entities, associations));

    Address address = new Address();
    address.street = "Foo";
    address.zipCode = "Bar";

    this.user = new User();
    this.user.firstname = "Oliver";
    this.user.lastname = "Gierke";
    this.user.address = address;
}

From source file:org.springframework.data.rest.tests.mongodb.MongoWebTests.java

@Before
public void populateProfiles() {

    mapper.setSerializationInclusion(Include.NON_NULL);

    Profile twitter = new Profile();
    twitter.setPerson(1L);/*from   w ww.  j a v a2  s.  co  m*/
    twitter.setType("Twitter");

    Profile linkedIn = new Profile();
    linkedIn.setPerson(1L);
    linkedIn.setType("LinkedIn");

    repository.save(Arrays.asList(twitter, linkedIn));

    Address address = new Address();
    address.street = "ETagDoesntMatchExceptionUnitTests";
    address.zipCode = "Bar";

    User thomas = new User();
    thomas.firstname = "Thomas";
    thomas.lastname = "Darimont";
    thomas.address = address;

    userRepository.save(thomas);

    User oliver = new User();
    oliver.firstname = "Oliver";
    oliver.lastname = "Gierke";
    oliver.address = address;
    oliver.colleagues = Arrays.asList(thomas);
    userRepository.save(oliver);

    thomas.colleagues = Arrays.asList(oliver);
    userRepository.save(thomas);
}

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

/**
 * @see DATAREST-609/*from  www  .j  av a  2  s .c  o  m*/
 */
@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")));
}

From source file:org.springframework.data.rest.webmvc.json.PersistentEntitySerializationTests.java

/**
 * @see DATAREST-250//from w w w . ja va 2  s.c  o m
 */
@Test
public void serializesEmbeddedReferencesCorrectly() throws Exception {

    User user = new User();
    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));

    String result = mapper.writeValueAsString(persistentEntityResource);

    assertThat(JsonPath.read(result, "$._embedded.users[*].address"), is(notNullValue()));
}

From source file:org.springframework.data.rest.webmvc.config.JsonPatchHandlerUnitTests.java

/**
 * DATAREST-537/*w  w  w  .j  a va 2s  . c o  m*/
 */
@Test
public void removesArrayItemCorrectly() throws Exception {

    User thomas = new User();
    thomas.firstname = "Thomas";

    User christoph = new User();
    christoph.firstname = "Christoph";

    this.user.colleagues = new ArrayList<User>(Arrays.asList(thomas, christoph));

    String input = "[{ \"op\": \"remove\", \"path\": \"/colleagues/0\" }]";

    handler.applyPatch(asStream(input), user);

    assertThat(user.colleagues, hasSize(1));
    assertThat(user.colleagues.get(0).firstname, is(christoph.firstname));
}

From source file:org.springframework.data.rest.webmvc.config.JsonPatchHandlerUnitTests.java

/**
 * @see DATAREST-609/* ww  w.  ja  v a2s  . com*/
 */
@Test
public void hintsToMediaTypeIfBodyCantBeRead() throws Exception {

    exception.expect(HttpMessageNotReadableException.class);
    exception.expectMessage(RestMediaTypes.JSON_PATCH_JSON.toString());

    handler.applyPatch(asStream("{ \"foo\" : \"bar\" }"), new User());
}

From source file:org.springframework.data.rest.tests.mongodb.MongoWebTests.java

/**
 * @see DATAREST-482//from   ww w .j  av  a  2  s  .c  om
 */
@Test
public void putDoesNotRemoveAssociations() throws Exception {

    Link usersLink = client.discoverUnique("users");
    Link userLink = assertHasContentLinkWithRel("self", client.request(usersLink));
    Link colleaguesLink = client.assertHasLinkWithRel("colleagues", client.request(userLink));

    // Expect a user returned as colleague
    client.follow(colleaguesLink).//
            andExpect(jsonPath("$._embedded.users").exists());

    User oliver = new User();
    oliver.firstname = "Oliver";
    oliver.lastname = "Gierke";

    putAndGet(userLink, mapper.writeValueAsString(oliver), MediaType.APPLICATION_JSON);

    // Expect colleague still present but address has been wiped
    client.follow(colleaguesLink).//
            andExpect(jsonPath("$._embedded.users").exists()).//
            andExpect(jsonPath("$.embedded.users[0].address").doesNotExist());
}