use of io.crnk.meta.model.MetaAttribute in project crnk-framework by crnk-project.
the class MetaFilteringTest method checkInsertableAttribute.
@Test
public void checkInsertableAttribute() 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.NONE);
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.assertTrue(projectAttr.isInsertable());
Assert.assertFalse(projectAttr.isUpdatable());
}
use of io.crnk.meta.model.MetaAttribute in project crnk-framework by crnk-project.
the class MetaFilteringTest method checkResourceMeta.
private void checkResourceMeta(boolean readable, boolean insertable, boolean updatable, boolean deletable) throws IOException {
QuerySpec querySpec = new QuerySpec(MetaResource.class);
querySpec.addFilter(new FilterSpec(Arrays.asList("name"), FilterOperator.EQ, "Tasks"));
ResourceList<MetaResource> list = repository.findAll(querySpec);
boolean filtered = !readable && !insertable && !updatable && !deletable;
Assert.assertEquals(filtered, list.isEmpty());
if (!filtered) {
MetaResource metaResource = list.get(0);
Assert.assertEquals(readable, metaResource.isReadable());
Assert.assertEquals(deletable, metaResource.isDeletable());
Assert.assertEquals(insertable, metaResource.isInsertable());
Assert.assertEquals(updatable, metaResource.isUpdatable());
MetaAttribute idAttr = metaResource.getAttribute("id");
Assert.assertNotNull(idAttr);
}
}
use of io.crnk.meta.model.MetaAttribute in project crnk-framework by crnk-project.
the class MetaMetaTest method testLinksNaming.
@Test
public void testLinksNaming() {
MetaResource taskMeta = resourceProvider.getMeta(Task.class);
MetaAttribute linksInformation = taskMeta.getAttribute("linksInformation");
MetaType type = linksInformation.getType();
Assert.assertEquals(type.getId(), "resources.tasks$links");
Assert.assertEquals(type.getName(), "TaskLinks");
}
use of io.crnk.meta.model.MetaAttribute in project crnk-framework by crnk-project.
the class MetaMetaTest method testNonMetaElementMutable.
@Test
public void testNonMetaElementMutable() {
MetaResource dataMeta = resourceProvider.getMeta(Task.class);
Assert.assertTrue(dataMeta.isUpdatable());
Assert.assertTrue(dataMeta.isInsertable());
Assert.assertTrue(dataMeta.isDeletable());
Assert.assertNotEquals(0, dataMeta.getAttributes().size());
for (MetaAttribute attr : dataMeta.getAttributes()) {
Assert.assertTrue(attr.isInsertable());
}
}
Aggregations