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