Search in sources :

Example 21 with RelatedEntity

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

the class JpaQuerySpecEndToEndTest method testMappedSuperTypeWithPkOnSuperType.

@Test
public void testMappedSuperTypeWithPkOnSuperType() throws InstantiationException, IllegalAccessException {
    ResourceRepositoryV2<TestSubclassWithSuperclassPk, Serializable> repo = client.getQuerySpecRepository(TestSubclassWithSuperclassPk.class);
    ResourceRepositoryV2<RelatedEntity, Serializable> relatedRepo = client.getQuerySpecRepository(RelatedEntity.class);
    RelatedEntity related = new RelatedEntity();
    related.setId(23423L);
    related.setStringValue("test");
    relatedRepo.create(related);
    TestSubclassWithSuperclassPk entity = new TestSubclassWithSuperclassPk();
    entity.setId("test");
    entity.setLongValue(12L);
    entity.setSuperRelatedValue(related);
    repo.create(entity);
    QuerySpec querySpec = new QuerySpec(TestSubclassWithSuperclassPk.class);
    querySpec.includeRelation(Arrays.asList(TestMappedSuperclassWithPk.ATTR_superRelatedValue));
    List<TestSubclassWithSuperclassPk> list = repo.findAll(querySpec);
    Assert.assertEquals(1, list.size());
    TestSubclassWithSuperclassPk testEntity = list.get(0);
    RelatedEntity superRelatedValue = testEntity.getSuperRelatedValue();
    Assert.assertNotNull(superRelatedValue);
}
Also used : TestSubclassWithSuperclassPk(io.crnk.jpa.model.TestSubclassWithSuperclassPk) Serializable(java.io.Serializable) RelatedEntity(io.crnk.jpa.model.RelatedEntity) OtherRelatedEntity(io.crnk.jpa.model.OtherRelatedEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest) Test(org.junit.Test)

Example 22 with RelatedEntity

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

the class JpaQuerySpecEndToEndTest method testIncludeManyRelations.

@Test
public void testIncludeManyRelations() throws InstantiationException, IllegalAccessException {
    addTestWithManyRelations();
    QuerySpec querySpec = new QuerySpec(TestEntity.class);
    querySpec.includeRelation(Arrays.asList(TestEntity.ATTR_manyRelatedValues));
    List<TestEntity> list = testRepo.findAll(querySpec);
    Assert.assertEquals(1, list.size());
    TestEntity testEntity = list.get(0);
    List<RelatedEntity> manyRelatedValues = testEntity.getManyRelatedValues();
    Assert.assertNotNull(manyRelatedValues);
    Assert.assertEquals(3, manyRelatedValues.size());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) RelatedEntity(io.crnk.jpa.model.RelatedEntity) OtherRelatedEntity(io.crnk.jpa.model.OtherRelatedEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest) Test(org.junit.Test)

Example 23 with RelatedEntity

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

the class JpaQuerySpecEndToEndTest 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 QuerySpec(TestEntity.class));
    Assert.assertEquals(test.getId(), savedTest.getId());
    Assert.assertEquals(test.getStringValue(), savedTest.getStringValue());
    Assert.assertNull(savedTest.getOneRelatedValue());
// TOOD 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) OtherRelatedEntity(io.crnk.jpa.model.OtherRelatedEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest) Test(org.junit.Test)

Example 24 with RelatedEntity

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

the class JpaQuerySpecEndToEndTest method testFindOneTarget.

@Test
public void testFindOneTarget() throws InstantiationException, IllegalAccessException {
    TestEntity test = addTestWithOneRelation();
    RelationshipRepositoryV2<TestEntity, Serializable, RelatedEntity, Serializable> relRepo = client.getQuerySpecRepository(TestEntity.class, RelatedEntity.class);
    RelatedEntity related = relRepo.findOneTarget(test.getId(), TestEntity.ATTR_oneRelatedValue, new QuerySpec(RelatedEntity.class));
    Assert.assertNotNull(related);
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) Serializable(java.io.Serializable) RelatedEntity(io.crnk.jpa.model.RelatedEntity) OtherRelatedEntity(io.crnk.jpa.model.OtherRelatedEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest) Test(org.junit.Test)

Example 25 with RelatedEntity

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

the class SaveRelationshipWithResourceEndToEndTest method testOneToOne.

@Test
public void testOneToOne() throws InstantiationException, IllegalAccessException {
    RelatedEntity related = new RelatedEntity();
    related.setId(12L);
    ResourceRepositoryV2<RelatedEntity, Serializable> relatedRepo = client.getRepositoryForType(RelatedEntity.class);
    relatedRepo.create(related);
    OneToOneTestEntity test = new OneToOneTestEntity();
    test.setId(11L);
    test.setOneRelatedValue(related);
    ResourceRepositoryV2<OneToOneTestEntity, Serializable> testRepo = client.getRepositoryForType(OneToOneTestEntity.class);
    testRepo.create(test);
    QuerySpec querySpec = new QuerySpec(OneToOneTestEntity.class);
    querySpec.includeRelation(Arrays.asList("oneRelatedValue"));
    ResourceList<OneToOneTestEntity> list = testRepo.findAll(querySpec);
    Assert.assertEquals(1, list.size());
    OneToOneTestEntity testCopy = list.get(0);
    Assert.assertNotNull(testCopy.getOneRelatedValue());
    Assert.assertEquals(12L, testCopy.getOneRelatedValue().getId().longValue());
}
Also used : Serializable(java.io.Serializable) RelatedEntity(io.crnk.jpa.model.RelatedEntity) OneToOneTestEntity(io.crnk.jpa.model.OneToOneTestEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest)

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