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