use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.
the class FieldResourceGetTest method onNonRelationRequestShouldDenyIt.
@Test
public void onNonRelationRequestShouldDenyIt() {
// GIVEN
JsonPath jsonPath = new ResourcePath("tasks");
ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
FieldResourceGet sut = new FieldResourceGet(resourceRegistry, typeParser, documentMapper);
// WHEN
boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
// THEN
assertThat(result).isFalse();
}
use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.
the class FieldResourceGetTest method onRelationshipRequestShouldDenyIt.
@Test
public void onRelationshipRequestShouldDenyIt() {
// GIVEN
JsonPath jsonPath = new ResourcePath("tasks/1/relationships/project");
ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
FieldResourceGet sut = new FieldResourceGet(resourceRegistry, typeParser, documentMapper);
// WHEN
boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
// THEN
assertThat(result).isFalse();
}
use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.
the class FieldResourceGetTest method onValidRequestShouldAcceptIt.
@Test
public void onValidRequestShouldAcceptIt() {
// GIVEN
JsonPath jsonPath = pathBuilder.build("tasks/1/project");
ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
FieldResourceGet sut = new FieldResourceGet(resourceRegistry, typeParser, documentMapper);
// WHEN
boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
// THEN
assertThat(result).isTrue();
}
use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.
the class CrnkBootTest method boot.
@Test
public void boot() {
CrnkBoot boot = new CrnkBoot();
boot.setDefaultServiceUrlProvider(new ServiceUrlProvider() {
@Override
public String getUrl() {
return "http://127.0.0.1";
}
});
boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
boot.addModule(new SimpleModule("test"));
boot.boot();
RequestDispatcher requestDispatcher = boot.getRequestDispatcher();
ResourceRegistry resourceRegistry = boot.getResourceRegistry();
RegistryEntry taskEntry = resourceRegistry.getEntry(Task.class);
Assert.assertNotEquals(0, taskEntry.getRelationshipEntries().size());
ResourceRepositoryAdapter<?, ?> repositoryAdapter = taskEntry.getResourceRepository(null);
Assert.assertNotNull(repositoryAdapter.getResourceRepository());
JsonApiResponse response = repositoryAdapter.findAll(new QueryParamsAdapter(taskEntry.getResourceInformation(), new QueryParams(), boot.getModuleRegistry()));
Assert.assertNotNull(response);
Assert.assertNotNull(requestDispatcher);
ServiceDiscovery serviceDiscovery = boot.getServiceDiscovery();
Assert.assertNotNull(serviceDiscovery);
Assert.assertNotNull(boot.getModuleRegistry());
Assert.assertNotNull(boot.getExceptionMapperRegistry());
List<Module> modules = boot.getModuleRegistry().getModules();
Assert.assertEquals(4, modules.size());
boot.setDefaultPageLimit(20L);
boot.setMaxPageLimit(100L);
Assert.assertEquals(1, boot.getPagingBehaviors().size());
Assert.assertTrue(boot.getPagingBehaviors().get(0) instanceof OffsetLimitPagingBehavior);
}
use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.
the class ResourceMetaFilter method getResourceInformation.
private ResourceInformation getResourceInformation(MetaResourceBase meta, boolean allowNull) {
ResourceRegistry resourceRegistry = context.getModuleContext().getResourceRegistry();
if (meta instanceof MetaResource) {
RegistryEntry entry = resourceRegistry.getEntry(((MetaResource) meta).getResourceType());
if (entry != null) {
return entry.getResourceInformation();
}
}
Class<?> resourceClass = meta.getImplementationClass();
ResourceInformationProvider infoBuilder = context.getModuleContext().getResourceInformationBuilder();
if (infoBuilder.accept(resourceClass)) {
return infoBuilder.build(resourceClass);
}
if (allowNull) {
return null;
}
throw new IllegalStateException("failed to get information for " + resourceClass.getName());
}
Aggregations