Search in sources :

Example 91 with QuerySpec

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

the class DefaultQuerySpecDeserializerTestBase method customPaginationOnRoot.

@Test
public void customPaginationOnRoot() {
    Map<String, Set<String>> params = new HashMap<>();
    QuerySpec actualSpec = deserializer.deserialize(taskWithPagingBehaviorInformation, params);
    Assert.assertEquals(1L, actualSpec.getOffset());
    Assert.assertEquals(10L, actualSpec.getLimit().longValue());
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) QuerySpec(io.crnk.core.queryspec.QuerySpec) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 92 with QuerySpec

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

the class DefaultQuerySpecDeserializerTestBase method testFindAll.

@Test
public void testFindAll() {
    Map<String, Set<String>> params = new HashMap<>();
    QuerySpec actualSpec = deserializer.deserialize(taskInformation, params);
    QuerySpec expectedSpec = new QuerySpec(Task.class);
    Assert.assertEquals(expectedSpec, actualSpec);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) QuerySpec(io.crnk.core.queryspec.QuerySpec) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 93 with QuerySpec

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

the class DefaultQuerySpecDeserializerTestBase method testUnknownPropertyNotAllowed.

@Test(expected = PropertyException.class)
public void testUnknownPropertyNotAllowed() {
    QuerySpec expectedSpec = new QuerySpec(Task.class);
    expectedSpec.addFilter(new FilterSpec(Arrays.asList("doesNotExists"), FilterOperator.EQ, "value"));
    deserializer.setAllowUnknownAttributes(false);
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "filter[tasks][doesNotExists]", "value");
    deserializer.deserialize(taskInformation, params);
}
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 94 with QuerySpec

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

the class DefaultQuerySpecDeserializerTestBase method testPagingMaxLimitAllowed.

@Test
public void testPagingMaxLimitAllowed() {
    QuerySpec expectedSpec = new QuerySpec(Task.class);
    expectedSpec.setOffset(1L);
    expectedSpec.setLimit(5L);
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "page[offset]", "1");
    add(params, "page[limit]", "5");
    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) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 95 with QuerySpec

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

the class DefaultQuerySpecDeserializerTestBase method testGenericCast.

@Test
public void testGenericCast() {
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "filter[id]", "12");
    add(params, "filter[name]", "test");
    add(params, "filter[completed]", "true");
    deserializer.setIgnoreParseExceptions(false);
    QuerySpec querySpec = deserializer.deserialize(taskInformation, params);
    Assert.assertEquals(Task.class, querySpec.getResourceClass());
    Assert.assertEquals(Arrays.asList("id"), querySpec.getFilters().get(2).getAttributePath());
    Long id = querySpec.getFilters().get(2).getValue();
    Assert.assertEquals(Long.valueOf(12), id);
    String name = querySpec.getFilters().get(0).getValue();
    Assert.assertEquals("test", name);
    Boolean completed = querySpec.getFilters().get(1).getValue();
    Assert.assertEquals(Boolean.TRUE, completed);
    Assert.assertNull(querySpec.getRelatedSpecs().get(Project.class));
}
Also used : Project(io.crnk.core.mock.models.Project) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) QuerySpec(io.crnk.core.queryspec.QuerySpec) 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