Search in sources :

Example 51 with MetaAttribute

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

Example 52 with MetaAttribute

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);
    }
}
Also used : 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)

Example 53 with MetaAttribute

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");
}
Also used : MetaResource(io.crnk.meta.model.resource.MetaResource) MetaAttribute(io.crnk.meta.model.MetaAttribute) MetaType(io.crnk.meta.model.MetaType) Test(org.junit.Test)

Example 54 with MetaAttribute

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());
    }
}
Also used : MetaResource(io.crnk.meta.model.resource.MetaResource) MetaAttribute(io.crnk.meta.model.MetaAttribute) Test(org.junit.Test)

Aggregations

MetaAttribute (io.crnk.meta.model.MetaAttribute)54 Test (org.junit.Test)32 MetaResource (io.crnk.meta.model.resource.MetaResource)16 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)9 MetaDataObject (io.crnk.meta.model.MetaDataObject)7 MetaKey (io.crnk.meta.model.MetaKey)7 MetaResourceBase (io.crnk.meta.model.resource.MetaResourceBase)7 FilterSpec (io.crnk.core.queryspec.FilterSpec)5 MetaType (io.crnk.meta.model.MetaType)5 ResourceField (io.crnk.core.engine.information.resource.ResourceField)4 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)4 QuerySpec (io.crnk.core.queryspec.QuerySpec)4 MetaElement (io.crnk.meta.model.MetaElement)4 EntityManager (javax.persistence.EntityManager)4 Type (java.lang.reflect.Type)3 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)2 TSField (io.crnk.gen.typescript.model.TSField)2 MetaEntity (io.crnk.jpa.meta.MetaEntity)2 MetaJpaDataObject (io.crnk.jpa.meta.MetaJpaDataObject)2 NamingTestEntity (io.crnk.jpa.model.NamingTestEntity)2