Search in sources :

Example 96 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.

the class DefaultQuerySpecDeserializerTestBase method testUnknownPropertyAllowed.

@Test
public void testUnknownPropertyAllowed() {
    QuerySpec expectedSpec = new QuerySpec(Task.class);
    expectedSpec.addFilter(new FilterSpec(Arrays.asList("doesNotExists"), FilterOperator.EQ, "value"));
    deserializer.setAllowUnknownAttributes(true);
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "filter[tasks][doesNotExists]", "value");
    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) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 97 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.

the class DefaultQuerySpecDeserializerTestBase method testHyphenIsAllowedInResourceName.

@Test
public void testHyphenIsAllowedInResourceName() {
    QuerySpec expectedSpec = new QuerySpec(Task.class);
    expectedSpec.addSort(new SortSpec(Arrays.asList("id"), Direction.ASC));
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "sort[task-with-lookup]", "id");
    ResourceInformation taskWithLookUpInformation = resourceRegistry.getEntryForClass(TaskWithLookup.class).getResourceInformation();
    QuerySpec actualSpec = deserializer.deserialize(taskWithLookUpInformation, params);
    Assert.assertEquals(expectedSpec, actualSpec);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) TaskWithLookup(io.crnk.core.mock.models.TaskWithLookup) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) QuerySpec(io.crnk.core.queryspec.QuerySpec) SortSpec(io.crnk.core.queryspec.SortSpec) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 98 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.

the class DefaultQuerySpecDeserializerTestBase method testFindAllOrderByDesc.

@Test
public void testFindAllOrderByDesc() {
    QuerySpec expectedSpec = new QuerySpec(Task.class);
    expectedSpec.addSort(new SortSpec(Arrays.asList("name"), Direction.DESC));
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "sort[tasks]", "-name");
    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) SortSpec(io.crnk.core.queryspec.SortSpec) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 99 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.

the class DefaultQuerySpecDeserializerTestBase method testFilterGreaterOnRoot.

@Test
public void testFilterGreaterOnRoot() {
    QuerySpec expectedSpec = new QuerySpec(Task.class);
    expectedSpec.addFilter(new FilterSpec(Arrays.asList("id"), FilterOperator.LE, 1L));
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "filter[id][LE]", "1");
    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) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 100 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.

the class DefaultQuerySpecDeserializerTestBase method testFilterWithComputedAttribute.

@Test
public void testFilterWithComputedAttribute() {
    // if computeAttribte is not found, module order is wrong
    // tests setup with information builder must be hardened
    QuerySpec expectedSpec = new QuerySpec(Task.class);
    expectedSpec.addFilter(new FilterSpec(Arrays.asList("computedAttribute"), FilterOperator.EQ, 13));
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "filter[tasks][computedAttribute]", "13");
    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) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Aggregations

QuerySpec (io.crnk.core.queryspec.QuerySpec)306 Test (org.junit.Test)233 FilterSpec (io.crnk.core.queryspec.FilterSpec)51 Document (io.crnk.core.engine.document.Document)45 Resource (io.crnk.core.engine.document.Resource)43 Set (java.util.Set)39 HashMap (java.util.HashMap)37 HashSet (java.util.HashSet)36 AbstractQuerySpecTest (io.crnk.core.queryspec.AbstractQuerySpecTest)34 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)32 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)32 Task (io.crnk.test.mock.models.Task)32 Project (io.crnk.core.mock.models.Project)28 Relationship (io.crnk.core.engine.document.Relationship)26 Task (io.crnk.core.mock.models.Task)26 TestEntity (io.crnk.jpa.model.TestEntity)26 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)25 Serializable (java.io.Serializable)24 RelatedEntity (io.crnk.jpa.model.RelatedEntity)21 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)20