use of io.crnk.core.queryspec.FilterSpec in project crnk-framework by crnk-project.
the class MetaFilteringTest method checkReadOnlyAttribute.
@Test
public void checkReadOnlyAttribute() throws IOException {
RegistryEntry entry = boot.getResourceRegistry().getEntry(Task.class);
ResourceInformation resourceInformation = entry.getResourceInformation();
ResourceField projectField = resourceInformation.findFieldByUnderlyingName("project");
Mockito.when(filter.filterField(Mockito.eq(projectField), Mockito.eq(HttpMethod.POST))).thenReturn(FilterBehavior.FORBIDDEN);
Mockito.when(filter.filterField(Mockito.eq(projectField), Mockito.eq(HttpMethod.PATCH))).thenReturn(FilterBehavior.FORBIDDEN);
QuerySpec querySpec = new QuerySpec(MetaResource.class);
querySpec.addFilter(new FilterSpec(Arrays.asList("name"), FilterOperator.EQ, "Tasks"));
ResourceList<MetaResource> list = repository.findAll(querySpec);
Assert.assertEquals(1, list.size());
MetaResource taskMeta = list.get(0);
Assert.assertTrue(taskMeta.hasAttribute("project"));
MetaAttribute projectAttr = taskMeta.getAttribute("project");
Assert.assertFalse(projectAttr.isInsertable());
Assert.assertFalse(projectAttr.isUpdatable());
}
use of io.crnk.core.queryspec.FilterSpec in project crnk-framework by crnk-project.
the class AbstractBraveModuleTest method testFindAll.
@Test
public void testFindAll() {
Task task = new Task();
task.setId(13L);
task.setName("myTask");
QuerySpec querySpec = new QuerySpec(Task.class);
querySpec.addFilter(new FilterSpec(Arrays.asList("name"), FilterOperator.EQ, "doe"));
taskRepo.findAll(querySpec);
// check client call and link span
ArgumentCaptor<Span> clientSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(clientReporter, Mockito.times(isOkHttp ? 1 : 1)).report(clientSpanCaptor.capture());
List<Span> clientSpans = clientSpanCaptor.getAllValues();
Span callSpan = clientSpans.get(0);
Assert.assertEquals("get", callSpan.name());
Assert.assertEquals(Span.Kind.CLIENT, callSpan.kind());
// check server local span
ArgumentCaptor<Span> serverSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(serverReporter, Mockito.times(1)).report(serverSpanCaptor.capture());
List<Span> serverSpans = serverSpanCaptor.getAllValues();
Span repositorySpan = serverSpans.get(0);
Assert.assertEquals("crnk:get:/tasks/", repositorySpan.name());
Assert.assertTrue(repositorySpan.toString().contains("\"lc\""));
assertTag(repositorySpan, "lc", "crnk");
assertTag(repositorySpan, "crnk.query", "?filter[tasks][name][EQ]=doe");
assertTag(repositorySpan, "crnk.results", "0");
assertTag(repositorySpan, "crnk.status", "OK");
}
use of io.crnk.core.queryspec.FilterSpec in project crnk-framework by crnk-project.
the class JpaQuerySpecEndToEndTest method testIncludeAndFilterManyRelations.
@Test
public void testIncludeAndFilterManyRelations() throws InstantiationException, IllegalAccessException {
addTestWithManyRelations();
QuerySpec querySpec = new QuerySpec(TestEntity.class);
querySpec.includeRelation(Arrays.asList(TestEntity.ATTR_manyRelatedValues));
QuerySpec relatedSpec = querySpec.getOrCreateQuerySpec(RelatedEntity.class);
relatedSpec.addFilter(new FilterSpec(Arrays.asList(RelatedEntity.ATTR_id), FilterOperator.LT, 103L));
List<TestEntity> list = testRepo.findAll(querySpec);
Assert.assertEquals(1, list.size());
TestEntity testEntity = list.get(0);
List<RelatedEntity> manyRelatedValues = testEntity.getManyRelatedValues();
Assert.assertNotNull(manyRelatedValues);
Assert.assertEquals(2, manyRelatedValues.size());
for (RelatedEntity manyRelatedValue : manyRelatedValues) {
Assert.assertTrue(manyRelatedValue.getId() == 101L || manyRelatedValue.getId() == 102L);
}
}
use of io.crnk.core.queryspec.FilterSpec in project crnk-framework by crnk-project.
the class JpaRelationshipRepositoryTestBase method testFindManyTargetWithFilter.
@Test
public void testFindManyTargetWithFilter() throws InstantiationException, IllegalAccessException {
QuerySpec querySpec = new QuerySpec(RelatedEntity.class);
querySpec.addFilter(new FilterSpec(Arrays.asList("id"), FilterOperator.EQ, 101));
Iterable<RelatedEntity> relatedEntities = repo.findManyTargets(1L, TestEntity.ATTR_oneRelatedValue, querySpec);
Iterator<RelatedEntity> iterator = relatedEntities.iterator();
RelatedEntity relatedEntity = iterator.next();
Assert.assertFalse(iterator.hasNext());
Assert.assertNotNull(relatedEntity);
Assert.assertEquals(101L, relatedEntity.getId().longValue());
}
use of io.crnk.core.queryspec.FilterSpec in project crnk-framework by crnk-project.
the class DefaultQuerySpecDeserializerTestBase method testFilterByMany.
@Test
public void testFilterByMany() {
QuerySpec expectedSpec = new QuerySpec(Task.class);
expectedSpec.addFilter(new FilterSpec(Arrays.asList("name"), FilterOperator.EQ, new HashSet<>(Arrays.asList("value1", "value2"))));
Map<String, Set<String>> params = new HashMap<>();
params.put("filter[tasks][name][EQ]", new HashSet<>(Arrays.asList("value1", "value2")));
QuerySpec actualSpec = deserializer.deserialize(taskInformation, params);
Assert.assertEquals(expectedSpec, actualSpec);
}
Aggregations