Search in sources :

Example 51 with TestEntity

use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.

the class JpaRelationshipRepositoryTestBase method testSetRelation.

@Test
public void testSetRelation() throws InstantiationException, IllegalAccessException {
    RelatedEntity related = em.find(RelatedEntity.class, 101L);
    TestEntity test = em.find(TestEntity.class, 1L);
    Assert.assertNull(related.getTestEntity());
    relatedRepo.setRelation(related, 1L, RelatedEntity.ATTR_testEntity);
    em.flush();
    em.clear();
    test = em.find(TestEntity.class, 1L);
    Assert.assertEquals(1, test.getManyRelatedValues().size());
    related = em.find(RelatedEntity.class, 101L);
    Assert.assertNotNull(related.getTestEntity());
    // test set null
    relatedRepo.setRelation(related, null, RelatedEntity.ATTR_testEntity);
    em.flush();
    em.clear();
    test = em.find(TestEntity.class, 1L);
    Assert.assertEquals(0, test.getManyRelatedValues().size());
    related = em.find(RelatedEntity.class, 101L);
    Assert.assertNull(related.getTestEntity());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) RelatedEntity(io.crnk.jpa.model.RelatedEntity) Test(org.junit.Test) AbstractJpaTest(io.crnk.jpa.query.AbstractJpaTest)

Example 52 with TestEntity

use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.

the class JpaRelationshipRepositoryTestBase method testGetManyRelationWithPaging.

@Test
public void testGetManyRelationWithPaging() throws InstantiationException, IllegalAccessException {
    TestEntity test = setupManyRelation(Arrays.asList(100L, 101L, 102L, 103L, 104L));
    QuerySpec querySpec = new QuerySpec(TestEntity.class);
    querySpec.setOffset(2L);
    querySpec.setLimit(2L);
    ResourceList<RelatedEntity> list = repo.findManyTargets(test.getId(), TestEntity.ATTR_manyRelatedValues, querySpec);
    Assert.assertEquals(2, list.size());
    Assert.assertEquals(102, list.get(0).getId().intValue());
    Assert.assertEquals(103, list.get(1).getId().intValue());
    PagedMetaInformation metaInformation = list.getMeta(PagedMetaInformation.class);
    Assert.assertEquals(5, metaInformation.getTotalResourceCount().longValue());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) 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 53 with TestEntity

use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.

the class QuerydslRepositoryFilterTest method translationInterceptor.

@SuppressWarnings("unchecked")
@Test
public void translationInterceptor() {
    JpaEntityRepository<TestEntity, Long> repo = new JpaEntityRepository<>(module, JpaRepositoryConfig.create(TestEntity.class));
    QuerydslRepositoryFilterBase filter = Mockito.spy(new QuerydslRepositoryFilterBase());
    module.addFilter(filter);
    QuerySpec querySpec = new QuerySpec(TestEntity.class);
    repo.findAll(querySpec);
    Mockito.verify(filter, Mockito.times(1)).filterQueryTranslation(Mockito.eq(repo), Mockito.eq(querySpec), Mockito.any(QuerydslTranslationContext.class));
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) QuerydslRepositoryFilterBase(io.crnk.jpa.query.querydsl.QuerydslRepositoryFilterBase) QuerydslTranslationContext(io.crnk.jpa.query.querydsl.QuerydslTranslationContext) QuerySpec(io.crnk.core.queryspec.QuerySpec) JpaEntityRepository(io.crnk.jpa.JpaEntityRepository) Test(org.junit.Test) AbstractJpaTest(io.crnk.jpa.query.AbstractJpaTest)

Example 54 with TestEntity

use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.

the class JpaEntityRepositoryTestBase method testFilterLong.

@Test
public void testFilterLong() throws InstantiationException, IllegalAccessException {
    QuerySpec querySpec = new QuerySpec(TestEntity.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList("longValue"), FilterOperator.EQ, 2L));
    List<TestEntity> list = repo.findAll(querySpec);
    Assert.assertEquals(1, list.size());
    TestEntity entity = list.get(0);
    Assert.assertEquals(2, entity.getId().longValue());
    Assert.assertEquals(2L, entity.getLongValue());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) Test(org.junit.Test) AbstractJpaTest(io.crnk.jpa.query.AbstractJpaTest)

Example 55 with TestEntity

use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.

the class JpaEntityRepositoryTestBase method testPaging.

@Test
public void testPaging() throws InstantiationException, IllegalAccessException {
    QuerySpec querySpec = new QuerySpec(TestEntity.class);
    querySpec.setOffset(2L);
    querySpec.setLimit(2L);
    ResourceList<TestEntity> list = repo.findAll(querySpec);
    Assert.assertEquals(2, list.size());
    Assert.assertEquals(2, list.get(0).getId().intValue());
    Assert.assertEquals(3, list.get(1).getId().intValue());
    PagedMetaInformation metaInformation = list.getMeta(PagedMetaInformation.class);
    Assert.assertEquals(5, metaInformation.getTotalResourceCount().longValue());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) PagedMetaInformation(io.crnk.core.resource.meta.PagedMetaInformation) Test(org.junit.Test) AbstractJpaTest(io.crnk.jpa.query.AbstractJpaTest)

Aggregations

TestEntity (io.crnk.jpa.model.TestEntity)61 Test (org.junit.Test)50 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)28 QuerySpec (io.crnk.core.queryspec.QuerySpec)25 RelatedEntity (io.crnk.jpa.model.RelatedEntity)24 AbstractJpaTest (io.crnk.jpa.query.AbstractJpaTest)16 OtherRelatedEntity (io.crnk.jpa.model.OtherRelatedEntity)12 QueryParams (io.crnk.legacy.queryParams.QueryParams)6 CollectionAttributesTestEntity (io.crnk.jpa.model.CollectionAttributesTestEntity)5 UuidTestEntity (io.crnk.jpa.model.UuidTestEntity)5 Serializable (java.io.Serializable)5 JsonLinksInformation (io.crnk.client.response.JsonLinksInformation)4 JsonMetaInformation (io.crnk.client.response.JsonMetaInformation)4 PagedMetaInformation (io.crnk.core.resource.meta.PagedMetaInformation)4 TestDTO (io.crnk.jpa.model.dto.TestDTO)2 ObjectProxy (io.crnk.client.internal.proxy.ObjectProxy)1 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 FilterSpec (io.crnk.core.queryspec.FilterSpec)1 JpaEntityRepository (io.crnk.jpa.JpaEntityRepository)1 JpaRepositoryFilterBase (io.crnk.jpa.JpaRepositoryFilterBase)1