Search in sources :

Example 26 with QuerySpec

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

Example 27 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.

the class OperationsSingleEntityTest method testSingleEntityCrud.

@Test
public void testSingleEntityCrud() {
    MovieEntity movie = newMovie("test");
    // post
    OperationsCall call = operationsClient.createCall();
    call.add(HttpMethod.POST, movie);
    call.execute();
    // read
    ResourceList<MovieEntity> movies = movieRepo.findAll(new QuerySpec(MovieEntity.class));
    Assert.assertEquals(1, movies.size());
    movie = movies.get(0);
    // update
    movie.setTitle("NewTitle");
    call = operationsClient.createCall();
    call.add(HttpMethod.PATCH, movie);
    call.execute();
    movie = call.getResponseObject(0, MovieEntity.class);
    Assert.assertEquals("NewTitle", movie.getTitle());
    // delete
    call = operationsClient.createCall();
    call.add(HttpMethod.DELETE, movie);
    call.execute();
    movies = movieRepo.findAll(new QuerySpec(MovieEntity.class));
    Assert.assertEquals(0, movies.size());
}
Also used : MovieEntity(io.crnk.operations.model.MovieEntity) OperationsCall(io.crnk.operations.client.OperationsCall) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Example 28 with QuerySpec

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

Example 29 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.

the class SecurityModuleIntTest method metaAllPermissions.

@Test
public void metaAllPermissions() {
    identityManager.addUser("doe", "doePass", "allRole");
    ResourceList<Project> list = projectRepo.findAll(new QuerySpec(Project.class));
    ResourcePermissionInformation metaInformation = list.getMeta(ResourcePermissionInformationImpl.class);
    ResourcePermission resourcePermission = metaInformation.getResourcePermission();
    Assert.assertEquals(ResourcePermission.ALL, resourcePermission);
}
Also used : Project(io.crnk.security.model.Project) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Example 30 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.

the class SecurityModuleIntTest method rootAll.

@Test
public void rootAll() {
    identityManager.addUser("doe", "doePass", "allRole");
    Project project = new Project();
    project.setId(1L);
    project.setName("test");
    projectRepo.create(project);
    project.setName("updated");
    projectRepo.save(project);
    project = projectRepo.findOne(project.getId(), new QuerySpec(Project.class));
    Assert.assertNotNull(project);
    projectRepo.delete(project.getId());
}
Also used : Project(io.crnk.security.model.Project) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Aggregations

QuerySpec (io.crnk.core.queryspec.QuerySpec)306 Test (org.junit.Test)233 FilterSpec (io.crnk.core.queryspec.FilterSpec)51 Document (io.crnk.core.engine.document.Document)45 Resource (io.crnk.core.engine.document.Resource)43 Set (java.util.Set)39 HashMap (java.util.HashMap)37 HashSet (java.util.HashSet)36 AbstractQuerySpecTest (io.crnk.core.queryspec.AbstractQuerySpecTest)34 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)32 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)32 Task (io.crnk.test.mock.models.Task)32 Project (io.crnk.core.mock.models.Project)28 Relationship (io.crnk.core.engine.document.Relationship)26 Task (io.crnk.core.mock.models.Task)26 TestEntity (io.crnk.jpa.model.TestEntity)26 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)25 Serializable (java.io.Serializable)24 RelatedEntity (io.crnk.jpa.model.RelatedEntity)21 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)20