use of io.crnk.core.engine.dispatcher.RepositoryRequestSpec in project crnk-framework by crnk-project.
the class RepositoryFilterTest method addRelations.
@SuppressWarnings({ "unchecked" })
@Test
public void addRelations() throws Exception {
projectRelationAdapter.addRelations(user1, Arrays.asList(13L, 14L), assignedProjectsField, queryAdapter);
ArgumentCaptor<RepositoryFilterContext> contexts = ArgumentCaptor.forClass(RepositoryFilterContext.class);
Mockito.verify(filter, Mockito.times(1)).filterRequest(contexts.capture(), Mockito.any(RepositoryRequestFilterChain.class));
Mockito.verify(filter, Mockito.times(0)).filterResult(Mockito.any(RepositoryFilterContext.class), Mockito.any(RepositoryResultFilterChain.class));
Mockito.verify(filter, Mockito.times(0)).filterLinks(Mockito.any(RepositoryFilterContext.class), Mockito.any(Iterable.class), Mockito.any(RepositoryLinksFilterChain.class));
Mockito.verify(filter, Mockito.times(0)).filterMeta(Mockito.any(RepositoryFilterContext.class), Mockito.any(Iterable.class), Mockito.any(RepositoryMetaFilterChain.class));
Assert.assertEquals(1, contexts.getAllValues().size());
RepositoryFilterContext context = contexts.getAllValues().iterator().next();
RepositoryRequestSpec requestSpec = context.getRequest();
Assert.assertEquals(queryAdapter, requestSpec.getQueryAdapter());
Assert.assertEquals(user1, requestSpec.getEntity());
Assert.assertEquals(HttpMethod.POST, requestSpec.getMethod());
Assert.assertEquals(Arrays.asList(13L, 14L), requestSpec.getIds());
Assert.assertSame(querySpec, requestSpec.getQuerySpec(userInfo));
}
use of io.crnk.core.engine.dispatcher.RepositoryRequestSpec in project crnk-framework by crnk-project.
the class RepositoryFilterTest method findOneTarget.
@SuppressWarnings({ "unchecked" })
@Test
public void findOneTarget() throws Exception {
projectRelationAdapter.findOneTarget(1L, assignedProjectsField, queryAdapter);
ArgumentCaptor<RepositoryFilterContext> contexts = ArgumentCaptor.forClass(RepositoryFilterContext.class);
Mockito.verify(filter, Mockito.times(1)).filterRequest(contexts.capture(), Mockito.any(RepositoryRequestFilterChain.class));
Mockito.verify(filter, Mockito.times(1)).filterResult(Mockito.any(RepositoryFilterContext.class), Mockito.any(RepositoryResultFilterChain.class));
Mockito.verify(filter, Mockito.times(1)).filterLinks(Mockito.any(RepositoryFilterContext.class), Mockito.any(Iterable.class), Mockito.any(RepositoryLinksFilterChain.class));
Mockito.verify(filter, Mockito.times(1)).filterMeta(Mockito.any(RepositoryFilterContext.class), Mockito.any(Iterable.class), Mockito.any(RepositoryMetaFilterChain.class));
Assert.assertEquals(1, contexts.getAllValues().size());
RepositoryFilterContext context = contexts.getAllValues().iterator().next();
RepositoryRequestSpec requestSpec = context.getRequest();
Assert.assertEquals(queryAdapter, requestSpec.getQueryAdapter());
Assert.assertEquals(1L, requestSpec.getId());
Assert.assertEquals(HttpMethod.GET, requestSpec.getMethod());
Assert.assertEquals(Arrays.asList(1L), requestSpec.getIds());
Assert.assertSame(querySpec, requestSpec.getQuerySpec(userInfo));
}
use of io.crnk.core.engine.dispatcher.RepositoryRequestSpec in project crnk-framework by crnk-project.
the class RepositoryFilterTest method findBulkManyTargetsBulkImpl.
@SuppressWarnings({ "unchecked" })
@Test
public void findBulkManyTargetsBulkImpl() throws Exception {
List<Long> ids = Arrays.asList(1L, 2L);
taskRelationAdapter.findBulkManyTargets(ids, assignedTasksField, queryAdapter);
ArgumentCaptor<RepositoryFilterContext> contexts = ArgumentCaptor.forClass(RepositoryFilterContext.class);
Mockito.verify(filter, Mockito.times(0)).filterRequest(contexts.capture(), Mockito.any(RepositoryRequestFilterChain.class));
Mockito.verify(filter, Mockito.times(1)).filterBulkRequest(contexts.capture(), Mockito.any(RepositoryBulkRequestFilterChain.class));
Mockito.verify(filter, Mockito.times(2)).filterResult(Mockito.any(RepositoryFilterContext.class), Mockito.any(RepositoryResultFilterChain.class));
Mockito.verify(filter, Mockito.times(2)).filterLinks(Mockito.any(RepositoryFilterContext.class), Mockito.any(Iterable.class), Mockito.any(RepositoryLinksFilterChain.class));
Mockito.verify(filter, Mockito.times(2)).filterMeta(Mockito.any(RepositoryFilterContext.class), Mockito.any(Iterable.class), Mockito.any(RepositoryMetaFilterChain.class));
Assert.assertEquals(1, contexts.getAllValues().size());
RepositoryFilterContext context1 = contexts.getAllValues().get(0);
RepositoryRequestSpec requestSpec1 = context1.getRequest();
Assert.assertEquals(queryAdapter, requestSpec1.getQueryAdapter());
Assert.assertNull(requestSpec1.getEntity());
Assert.assertEquals("assignedTasks", requestSpec1.getRelationshipField().getUnderlyingName());
Assert.assertEquals(HttpMethod.GET, requestSpec1.getMethod());
Assert.assertEquals(Arrays.asList(1L, 2L), requestSpec1.getIds());
Assert.assertSame(querySpec, requestSpec1.getQuerySpec(userInfo));
}
use of io.crnk.core.engine.dispatcher.RepositoryRequestSpec in project crnk-framework by crnk-project.
the class RepositoryFilterTest method findAllWithResourceListResult.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void findAllWithResourceListResult() throws Exception {
RegistryEntry scheduleRegistry = resourceRegistry.getEntry(Schedule.class);
ResourceRepositoryAdapter<Schedule, Serializable> scheduleResourceAdapter = scheduleRegistry.getResourceRepository(null);
querySpec = new QuerySpec(Schedule.class);
querySpec.setPagingSpec(new OffsetLimitPagingSpec());
queryAdapter = new QuerySpecAdapter(querySpec, resourceRegistry);
scheduleResourceAdapter.findAll(queryAdapter);
ArgumentCaptor<Iterable> linksResources = ArgumentCaptor.forClass(Iterable.class);
ArgumentCaptor<Iterable> metaResources = ArgumentCaptor.forClass(Iterable.class);
ArgumentCaptor<RepositoryFilterContext> contexts = ArgumentCaptor.forClass(RepositoryFilterContext.class);
Mockito.verify(filter, Mockito.times(1)).filterRequest(contexts.capture(), Mockito.any(RepositoryRequestFilterChain.class));
Mockito.verify(filter, Mockito.times(1)).filterResult(Mockito.any(RepositoryFilterContext.class), Mockito.any(RepositoryResultFilterChain.class));
Mockito.verify(filter, Mockito.times(1)).filterLinks(Mockito.any(RepositoryFilterContext.class), linksResources.capture(), Mockito.any(RepositoryLinksFilterChain.class));
Mockito.verify(filter, Mockito.times(1)).filterMeta(Mockito.any(RepositoryFilterContext.class), metaResources.capture(), Mockito.any(RepositoryMetaFilterChain.class));
Assert.assertEquals(1, linksResources.getAllValues().size());
Assert.assertEquals(1, metaResources.getAllValues().size());
Assert.assertEquals(1, contexts.getAllValues().size());
RepositoryFilterContext context = contexts.getAllValues().iterator().next();
RepositoryRequestSpec requestSpec = context.getRequest();
Assert.assertEquals(queryAdapter, requestSpec.getQueryAdapter());
Assert.assertNull(requestSpec.getId());
Assert.assertNull(requestSpec.getIds());
QuerySpec actualQuerySpec = requestSpec.getQuerySpec(scheduleInfo);
Assert.assertSame(querySpec, actualQuerySpec);
}
use of io.crnk.core.engine.dispatcher.RepositoryRequestSpec in project crnk-framework by crnk-project.
the class RepositoryFilterTest method removeRelations.
@SuppressWarnings({ "unchecked" })
@Test
public void removeRelations() throws Exception {
projectRelationAdapter.removeRelations(user1, Arrays.asList(13L, 14L), assignedProjectsField, queryAdapter);
ArgumentCaptor<RepositoryFilterContext> contexts = ArgumentCaptor.forClass(RepositoryFilterContext.class);
Mockito.verify(filter, Mockito.times(1)).filterRequest(contexts.capture(), Mockito.any(RepositoryRequestFilterChain.class));
Mockito.verify(filter, Mockito.times(0)).filterResult(Mockito.any(RepositoryFilterContext.class), Mockito.any(RepositoryResultFilterChain.class));
Mockito.verify(filter, Mockito.times(0)).filterLinks(Mockito.any(RepositoryFilterContext.class), Mockito.any(Iterable.class), Mockito.any(RepositoryLinksFilterChain.class));
Mockito.verify(filter, Mockito.times(0)).filterMeta(Mockito.any(RepositoryFilterContext.class), Mockito.any(Iterable.class), Mockito.any(RepositoryMetaFilterChain.class));
Assert.assertEquals(1, contexts.getAllValues().size());
RepositoryFilterContext context = contexts.getAllValues().iterator().next();
RepositoryRequestSpec requestSpec = context.getRequest();
Assert.assertEquals(queryAdapter, requestSpec.getQueryAdapter());
Assert.assertEquals(user1, requestSpec.getEntity());
Assert.assertEquals("assignedProjects", requestSpec.getRelationshipField().getUnderlyingName());
Assert.assertEquals(HttpMethod.DELETE, requestSpec.getMethod());
Assert.assertEquals(Arrays.asList(13L, 14L), requestSpec.getIds());
Assert.assertSame(querySpec, requestSpec.getQuerySpec(userInfo));
}
Aggregations