Search in sources :

Example 1 with VoteEntity

use of io.crnk.operations.model.VoteEntity 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());
}
Also used : VoteEntity(io.crnk.operations.model.VoteEntity) OperationsCall(io.crnk.operations.client.OperationsCall) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Aggregations

QuerySpec (io.crnk.core.queryspec.QuerySpec)1 OperationsCall (io.crnk.operations.client.OperationsCall)1 VoteEntity (io.crnk.operations.model.VoteEntity)1 Test (org.junit.Test)1