Search in sources :

Example 26 with RelatedEntity

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

the class JpaQueryParamsEndToEndTest method addTestWithOneRelation.

private TestEntity addTestWithOneRelation() {
    ResourceRepositoryStub<RelatedEntity, Long> relatedRepo = client.getQueryParamsRepository(RelatedEntity.class);
    RelatedEntity related = new RelatedEntity();
    related.setId(1L);
    related.setStringValue("project");
    relatedRepo.create(related);
    TestEntity test = new TestEntity();
    test.setId(2L);
    test.setStringValue("test");
    test.setOneRelatedValue(related);
    testRepo.create(test);
    return test;
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) RelatedEntity(io.crnk.jpa.model.RelatedEntity)

Example 27 with RelatedEntity

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

the class JpaQueryParamsEndToEndTest method testEagerOneRelation.

@Test
public void testEagerOneRelation() {
    ResourceRepositoryStub<RelatedEntity, Long> relatedRepo = client.getQueryParamsRepository(RelatedEntity.class);
    RelatedEntity related = new RelatedEntity();
    related.setId(1L);
    related.setStringValue("project");
    relatedRepo.create(related);
    TestEntity test = new TestEntity();
    test.setId(2L);
    test.setStringValue("test");
    test.setEagerRelatedValue(related);
    testRepo.create(test);
    TestEntity savedTest = testRepo.findOne(2L, new QueryParams());
    Assert.assertEquals(test.getId(), savedTest.getId());
    Assert.assertEquals(test.getStringValue(), savedTest.getStringValue());
    Assert.assertNull(savedTest.getOneRelatedValue());
// TODO should @JsonApiIncludeByDefault trigger this?
// Assert.assertNotNull(savedTest.getEagerRelatedValue());
// Assert.assertEquals(1L, savedTest.getEagerRelatedValue().getId().longValue());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) RelatedEntity(io.crnk.jpa.model.RelatedEntity) QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest)

Example 28 with RelatedEntity

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

the class BasicQueryTestBase method testWithGraphControlWithoutJoin.

@Test
public void testWithGraphControlWithoutJoin() {
    JpaQueryExecutor<TestEntity> exec = builder().buildExecutor().fetch(Arrays.asList(TestEntity.ATTR_oneRelatedValue));
    for (TestEntity test : exec.getResultList()) {
        assertTrue(Hibernate.isInitialized(test));
        RelatedEntity relatedValue = test.getOneRelatedValue();
        if (relatedValue != null) {
            assertTrue(Hibernate.isInitialized(relatedValue));
        }
    }
}
Also used : CollectionAttributesTestEntity(io.crnk.jpa.model.CollectionAttributesTestEntity) UuidTestEntity(io.crnk.jpa.model.UuidTestEntity) TestEntity(io.crnk.jpa.model.TestEntity) RelatedEntity(io.crnk.jpa.model.RelatedEntity) Test(org.junit.Test)

Example 29 with RelatedEntity

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

the class BasicQueryTestBase method testRelations.

@Test
public void testRelations() {
    List<Long> ids = Arrays.asList(1L);
    JpaQuery<RelatedEntity> builder = queryFactory.query(TestEntity.class, TestEntity.ATTR_oneRelatedValue, ids);
    RelatedEntity relatedEntity = builder.buildExecutor().getUniqueResult(false);
    assertEquals(101L, relatedEntity.getId().longValue());
}
Also used : RelatedEntity(io.crnk.jpa.model.RelatedEntity) Test(org.junit.Test)

Example 30 with RelatedEntity

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

the class JpaRelationshipRepositoryTestBase method setup.

@Override
@Before
public void setup() {
    super.setup();
    ResourceField resourceField = this.resourceRegistry.getEntry(TestEntity.class).getResourceInformation().findFieldByUnderlyingName("oneRelatedValue");
    ResourceField relatedField = this.resourceRegistry.getEntry(RelatedEntity.class).getResourceInformation().findFieldByUnderlyingName("testEntity");
    repo = new JpaRelationshipRepository<TestEntity, Long, RelatedEntity, Long>(module, resourceField, JpaRepositoryConfig.create(RelatedEntity.class));
    relatedRepo = new JpaRelationshipRepository<RelatedEntity, Long, TestEntity, Long>(module, relatedField, JpaRepositoryConfig.create(TestEntity.class));
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) ResourceField(io.crnk.core.engine.information.resource.ResourceField) RelatedEntity(io.crnk.jpa.model.RelatedEntity) Before(org.junit.Before)

Aggregations

RelatedEntity (io.crnk.jpa.model.RelatedEntity)35 Test (org.junit.Test)27 TestEntity (io.crnk.jpa.model.TestEntity)24 QuerySpec (io.crnk.core.queryspec.QuerySpec)21 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)13 OtherRelatedEntity (io.crnk.jpa.model.OtherRelatedEntity)13 AbstractJpaTest (io.crnk.jpa.query.AbstractJpaTest)11 Serializable (java.io.Serializable)6 FilterSpec (io.crnk.core.queryspec.FilterSpec)3 JsonLinksInformation (io.crnk.client.response.JsonLinksInformation)2 JsonMetaInformation (io.crnk.client.response.JsonMetaInformation)2 PagedMetaInformation (io.crnk.core.resource.meta.PagedMetaInformation)2 CollectionAttributesTestEntity (io.crnk.jpa.model.CollectionAttributesTestEntity)2 UuidTestEntity (io.crnk.jpa.model.UuidTestEntity)2 ObjectProxy (io.crnk.client.internal.proxy.ObjectProxy)1 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 OneToOneTestEntity (io.crnk.jpa.model.OneToOneTestEntity)1 TestSubclassWithSuperclassPk (io.crnk.jpa.model.TestSubclassWithSuperclassPk)1 RelatedDTO (io.crnk.jpa.model.dto.RelatedDTO)1 QueryParams (io.crnk.legacy.queryParams.QueryParams)1