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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations