@Test public void testFindResource() { Sample r = new Sample("toto"); r = (Sample) this.request("service-based").xmlPost(r).resource(r.getClass()); Response response = this.request("service-based/" + r.getId()).get(); Assertions.assertThat(response.getStatus()).isEqualTo(Http.OK); }
@Test(expectedExceptions = {NotImplementedClientException.class}) public void testFindAllResourcesUnpaginated() { this.request("service-based").jsonPost(new Sample("toto")); this.request("service-based").jsonPost(new Sample("toto")); Response r = this.request("service-based").setQueryParameter("page", "no").getXml(); Assertions.assertThat(r).isNotNull(); Assertions.assertThat(r.getStatus()).isEqualTo(Http.NOT_IMPLEMENTED); }
@Test public void testCreateResource() { Sample r = new Sample("toto"); Response response = this.request("service-based").xmlPost(r); r = (Sample) response.resource(r.getClass()); Assertions.assertThat(r).isNotNull(); Assertions.assertThat(r.getName()).isEqualTo("toto"); }
@Test(expectedExceptions = {NotFoundClientException.class}) public void testDeleteResource() { Sample r = new Sample("toto"); r = this.request("service-based").xmlPost(r).resource(r.getClass()); Assertions.assertThat(r).isNotNull(); Response response = this.request("service-based/" + r.getId()).delete(); Assertions.assertThat(response.getStatus()).isEqualTo(Http.NO_CONTENT); this.request("service-based/" + r.getId()).get(); }
@Test public void testFindPaginatedResources() { this.request("repository-based").xmlPost(new Sample("toto")); this.request("repository-based").xmlPost(new Sample("titi")); Response response = this.request("repository-based").setQueryParameter("page", "1").getXml(); Page<Sample> samples = response.resource(new TypeReference<Page<Sample>>() {}); Assertions.assertThat(samples).isNotNull(); Assertions.assertThat(samples.getContent()).isNotNull(); Assertions.assertThat(samples.getContent().size()).isEqualTo(2); Assertions.assertThat(samples.getTotalPages()).isEqualTo(1); Assertions.assertThat(samples.getTotalElements()).isEqualTo(2); Assertions.assertThat(samples.getContent().get(0).getName()).isIn("titi", "toto"); Assertions.assertThat(samples.getContent().get(1).getName()).isIn("titi", "toto"); }