Search in sources :

Example 11 with QueryParams

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

the class JpaQueryParamsEndToEndTest method testDelete.

@Test
public void testDelete() {
    TestEntity test = new TestEntity();
    test.setId(1L);
    test.setStringValue("test");
    testRepo.create(test);
    testRepo.delete(1L);
    List<TestEntity> list = testRepo.findAll(new QueryParams());
    Assert.assertEquals(0, list.size());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest)

Example 12 with QueryParams

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

the class DefaultQuerySpecConverterTest method testFilterNEQ.

@Test
public void testFilterNEQ() throws InstantiationException, IllegalAccessException {
    Map<String, Set<String>> params = new HashMap<String, Set<String>>();
    addParams(params, "filter[tasks][id][NEQ]", "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.NEQ, filter.getOperator());
    Assert.assertEquals(Long.valueOf(12L), filter.getValue());
}
Also used : QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test)

Example 13 with QueryParams

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

the class DefaultQuerySpecConverterTest method testPaging.

@Test
public void testPaging() throws InstantiationException, IllegalAccessException {
    Map<String, Set<String>> params = new HashMap<String, Set<String>>();
    addParams(params, "page[offset]", "1");
    addParams(params, "page[limit]", "2");
    addParams(params, "sort[tasks][id]", "asc");
    QueryParams queryParams = queryParamsBuilder.buildQueryParams(params);
    QuerySpec spec = querySpecConverter.fromParams(Task.class, queryParams);
    Assert.assertEquals(1L, spec.getOffset());
    Assert.assertEquals(Long.valueOf(2L), spec.getLimit());
}
Also used : QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test)

Example 14 with QueryParams

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

the class DefaultQuerySpecConverterTest method testIncludeField.

@Test
public void testIncludeField() throws InstantiationException, IllegalAccessException {
    Map<String, Set<String>> params = new HashMap<String, Set<String>>();
    addParams(params, "fields[tasks]", "name");
    QueryParams queryParams = queryParamsBuilder.buildQueryParams(params);
    QuerySpec spec = querySpecConverter.fromParams(Task.class, queryParams);
    List<IncludeFieldSpec> includes = spec.getIncludedFields();
    Assert.assertEquals(1, includes.size());
    IncludeFieldSpec include = includes.get(0);
    Assert.assertEquals(Arrays.asList("name"), include.getAttributePath());
}
Also used : QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test)

Example 15 with QueryParams

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

the class DefaultQuerySpecConverterTest method testFilterString.

@Test
public void testFilterString() throws InstantiationException, IllegalAccessException {
    Map<String, Set<String>> params = new HashMap<String, Set<String>>();
    addParams(params, "filter[tasks][name]", "test1");
    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("name"), filter.getAttributePath());
    Assert.assertEquals("test1", filter.getValue());
}
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