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