Search in sources :

Example 6 with OperationsCall

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());
}
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

OperationsCall (io.crnk.operations.client.OperationsCall)6 Test (org.junit.Test)6 QuerySpec (io.crnk.core.queryspec.QuerySpec)5 MovieEntity (io.crnk.operations.model.MovieEntity)4 PersonEntity (io.crnk.operations.model.PersonEntity)3 UUID (java.util.UUID)2 Relationship (io.crnk.core.engine.document.Relationship)1 Resource (io.crnk.core.engine.document.Resource)1 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)1 InternalServerErrorException (io.crnk.core.exception.InternalServerErrorException)1 OperationsClient (io.crnk.operations.client.OperationsClient)1 VoteEntity (io.crnk.operations.model.VoteEntity)1 OperationFilter (io.crnk.operations.server.OperationFilter)1 OperationFilterChain (io.crnk.operations.server.OperationFilterChain)1 OperationFilterContext (io.crnk.operations.server.OperationFilterContext)1 List (java.util.List)1