Search in sources :

Example 41 with QueryParams

use of io.crnk.legacy.queryParams.QueryParams in project crnk-framework by crnk-project.

the class DefaultQuerySpecConverterTest method testFindAll.

@Test
public void testFindAll() throws InstantiationException, IllegalAccessException {
    QuerySpec spec = querySpecConverter.fromParams(Task.class, new QueryParams());
    Assert.assertEquals(new QuerySpec(Task.class), spec);
}
Also used : Task(io.crnk.core.mock.models.Task) QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test)

Example 42 with QueryParams

use of io.crnk.legacy.queryParams.QueryParams in project crnk-framework by crnk-project.

the class DefaultQuerySpecConverterTest method testFilterLong.

@Test
public void testFilterLong() throws InstantiationException, IllegalAccessException {
    Map<String, Set<String>> params = new HashMap<String, Set<String>>();
    addParams(params, "filter[tasks][id]", "12");
    QueryParams queryParams = queryParamsBuilder.buildQueryParams(params);
    QuerySpec spec = querySpecConverter.fromParams(Task.class, queryParams);
    List<FilterSpec> filters = spec.getFilters();
    Assert.assertEquals(1, filters.size());
    FilterSpec filter = filters.get(0);
    Assert.assertEquals(Arrays.asList("id"), filter.getAttributePath());
    Assert.assertEquals(FilterOperator.EQ, filter.getOperator());
    Assert.assertEquals(Long.valueOf(12L), filter.getValue());
}
Also used : QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test)

Example 43 with QueryParams

use of io.crnk.legacy.queryParams.QueryParams in project crnk-framework by crnk-project.

the class DefaultQuerySpecConverterTest method testNestedSort.

@Test
public void testNestedSort() throws InstantiationException, IllegalAccessException {
    Map<String, Set<String>> params = new HashMap<String, Set<String>>();
    addParams(params, "sort[tasks][project][name]", "asc");
    QueryParams queryParams = queryParamsBuilder.buildQueryParams(params);
    QuerySpec spec = querySpecConverter.fromParams(Task.class, queryParams);
    List<SortSpec> sorts = spec.getSort();
    Assert.assertEquals(1, sorts.size());
    SortSpec sort = sorts.get(0);
    Assert.assertEquals(Arrays.asList("project", "name"), sort.getAttributePath());
    Assert.assertEquals(Direction.ASC, sort.getDirection());
}
Also used : QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test)

Example 44 with QueryParams

use of io.crnk.legacy.queryParams.QueryParams in project crnk-framework by crnk-project.

the class DefaultQuerySpecConverterTest method testFindAllOrder.

public void testFindAllOrder(boolean asc) throws InstantiationException, IllegalAccessException {
    Map<String, Set<String>> params = new HashMap<String, Set<String>>();
    addParams(params, "sort[tasks][name]", asc ? "asc" : "desc");
    QueryParams queryParams = queryParamsBuilder.buildQueryParams(params);
    QuerySpec spec = querySpecConverter.fromParams(Task.class, queryParams);
    List<SortSpec> sort = spec.getSort();
    Assert.assertEquals(1, sort.size());
    Assert.assertEquals(Arrays.asList("name"), sort.get(0).getAttributePath());
    Assert.assertEquals(asc ? Direction.ASC : Direction.DESC, sort.get(0).getDirection());
}
Also used : QueryParams(io.crnk.legacy.queryParams.QueryParams)

Example 45 with QueryParams

use of io.crnk.legacy.queryParams.QueryParams in project crnk-framework by crnk-project.

the class DefaultQuerySpecConverterTest method testFilterUnknownResource.

@Test(expected = IllegalArgumentException.class)
public void testFilterUnknownResource() throws InstantiationException, IllegalAccessException {
    Map<String, Set<String>> params = new HashMap<String, Set<String>>();
    addParams(params, "filter[unknown][id]", "12");
    QueryParams queryParams = queryParamsBuilder.buildQueryParams(params);
    querySpecConverter.fromParams(Task.class, queryParams);
}
Also used : QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test)

Aggregations

QueryParams (io.crnk.legacy.queryParams.QueryParams)46 Test (org.junit.Test)37 QueryParamsAdapter (io.crnk.legacy.internal.QueryParamsAdapter)10 Response (io.crnk.core.engine.dispatcher.Response)9 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)9 Document (io.crnk.core.engine.document.Document)7 BaseControllerTest (io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest)7 Project (io.crnk.core.mock.models.Project)7 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)7 Resource (io.crnk.core.engine.document.Resource)6 TaskToProjectRepository (io.crnk.core.mock.repository.TaskToProjectRepository)6 TestEntity (io.crnk.jpa.model.TestEntity)6 Task (io.crnk.test.mock.models.Task)6 ResourcePost (io.crnk.core.engine.internal.dispatcher.controller.ResourcePost)5 Task (io.crnk.core.mock.models.Task)5 DefaultQueryParamsParser (io.crnk.legacy.queryParams.DefaultQueryParamsParser)5 QueryParamsBuilder (io.crnk.legacy.queryParams.QueryParamsBuilder)5 Relationship (io.crnk.core.engine.document.Relationship)3 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)3 ResourceModificationFilter (io.crnk.core.engine.filter.ResourceModificationFilter)3