Search in sources :

Example 21 with ResourceInformation

use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.

the class DefaultQuerySpecConverter method getResourceClass.

private Class<?> getResourceClass(String resourceType) {
    RegistryEntry registryEntry = resourceRegistry.getEntry(resourceType);
    if (registryEntry == null) {
        throw new IllegalArgumentException("resourceType " + resourceType + " not found");
    }
    ResourceInformation resourceInformation = registryEntry.getResourceInformation();
    return resourceInformation.getResourceClass();
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 22 with ResourceInformation

use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.

the class MetaFilteringTest method checkTotalResourceFiltering.

@Test
public void checkTotalResourceFiltering() throws IOException {
    RegistryEntry entry = boot.getResourceRegistry().getEntry(Task.class);
    ResourceInformation resourceInformation = entry.getResourceInformation();
    Mockito.when(filter.filterResource(Mockito.eq(resourceInformation), Mockito.any(HttpMethod.class))).thenReturn(FilterBehavior.FORBIDDEN);
    checkResourceMeta(false, false, false, false);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) HttpMethod(io.crnk.core.engine.http.HttpMethod) Test(org.junit.Test)

Example 23 with ResourceInformation

use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.

the class MetaFilteringTest method checkReadOnlyResource.

@Test
public void checkReadOnlyResource() throws IOException {
    RegistryEntry entry = boot.getResourceRegistry().getEntry(Task.class);
    ResourceInformation resourceInformation = entry.getResourceInformation();
    Mockito.when(filter.filterResource(Mockito.eq(resourceInformation), Mockito.eq(HttpMethod.GET))).thenReturn(FilterBehavior.NONE);
    Mockito.when(filter.filterResource(Mockito.eq(resourceInformation), Mockito.eq(HttpMethod.POST))).thenReturn(FilterBehavior.FORBIDDEN);
    Mockito.when(filter.filterResource(Mockito.eq(resourceInformation), Mockito.eq(HttpMethod.PATCH))).thenReturn(FilterBehavior.FORBIDDEN);
    Mockito.when(filter.filterResource(Mockito.eq(resourceInformation), Mockito.eq(HttpMethod.DELETE))).thenReturn(FilterBehavior.FORBIDDEN);
    checkResourceMeta(true, false, false, false);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Test(org.junit.Test)

Example 24 with ResourceInformation

use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.

the class MetaFilteringTest method checkReadOnlyInsertableResource.

@Test
public void checkReadOnlyInsertableResource() throws IOException {
    RegistryEntry entry = boot.getResourceRegistry().getEntry(Task.class);
    ResourceInformation resourceInformation = entry.getResourceInformation();
    Mockito.when(filter.filterResource(Mockito.eq(resourceInformation), Mockito.eq(HttpMethod.GET))).thenReturn(FilterBehavior.NONE);
    Mockito.when(filter.filterResource(Mockito.eq(resourceInformation), Mockito.eq(HttpMethod.POST))).thenReturn(FilterBehavior.NONE);
    Mockito.when(filter.filterResource(Mockito.eq(resourceInformation), Mockito.eq(HttpMethod.PATCH))).thenReturn(FilterBehavior.FORBIDDEN);
    Mockito.when(filter.filterResource(Mockito.eq(resourceInformation), Mockito.eq(HttpMethod.DELETE))).thenReturn(FilterBehavior.FORBIDDEN);
    checkResourceMeta(true, true, false, false);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Test(org.junit.Test)

Example 25 with ResourceInformation

use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.

the class MetaFilteringTest method checkReadOnlyAttribute.

@Test
public void checkReadOnlyAttribute() throws IOException {
    RegistryEntry entry = boot.getResourceRegistry().getEntry(Task.class);
    ResourceInformation resourceInformation = entry.getResourceInformation();
    ResourceField projectField = resourceInformation.findFieldByUnderlyingName("project");
    Mockito.when(filter.filterField(Mockito.eq(projectField), Mockito.eq(HttpMethod.POST))).thenReturn(FilterBehavior.FORBIDDEN);
    Mockito.when(filter.filterField(Mockito.eq(projectField), Mockito.eq(HttpMethod.PATCH))).thenReturn(FilterBehavior.FORBIDDEN);
    QuerySpec querySpec = new QuerySpec(MetaResource.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList("name"), FilterOperator.EQ, "Tasks"));
    ResourceList<MetaResource> list = repository.findAll(querySpec);
    Assert.assertEquals(1, list.size());
    MetaResource taskMeta = list.get(0);
    Assert.assertTrue(taskMeta.hasAttribute("project"));
    MetaAttribute projectAttr = taskMeta.getAttribute("project");
    Assert.assertFalse(projectAttr.isInsertable());
    Assert.assertFalse(projectAttr.isUpdatable());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) MetaResource(io.crnk.meta.model.resource.MetaResource) MetaAttribute(io.crnk.meta.model.MetaAttribute) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Test(org.junit.Test)

Aggregations

ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)167 Test (org.junit.Test)79 ResourceField (io.crnk.core.engine.information.resource.ResourceField)76 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)60 QuerySpec (io.crnk.core.queryspec.QuerySpec)16 Resource (io.crnk.core.engine.document.Resource)15 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)15 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)9 Task (io.crnk.core.mock.models.Task)9 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)9 HashSet (java.util.HashSet)9 Collection (java.util.Collection)8 Relationship (io.crnk.core.engine.document.Relationship)7 HttpMethod (io.crnk.core.engine.http.HttpMethod)7 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)7 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)7 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)7 DefaultResourceList (io.crnk.core.resource.list.DefaultResourceList)7 Set (java.util.Set)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6