use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class ResourceFilterDirectoryImplTest method checkForbiddenRelationshipsField.
@Test
public void checkForbiddenRelationshipsField() {
ResourceInformation projectsInformation = Mockito.mock(ResourceInformation.class);
Mockito.when(filter.filterField(Mockito.eq(resourceField), Mockito.any(HttpMethod.class))).thenReturn(FilterBehavior.NONE);
Mockito.when(resourceField.getResourceFieldType()).thenReturn(ResourceFieldType.RELATIONSHIP);
Mockito.when(resourceField.getOppositeResourceType()).thenReturn("projects");
RegistryEntry projectsEntry = Mockito.mock(RegistryEntry.class);
Mockito.when(projectsEntry.getResourceInformation()).thenReturn(projectsInformation);
Mockito.when(resourceRegistry.getEntry(Mockito.eq("projects"))).thenReturn(projectsEntry);
// forbid related resource
Mockito.when(filter.filterResource(Mockito.eq(projectsInformation), Mockito.any(HttpMethod.class))).thenReturn(FilterBehavior.FORBIDDEN);
Assert.assertEquals(FilterBehavior.FORBIDDEN, directory.get(resourceField, HttpMethod.GET));
// allow related resource
Mockito.when(filter.filterResource(Mockito.eq(projectsInformation), Mockito.any(HttpMethod.class))).thenReturn(FilterBehavior.NONE);
Assert.assertEquals(FilterBehavior.NONE, directory.get(resourceField, HttpMethod.GET));
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class ResourceFieldImplTest method checkToString.
@Test
public void checkToString() {
ResourceFieldImpl impl = new ResourceFieldImpl("test-name", "testName", ResourceFieldType.ID, String.class, String.class, null);
ResourceInformation resourceInformation = Mockito.mock(ResourceInformation.class);
Mockito.when(resourceInformation.getResourceType()).thenReturn("someResource");
Mockito.when(resourceInformation.getResourceClass()).thenReturn((Class) Resource.class);
impl.setResourceInformation(resourceInformation);
Assert.assertEquals("ResourceFieldImpl[jsonName=test-name,resourceType=someResource]", impl.toString());
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class ConstraintViolationExceptionMapper method getResourceType.
protected String getResourceType(Object resource) {
ResourceRegistry resourceRegistry = context.getResourceRegistry();
RegistryEntry entry = resourceRegistry.findEntry(resource.getClass());
ResourceInformation resourceInformation = entry.getResourceInformation();
return resourceInformation.getResourceType();
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class DefaultRegistryEntryBuilder method contributeFields.
private void contributeFields(ResourceInformation resourceInformation) {
// TODO make service discovery the primary target to resolve all objects => wrapped it with module
List<ResourceFieldContributor> contributors = new ArrayList<>();
contributors.addAll(moduleRegistry.getServiceDiscovery().getInstancesByType(ResourceFieldContributor.class));
for (Object repo : moduleRegistry.getRepositories()) {
if (repo instanceof ResourceFieldContributor && !contributors.contains(repo)) {
contributors.add((ResourceFieldContributor) repo);
}
}
for (ResourceFieldContributor contributor : contributors) {
List<ResourceField> contributedFields = contributor.getResourceFields(new ResourceFieldContributorContext() {
@Override
public ResourceInformation getResourceInformation() {
return resourceInformation;
}
@Override
public InformationBuilder getInformationBuilder() {
return new DefaultInformationBuilder(moduleRegistry.getTypeParser());
}
});
List<ResourceField> fields = new ArrayList<>();
fields.addAll(resourceInformation.getFields());
fields.addAll(contributedFields);
resourceInformation.setFields(fields);
}
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class DefaultRegistryEntryBuilder method buildResource.
private ResourceInformation buildResource() {
ResourceInformation resourceInformation = resource.build();
contributeFields(resourceInformation);
return resourceInformation;
}
Aggregations