Search in sources :

Example 1 with AnnotatedResourceRepositoryAdapter

use of io.crnk.legacy.internal.AnnotatedResourceRepositoryAdapter in project crnk-framework by crnk-project.

the class ResourceRepositoryAdapter method delete.

public JsonApiResponse delete(I id, QueryAdapter queryAdapter) {
    RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {

        @SuppressWarnings("rawtypes")
        @Override
        protected JsonApiResponse invoke(RepositoryFilterContext context) {
            RepositoryRequestSpec request = context.getRequest();
            QueryAdapter queryAdapter = request.getQueryAdapter();
            Serializable id = request.getId();
            if (isAnnotated) {
                ((AnnotatedResourceRepositoryAdapter) resourceRepository).delete(id, queryAdapter);
            } else if (resourceRepository instanceof ResourceRepositoryV2) {
                ((ResourceRepositoryV2) resourceRepository).delete(id);
            } else {
                ((ResourceRepository) resourceRepository).delete(id);
            }
            return new JsonApiResponse();
        }
    };
    RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forDelete(moduleRegistry, resourceInformation, queryAdapter, id);
    return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
Also used : Serializable(java.io.Serializable) RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) AnnotatedResourceRepositoryAdapter(io.crnk.legacy.internal.AnnotatedResourceRepositoryAdapter) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) RepositoryFilterContext(io.crnk.core.engine.filter.RepositoryFilterContext)

Example 2 with AnnotatedResourceRepositoryAdapter

use of io.crnk.legacy.internal.AnnotatedResourceRepositoryAdapter in project crnk-framework by crnk-project.

the class RepositoryAdapterTest method onClassWithGetLinksInformationShouldInvokeMethod.

@Test
public void onClassWithGetLinksInformationShouldInvokeMethod() throws Exception {
    // GIVEN
    ResourceRepositoryWithGetLinksInformation repo = spy(ResourceRepositoryWithGetLinksInformation.class);
    AnnotatedResourceRepositoryAdapter<Project, Long> sut = new AnnotatedResourceRepositoryAdapter<>(repo, parameterFactory);
    List<Project> resources = Collections.singletonList(new Project());
    // WHEN
    sut.getLinksInformation(resources, queryAdapter);
    // THEN
    verify(repo).getLinksInformation(resources, queryParams, "");
}
Also used : Project(io.crnk.core.mock.models.Project) AnnotatedResourceRepositoryAdapter(io.crnk.legacy.internal.AnnotatedResourceRepositoryAdapter) Test(org.junit.Test)

Example 3 with AnnotatedResourceRepositoryAdapter

use of io.crnk.legacy.internal.AnnotatedResourceRepositoryAdapter in project crnk-framework by crnk-project.

the class AnnotatedResourceRepositoryAdapterTest method onClassWithInvalidSaveShouldThrowException.

@Test(expected = RepositoryMethodException.class)
public void onClassWithInvalidSaveShouldThrowException() throws Exception {
    // GIVEN
    ResourceRepositoryWithEmptySave repo = new ResourceRepositoryWithEmptySave();
    AnnotatedResourceRepositoryAdapter<Project, Long> sut = new AnnotatedResourceRepositoryAdapter<>(repo, parameterProvider);
    // WHEN
    sut.save(new Project());
}
Also used : Project(io.crnk.core.mock.models.Project) AnnotatedResourceRepositoryAdapter(io.crnk.legacy.internal.AnnotatedResourceRepositoryAdapter) Test(org.junit.Test)

Example 4 with AnnotatedResourceRepositoryAdapter

use of io.crnk.legacy.internal.AnnotatedResourceRepositoryAdapter in project crnk-framework by crnk-project.

the class AnnotatedResourceRepositoryAdapterTest method onClassWithSaveShouldReturnValue.

@Test
public void onClassWithSaveShouldReturnValue() throws Exception {
    // GIVEN
    ResourceRepositoryWithSave repo = spy(ResourceRepositoryWithSave.class);
    AnnotatedResourceRepositoryAdapter<Project, Long> sut = new AnnotatedResourceRepositoryAdapter<>(repo, parameterProvider);
    // WHEN
    Project entity = new Project();
    Object result = sut.save(entity);
    // THEN
    verify(repo).save(eq(entity), eq(""));
    assertThat(result).isNotNull();
    assertThat(((Project) (result)).getId()).isEqualTo(1L);
}
Also used : Project(io.crnk.core.mock.models.Project) AnnotatedResourceRepositoryAdapter(io.crnk.legacy.internal.AnnotatedResourceRepositoryAdapter) Test(org.junit.Test)

Example 5 with AnnotatedResourceRepositoryAdapter

use of io.crnk.legacy.internal.AnnotatedResourceRepositoryAdapter in project crnk-framework by crnk-project.

the class RepositoryAdapterTest method onClassWithGetMetaInformationShouldInvokeMethod.

@Test
public void onClassWithGetMetaInformationShouldInvokeMethod() throws Exception {
    // GIVEN
    ResourceRepositoryWithGetMetaInformation repo = spy(ResourceRepositoryWithGetMetaInformation.class);
    AnnotatedResourceRepositoryAdapter<Project, Long> sut = new AnnotatedResourceRepositoryAdapter<>(repo, parameterFactory);
    List<Project> resources = Collections.singletonList(new Project());
    // WHEN
    sut.getMetaInformation(resources, queryAdapter);
    // THEN
    verify(repo).getMetaInformation(resources, queryParams, "");
}
Also used : Project(io.crnk.core.mock.models.Project) AnnotatedResourceRepositoryAdapter(io.crnk.legacy.internal.AnnotatedResourceRepositoryAdapter) Test(org.junit.Test)

Aggregations

AnnotatedResourceRepositoryAdapter (io.crnk.legacy.internal.AnnotatedResourceRepositoryAdapter)6 Project (io.crnk.core.mock.models.Project)5 Test (org.junit.Test)5 RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)1 RepositoryFilterContext (io.crnk.core.engine.filter.RepositoryFilterContext)1 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)1 ResourceRepositoryV2 (io.crnk.core.repository.ResourceRepositoryV2)1 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)1 Serializable (java.io.Serializable)1