Search in sources :

Example 76 with QuerySpec

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

the class AttributeNamingEndToEndTest method testCanStoreBasicAttributeValues.

@Test
public void testCanStoreBasicAttributeValues() throws InstantiationException, IllegalAccessException {
    ResourceRepositoryV2<NamingTestEntity, Serializable> repo = client.getRepositoryForType(NamingTestEntity.class);
    NamingTestEntity test = new NamingTestEntity();
    test.setId(1L);
    test.setSEcondUpperCaseValue(13L);
    repo.create(test);
    ResourceList<NamingTestEntity> list = repo.findAll(new QuerySpec(NamingTestEntity.class));
    Assert.assertEquals(1, list.size());
    NamingTestEntity saved = list.get(0);
    Assert.assertEquals(saved.getSEcondUpperCaseValue(), test.getSEcondUpperCaseValue());
}
Also used : Serializable(java.io.Serializable) QuerySpec(io.crnk.core.queryspec.QuerySpec) NamingTestEntity(io.crnk.jpa.model.NamingTestEntity) Test(org.junit.Test) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest)

Example 77 with QuerySpec

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

the class JpaMetaEndToEndTest method testRenameResourceType.

@Test
public void testRenameResourceType() {
    MetaResource metaResource = resourceMetaProvider.getMeta(RenamedTestEntity.class);
    Assert.assertEquals("renamedResource", metaResource.getResourceType());
    RenamedTestEntity test = new RenamedTestEntity();
    test.setId(1L);
    ResourceRepositoryV2<RenamedTestEntity, Serializable> repository = client.getRepositoryForType(RenamedTestEntity.class);
    repository.create(test);
    Assert.assertEquals(1, repository.findAll(new QuerySpec(RenamedTestEntity.class)).size());
    repository.delete(1L);
    Assert.assertEquals(0, repository.findAll(new QuerySpec(RenamedTestEntity.class)).size());
}
Also used : Serializable(java.io.Serializable) MetaResource(io.crnk.meta.model.resource.MetaResource) RenamedTestEntity(io.crnk.jpa.model.RenamedTestEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest)

Example 78 with QuerySpec

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

the class DtoMappingTest method testReadAndUpdateFromEntity.

@Test
public void testReadAndUpdateFromEntity() throws InstantiationException, IllegalAccessException {
    // create as regular entity
    TestEntity test = new TestEntity();
    test.setId(2L);
    test.setStringValue("test");
    testRepo.create(test);
    // query as regular entity (you may want to disable that in a real application)
    List<TestEntity> list = testRepo.findAll(new QuerySpec(TestEntity.class));
    Assert.assertEquals(1, list.size());
    // query the mapped DTO
    ResourceRepositoryV2<TestDTO, Serializable> dtoRepo = client.getQuerySpecRepository(TestDTO.class);
    List<TestDTO> dtos = dtoRepo.findAll(new QuerySpec(TestDTO.class));
    Assert.assertEquals(1, dtos.size());
    TestDTO dto = dtos.get(0);
    Assert.assertEquals(2L, dto.getId().longValue());
    Assert.assertEquals("test", dto.getStringValue());
    Assert.assertEquals("TEST", dto.getComputedUpperStringValue());
    // update the mapped dto
    dto.setStringValue("newValue");
    dtoRepo.save(dto);
    // read again
    dto = dtoRepo.findOne(2L, new QuerySpec(TestDTO.class));
    Assert.assertEquals(2L, dto.getId().longValue());
    Assert.assertEquals("newValue", dto.getStringValue());
    Assert.assertEquals("NEWVALUE", dto.getComputedUpperStringValue());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) QTestEntity(io.crnk.jpa.model.QTestEntity) TestDTO(io.crnk.jpa.model.dto.TestDTO) Serializable(java.io.Serializable) QuerySpec(io.crnk.core.queryspec.QuerySpec) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest) Test(org.junit.Test)

Example 79 with QuerySpec

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

the class JpaRelationshipRepositoryTestBase method testFindNulledOneTargetWithLimit.

/**
 * Note that implementation behaves slightly differently with a LIMIT in place. Does only work for single requests.
 */
@Test
public void testFindNulledOneTargetWithLimit() throws InstantiationException, IllegalAccessException {
    long nulledEntityId = numTestEntities - 1;
    QuerySpec querySpec = new QuerySpec(RelatedEntity.class);
    querySpec.setLimit(5L);
    RelatedEntity relatedEntity = repo.findOneTarget(nulledEntityId, TestEntity.ATTR_oneRelatedValue, querySpec);
    Assert.assertNull(relatedEntity);
    ResourceList<RelatedEntity> list = repo.findManyTargets(nulledEntityId, TestEntity.ATTR_oneRelatedValue, querySpec);
    Assert.assertEquals(0, list.size());
    PagedMetaInformation pagedMeta = list.getMeta(PagedMetaInformation.class);
    Assert.assertNotNull(pagedMeta.getTotalResourceCount());
    Assert.assertEquals(Long.valueOf(0L), pagedMeta.getTotalResourceCount());
}
Also used : PagedMetaInformation(io.crnk.core.resource.meta.PagedMetaInformation) RelatedEntity(io.crnk.jpa.model.RelatedEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test) AbstractJpaTest(io.crnk.jpa.query.AbstractJpaTest)

Example 80 with QuerySpec

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

the class JpaRelationshipRepositoryTestBase method testFindOneTarget.

@Test
public void testFindOneTarget() throws InstantiationException, IllegalAccessException {
    RelatedEntity relatedEntity = repo.findOneTarget(1L, TestEntity.ATTR_oneRelatedValue, new QuerySpec(RelatedEntity.class));
    Assert.assertNotNull(relatedEntity);
    Assert.assertEquals(101L, relatedEntity.getId().longValue());
}
Also used : RelatedEntity(io.crnk.jpa.model.RelatedEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test) AbstractJpaTest(io.crnk.jpa.query.AbstractJpaTest)

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