Search in sources :

Example 16 with ResourceRegistry

use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.

the class DecoratorTest method testResourceRegistryAwareDecoration.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testResourceRegistryAwareDecoration() {
    RegistryAwareResourceRepository repository = Mockito.mock(RegistryAwareResourceRepository.class);
    ResourceRepositoryDecoratorBase<Schedule, Long> decorator = new ResourceRepositoryDecoratorBase() {
    };
    decorator.setDecoratedObject(repository);
    ResourceRegistry resourceRegistry = Mockito.mock(ResourceRegistry.class);
    decorator.setResourceRegistry(resourceRegistry);
    Mockito.verify(repository, Mockito.times(1)).setResourceRegistry(Mockito.eq(resourceRegistry));
}
Also used : Schedule(io.crnk.core.mock.models.Schedule) ResourceRepositoryDecoratorBase(io.crnk.core.repository.decorate.ResourceRepositoryDecoratorBase) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) Test(org.junit.Test)

Example 17 with ResourceRegistry

use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.

the class BasicProxyFactory method createResourceProxy.

@Override
public <T> T createResourceProxy(Class<T> clazz, Object id) {
    T instance = ClassUtils.newInstance(clazz);
    ResourceRegistry resourceRegistry = context.getModuleRegistry().getResourceRegistry();
    RegistryEntry entry = resourceRegistry.findEntry(clazz);
    ResourceInformation resourceInformation = entry.getResourceInformation();
    resourceInformation.setId(instance, id);
    return instance;
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 18 with ResourceRegistry

use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.

the class RelationshipsResourceDeleteTest method onValidRequestShouldAcceptIt.

@Test
public void onValidRequestShouldAcceptIt() {
    // GIVEN
    JsonPath jsonPath = pathBuilder.build("tasks/1/relationships/project");
    ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
    RelationshipsResourceDelete sut = new RelationshipsResourceDelete(resourceRegistry, typeParser, modificationFilters);
    // WHEN
    boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
    // THEN
    assertThat(result).isTrue();
}
Also used : ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) RelationshipsResourceDelete(io.crnk.core.engine.internal.dispatcher.controller.RelationshipsResourceDelete) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

Example 19 with ResourceRegistry

use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.

the class RelationshipsResourcePatchTest method onNonRelationRequestShouldDenyIt.

@Test
public void onNonRelationRequestShouldDenyIt() {
    // GIVEN
    JsonPath jsonPath = new ResourcePath("tasks");
    ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
    RelationshipsResourcePatch sut = new RelationshipsResourcePatch(resourceRegistry, typeParser, modificationFilters);
    // WHEN
    boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
    // THEN
    assertThat(result).isFalse();
}
Also used : ResourcePath(io.crnk.core.engine.internal.dispatcher.path.ResourcePath) RelationshipsResourcePatch(io.crnk.core.engine.internal.dispatcher.controller.RelationshipsResourcePatch) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

Example 20 with ResourceRegistry

use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.

the class ResourceDeleteTest method onValidRequestShouldAcceptIt.

@Test
public void onValidRequestShouldAcceptIt() {
    // GIVEN
    JsonPath jsonPath = pathBuilder.build("tasks/1");
    ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
    ResourceDelete sut = new ResourceDelete(resourceRegistry, new ArrayList<ResourceModificationFilter>());
    // WHEN
    boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
    // THEN
    assertThat(result).isTrue();
}
Also used : ResourceModificationFilter(io.crnk.core.engine.filter.ResourceModificationFilter) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) ResourceDelete(io.crnk.core.engine.internal.dispatcher.controller.ResourceDelete) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

Aggregations

ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)48 Test (org.junit.Test)25 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)21 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)19 BaseControllerTest (io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest)17 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)15 ResourcePath (io.crnk.core.engine.internal.dispatcher.path.ResourcePath)10 ResourceField (io.crnk.core.engine.information.resource.ResourceField)5 PathBuilder (io.crnk.core.engine.internal.dispatcher.path.PathBuilder)4 ModuleRegistry (io.crnk.core.module.ModuleRegistry)4 QueryParamsAdapter (io.crnk.legacy.internal.QueryParamsAdapter)4 Before (org.junit.Before)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 FieldResourceGet (io.crnk.core.engine.internal.dispatcher.controller.FieldResourceGet)3 RelationshipsResourceGet (io.crnk.core.engine.internal.dispatcher.controller.RelationshipsResourceGet)3 ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)3 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)3 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)3 RequestDispatcher (io.crnk.core.engine.dispatcher.RequestDispatcher)2 ResourceModificationFilter (io.crnk.core.engine.filter.ResourceModificationFilter)2