use of io.crnk.operations.client.OperationsCall in project crnk-framework by crnk-project.
the class OperationsSingleEntityTest method testAutoIncrementCrud.
@Test
public void testAutoIncrementCrud() {
ResourceRepositoryV2<VoteEntity, Long> voteRepo = client.getRepositoryForType(VoteEntity.class);
VoteEntity vote = new VoteEntity();
vote.setNumStars(12);
// post
OperationsCall call = operationsClient.createCall();
call.add(HttpMethod.POST, vote);
call.execute();
// read
ResourceList<VoteEntity> votes = voteRepo.findAll(new QuerySpec(VoteEntity.class));
Assert.assertEquals(1, votes.size());
vote = votes.get(0);
Assert.assertEquals(1, vote.getId().intValue());
// update
vote.setNumStars(13);
call = operationsClient.createCall();
call.add(HttpMethod.PATCH, vote);
call.execute();
vote = call.getResponseObject(0, VoteEntity.class);
Assert.assertEquals(13, vote.getNumStars());
Assert.assertEquals(1, vote.getId().intValue());
// delete
call = operationsClient.createCall();
call.add(HttpMethod.DELETE, vote);
call.execute();
votes = voteRepo.findAll(new QuerySpec(VoteEntity.class));
Assert.assertEquals(0, votes.size());
}
Aggregations