List of usage examples for org.springframework.data.rest.webmvc.jpa Person Person
public Person(String firstName, String lastName)
From source file:org.springframework.data.rest.webmvc.json.Jackson2DatatypeHelperIntegrationTests.java
@Before public void setUp() { this.order = orders.save(new Order(people.save(new Person("Dave", "Matthews")))); // Reset JPA to make sure the query returns a result with proxy references em.flush();// w w w . jav a 2 s . c o m em.clear(); }
From source file:org.springframework.data.rest.webmvc.jpa.JpaWebTests.java
/** * @see DATAREST-117/*w ww. ja v a 2 s.c o m*/ */ @Test public void createPersonThenVerifyIgnoredAttributesDontExist() throws Exception { Link peopleLink = client.discoverUnique("people"); ObjectMapper mapper = new ObjectMapper(); Person frodo = new Person("Frodo", "Baggins"); frodo.setAge(77); frodo.setHeight(42); frodo.setWeight(75); String frodoString = mapper.writeValueAsString(frodo); MockHttpServletResponse response = postAndGet(peopleLink, frodoString, MediaType.APPLICATION_JSON); assertJsonPathEquals("$.firstName", "Frodo", response); assertJsonPathEquals("$.lastName", "Baggins", response); assertJsonPathDoesntExist("$.age", response); assertJsonPathDoesntExist("$.height", response); assertJsonPathDoesntExist("$.weight", response); }
From source file:org.springframework.data.rest.webmvc.jpa.JpaWebTests.java
/** * @see DATAREST-219// w w w . jav a2 s .c o m */ @Test public void manipulatePropertyCollectionRestfullyWithMultiplePosts() throws Exception { List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), // new Person("Bilbo", "Baggins"), // new Person("Merry", "Baggins"), // new Person("Pippin", "Baggins")); Link frodosSiblingLink = links.get(0); patchAndGet(frodosSiblingLink, links.get(1).getHref(), TEXT_URI_LIST); patchAndGet(frodosSiblingLink, links.get(2).getHref(), TEXT_URI_LIST); patchAndGet(frodosSiblingLink, links.get(3).getHref(), TEXT_URI_LIST); assertSiblingNames(frodosSiblingLink, "Bilbo", "Merry", "Pippin"); }
From source file:org.springframework.data.rest.webmvc.jpa.JpaWebTests.java
/** * @see DATAREST-219/*from w ww . j a v a2 s . c o m*/ */ @Test public void manipulatePropertyCollectionRestfullyWithSinglePost() throws Exception { List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), // new Person("Bilbo", "Baggins"), // new Person("Merry", "Baggins"), // new Person("Pippin", "Baggins")); Link frodosSiblingLink = links.get(0); patchAndGet(frodosSiblingLink, toUriList(links.get(1), links.get(2), links.get(3)), TEXT_URI_LIST); assertSiblingNames(frodosSiblingLink, "Bilbo", "Merry", "Pippin"); }
From source file:org.springframework.data.rest.webmvc.jpa.JpaWebTests.java
/** * @see DATAREST-219//from w w w .j a va2 s.com */ @Test public void manipulatePropertyCollectionRestfullyWithMultiplePuts() throws Exception { List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), // new Person("Bilbo", "Baggins"), // new Person("Merry", "Baggins"), // new Person("Pippin", "Baggins")); Link frodosSiblingsLink = links.get(0); putAndGet(frodosSiblingsLink, links.get(1).expand().getHref(), TEXT_URI_LIST); putAndGet(frodosSiblingsLink, links.get(2).expand().getHref(), TEXT_URI_LIST); putAndGet(frodosSiblingsLink, links.get(3).expand().getHref(), TEXT_URI_LIST); assertSiblingNames(frodosSiblingsLink, "Pippin"); patchAndGet(frodosSiblingsLink, links.get(2).getHref(), TEXT_URI_LIST); assertSiblingNames(frodosSiblingsLink, "Merry", "Pippin"); }
From source file:org.springframework.data.rest.webmvc.jpa.JpaWebTests.java
/** * @see DATAREST-219/* ww w .j a v a 2s . co m*/ */ @Test public void manipulatePropertyCollectionRestfullyWithSinglePut() throws Exception { List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), // new Person("Bilbo", "Baggins"), // new Person("Merry", "Baggins"), // new Person("Pippin", "Baggins")); Link frodoSiblingLink = links.get(0); putAndGet(frodoSiblingLink, toUriList(links.get(1), links.get(2), links.get(3)), TEXT_URI_LIST); assertSiblingNames(frodoSiblingLink, "Bilbo", "Merry", "Pippin"); putAndGet(frodoSiblingLink, toUriList(links.get(3)), TEXT_URI_LIST); assertSiblingNames(frodoSiblingLink, "Pippin"); patchAndGet(frodoSiblingLink, toUriList(links.get(2)), TEXT_URI_LIST); assertSiblingNames(frodoSiblingLink, "Merry", "Pippin"); }
From source file:org.springframework.data.rest.webmvc.jpa.JpaWebTests.java
/** * @see DATAREST-219//from ww w. j av a 2 s.c o m */ @Test public void manipulatePropertyCollectionRestfullyWithDelete() throws Exception { List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), // new Person("Bilbo", "Baggins"), // new Person("Merry", "Baggins"), // new Person("Pippin", "Baggins")); Link frodosSiblingsLink = links.get(0); patchAndGet(frodosSiblingsLink, links.get(1).getHref(), TEXT_URI_LIST); patchAndGet(frodosSiblingsLink, links.get(2).getHref(), TEXT_URI_LIST); patchAndGet(frodosSiblingsLink, links.get(3).getHref(), TEXT_URI_LIST); String pippinId = new UriTemplate("/people/{id}").match(links.get(3).getHref()).get("id"); deleteAndVerify(new Link(frodosSiblingsLink.getHref() + "/" + pippinId)); assertSiblingNames(frodosSiblingsLink, "Bilbo", "Merry"); }
From source file:org.springframework.data.rest.webmvc.jpa.JpaWebTests.java
/** * @see DATAREST-238/*from w w w.ja v a2 s .c om*/ */ @Test public void putShouldWorkDespiteExistingLinks() throws Exception { Link peopleLink = client.discoverUnique("people"); Person frodo = new Person("Frodo", "Baggins"); String frodoString = mapper.writeValueAsString(frodo); MockHttpServletResponse createdPerson = postAndGet(peopleLink, frodoString, MediaType.APPLICATION_JSON); Link frodoLink = client.assertHasLinkWithRel("self", createdPerson); assertJsonPathEquals("$.firstName", "Frodo", createdPerson); String bilboWithFrodosLinks = createdPerson.getContentAsString().replace("Frodo", "Bilbo"); MockHttpServletResponse overwrittenResponse = putAndGet(frodoLink, bilboWithFrodosLinks, MediaType.APPLICATION_JSON); client.assertHasLinkWithRel("self", overwrittenResponse); assertJsonPathEquals("$.firstName", "Bilbo", overwrittenResponse); }
From source file:org.springframework.data.rest.webmvc.jpa.JpaWebTests.java
/** * @see DATAREST-311/*from w ww. j a v a 2 s .c o m*/ */ @Test public void onlyLinksShouldAppearWhenExecuteSearchCompact() throws Exception { Link peopleLink = client.discoverUnique("people"); Person daenerys = new Person("Daenerys", "Targaryen"); String daenerysString = mapper.writeValueAsString(daenerys); MockHttpServletResponse createdPerson = postAndGet(peopleLink, daenerysString, MediaType.APPLICATION_JSON); Link daenerysLink = client.assertHasLinkWithRel("self", createdPerson); assertJsonPathEquals("$.firstName", "Daenerys", createdPerson); Link searchLink = client.discoverUnique(peopleLink, "search"); Link byFirstNameLink = client.discoverUnique(searchLink, "findFirstPersonByFirstName"); MockHttpServletResponse response = client.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"); assertThat(personLinks, hasSize(1)); assertThat(personLinks.get(0), is((Object) daenerysLink.getHref())); assertThat(JsonPath.<JSONArray>read(responseBody, "$.content"), hasSize(0)); }
From source file:org.springframework.data.rest.webmvc.jpa.JpaWebTests.java
/** * @see DATAREST-523//from ww w. j a va2 s. c o m */ @Test public void augmentsCollectionAssociationUsingPost() throws Exception { List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), // new Person("Bilbo", "Baggins")); Link frodosSiblingsLink = links.get(0).expand(); Link bilboLink = links.get(1); for (int i = 1; i <= 2; i++) { mvc.perform(post(frodosSiblingsLink.getHref()).// content(bilboLink.getHref()).// contentType(TEXT_URI_LIST)).// andExpect(status().isNoContent()); mvc.perform(get(frodosSiblingsLink.getHref())).// andExpect(jsonPath("$._embedded.people", hasSize(i))); } }