Search in sources :

Example 21 with FilterSpec

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());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) MetaResource(io.crnk.meta.model.resource.MetaResource) MetaAttribute(io.crnk.meta.model.MetaAttribute) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Test(org.junit.Test)

Example 22 with FilterSpec

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");
}
Also used : Task(io.crnk.monitor.brave.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) Span(zipkin2.Span) Test(org.junit.Test)

Example 23 with FilterSpec

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);
    }
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) RelatedEntity(io.crnk.jpa.model.RelatedEntity) OtherRelatedEntity(io.crnk.jpa.model.OtherRelatedEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest) Test(org.junit.Test)

Example 24 with FilterSpec

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());
}
Also used : RelatedEntity(io.crnk.jpa.model.RelatedEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) Test(org.junit.Test) AbstractJpaTest(io.crnk.jpa.query.AbstractJpaTest)

Example 25 with FilterSpec

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);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) HashSet(java.util.HashSet) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Aggregations

FilterSpec (io.crnk.core.queryspec.FilterSpec)56 QuerySpec (io.crnk.core.queryspec.QuerySpec)51 Test (org.junit.Test)40 HashSet (java.util.HashSet)14 Set (java.util.Set)13 AbstractQuerySpecTest (io.crnk.core.queryspec.AbstractQuerySpecTest)12 HashMap (java.util.HashMap)12 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)9 TaskResource (io.crnk.activiti.resource.TaskResource)8 MetaResource (io.crnk.meta.model.resource.MetaResource)8 ScheduleApprovalProcessInstance (io.crnk.activiti.example.model.ScheduleApprovalProcessInstance)5 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)5 MetaAttribute (io.crnk.meta.model.MetaAttribute)5 ResourceField (io.crnk.core.engine.information.resource.ResourceField)4 ResourceList (io.crnk.core.resource.list.ResourceList)3 RelatedEntity (io.crnk.jpa.model.RelatedEntity)3 ArrayList (java.util.ArrayList)3 MultivaluedMap (io.crnk.core.engine.internal.utils.MultivaluedMap)2 ResourceRepositoryV2 (io.crnk.core.repository.ResourceRepositoryV2)2 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)2