use of io.crnk.operations.model.PersonEntity in project crnk-framework by crnk-project.
the class OperationsExceptionTest method testValidationErrorCancelsPatch.
@Test
public void testValidationErrorCancelsPatch() {
PersonEntity person1 = newPerson("1");
PersonEntity person2 = newPerson("2");
// trigger validation error
person1.setName(null);
OperationsCall insertCall = operationsClient.createCall();
insertCall.add(HttpMethod.POST, person1);
insertCall.add(HttpMethod.POST, person2);
insertCall.execute();
Assert.assertEquals(HttpStatus.UNPROCESSABLE_ENTITY_422, insertCall.getResponse(0).getStatus());
Assert.assertEquals(HttpStatus.PRECONDITION_FAILED_412, insertCall.getResponse(1).getStatus());
QuerySpec querySpec = new QuerySpec(PersonEntity.class);
ResourceRepositoryV2<PersonEntity, UUID> personRepo = client.getRepositoryForType(PersonEntity.class);
List<PersonEntity> list = personRepo.findAll(querySpec);
Assert.assertEquals(0, list.size());
}
use of io.crnk.operations.model.PersonEntity in project crnk-framework by crnk-project.
the class OperationsPostTest method testMultiplePost.
@Test
public void testMultiplePost() {
ResourceRepositoryV2<PersonEntity, UUID> personRepo = client.getRepositoryForType(PersonEntity.class);
PersonEntity person1 = newPerson("1");
PersonEntity person2 = newPerson("2");
MovieEntity movie = newMovie("test");
movie.setDirectors(new HashSet<>(Arrays.asList(person1, person2)));
// tag::client[]
OperationsClient operationsClient = new OperationsClient(client);
OperationsCall call = operationsClient.createCall();
call.add(HttpMethod.POST, movie);
call.add(HttpMethod.POST, person1);
call.add(HttpMethod.POST, person2);
call.execute();
// end::client[]
QuerySpec querySpec = new QuerySpec(PersonEntity.class);
ResourceList<PersonEntity> persons = personRepo.findAll(querySpec);
Assert.assertEquals(2, persons.size());
querySpec = new QuerySpec(MovieEntity.class);
querySpec.includeRelation(Arrays.asList("directors"));
ResourceList<MovieEntity> movies = movieRepo.findAll(querySpec);
Assert.assertEquals(1, movies.size());
movie = movies.get(0);
Assert.assertEquals(2, movie.getDirectors().size());
}
use of io.crnk.operations.model.PersonEntity in project crnk-framework by crnk-project.
the class OperationsDeleteRelationTest method testDeleteRelation.
@Test
public void testDeleteRelation() {
PersonEntity person1 = newPerson("1");
PersonEntity person2 = newPerson("2");
MovieEntity movie = newMovie("test");
movie.setDirectors(new HashSet<>(Arrays.asList(person1, person2)));
OperationsCall insertCall = operationsClient.createCall();
insertCall.add(HttpMethod.POST, movie);
insertCall.add(HttpMethod.POST, person1);
insertCall.add(HttpMethod.POST, person2);
insertCall.execute();
QuerySpec querySpec = new QuerySpec(MovieEntity.class);
querySpec.includeRelation(Arrays.asList("directors"));
MovieEntity updatedMovie = movieRepo.findOne(movie.getId(), querySpec);
Set<PersonEntity> directors = updatedMovie.getDirectors();
PersonEntity deletedDirector = directors.iterator().next();
directors.remove(deletedDirector);
OperationsCall call = operationsClient.createCall();
call.add(HttpMethod.PATCH, updatedMovie);
call.add(HttpMethod.DELETE, deletedDirector);
call.execute();
// check whether updated relationship is included in the response
Resource movieResource = call.getResponse(0).getSingleData().get();
Relationship directorsRelationship = movieResource.getRelationships().get("directors");
List<ResourceIdentifier> directorIds = directorsRelationship.getCollectionData().get();
Assert.assertEquals(1, directorIds.size());
}
use of io.crnk.operations.model.PersonEntity in project crnk-framework by crnk-project.
the class AbstractOperationsTest method newPerson.
protected PersonEntity newPerson(String name) {
PersonEntity person = new PersonEntity();
person.setId(UUID.randomUUID());
person.setName(name);
return person;
}
Aggregations