Search in sources :

Example 16 with RelatedEntity

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

the class JpaRelationshipRepositoryTestBase method testFindNulledOneTarget.

@Test
public void testFindNulledOneTarget() throws InstantiationException, IllegalAccessException {
    long nulledEntityId = numTestEntities - 1;
    QuerySpec querySpec = new QuerySpec(RelatedEntity.class);
    RelatedEntity relatedEntity = repo.findOneTarget(nulledEntityId, TestEntity.ATTR_oneRelatedValue, querySpec);
    Assert.assertNull(relatedEntity);
}
Also used : RelatedEntity(io.crnk.jpa.model.RelatedEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test) AbstractJpaTest(io.crnk.jpa.query.AbstractJpaTest)

Example 17 with RelatedEntity

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

the class BasicQueryTestBase method testWithoutGraphControl.

@Test
public void testWithoutGraphControl() {
    JpaQueryExecutor<TestEntity> exec = builder().addFilter(TestEntity.ATTR_oneRelatedValue, FilterOperator.NEQ, null).buildExecutor();
    for (TestEntity test : exec.getResultList()) {
        RelatedEntity relatedValue = test.getOneRelatedValue();
        assertTrue(Hibernate.isInitialized(test));
        assertFalse(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 18 with RelatedEntity

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

the class HasNextPagingEndToEndTest method testRelationPaging.

@Test
public void testRelationPaging() {
    TestEntity test = new TestEntity();
    test.setId(1L);
    test.setStringValue("test");
    testRepo.create(test);
    ResourceRepositoryStub<RelatedEntity, Long> relatedRepo = client.getQueryParamsRepository(RelatedEntity.class);
    RelationshipRepositoryV2<TestEntity, Long, RelatedEntity, Long> relRepo = client.getQuerySpecRepository(TestEntity.class, RelatedEntity.class);
    for (long i = 0; i < 5; i++) {
        RelatedEntity related1 = new RelatedEntity();
        related1.setId(i);
        related1.setStringValue("related" + i);
        relatedRepo.create(related1);
        relRepo.addRelations(test, Arrays.asList(i), TestEntity.ATTR_manyRelatedValues);
    }
    QuerySpec querySpec = new QuerySpec(RelatedEntity.class);
    querySpec.setOffset(2L);
    querySpec.setLimit(2L);
    ResourceList<RelatedEntity> list = relRepo.findManyTargets(test.getId(), TestEntity.ATTR_manyRelatedValues, querySpec);
    Assert.assertEquals(2, list.size());
    Assert.assertEquals(2, list.get(0).getId().intValue());
    Assert.assertEquals(3, list.get(1).getId().intValue());
    JsonMetaInformation meta = list.getMeta(JsonMetaInformation.class);
    JsonLinksInformation links = list.getLinks(JsonLinksInformation.class);
    Assert.assertNull(meta);
    Assert.assertNotNull(links);
    String baseUri = getBaseUri().toString();
    Assert.assertEquals(baseUri + "test/1/relationships/manyRelatedValues?page[limit]=2", links.asJsonNode().get("first").asText());
    Assert.assertNull(links.asJsonNode().get("last"));
    Assert.assertEquals(baseUri + "test/1/relationships/manyRelatedValues?page[limit]=2", links.asJsonNode().get("prev").asText());
    Assert.assertEquals(baseUri + "test/1/relationships/manyRelatedValues?page[limit]=2&page[offset]=4", links.asJsonNode().get("next").asText());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) JsonLinksInformation(io.crnk.client.response.JsonLinksInformation) JsonMetaInformation(io.crnk.client.response.JsonMetaInformation) RelatedEntity(io.crnk.jpa.model.RelatedEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest)

Example 19 with RelatedEntity

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

the class JpaQuerySpecEndToEndTest method testMappedSuperTypeWithPkOnSubclass.

@Test
public void testMappedSuperTypeWithPkOnSubclass() throws InstantiationException, IllegalAccessException {
    ResourceRepositoryV2<RelatedEntity, Serializable> relatedRepo = client.getQuerySpecRepository(RelatedEntity.class);
    RelatedEntity related = new RelatedEntity();
    related.setId(23423L);
    related.setStringValue("test");
    relatedRepo.create(related);
    TestEntity entity = new TestEntity();
    entity.setId(345345L);
    entity.setLongValue(12L);
    entity.setSuperRelatedValue(related);
    testRepo.create(entity);
    QuerySpec querySpec = new QuerySpec(TestEntity.class);
    querySpec.includeRelation(Arrays.asList(TestEntity.ATTR_superRelatedValue));
    List<TestEntity> list = testRepo.findAll(querySpec);
    Assert.assertEquals(1, list.size());
    TestEntity testEntity = list.get(0);
    RelatedEntity superRelatedValue = testEntity.getSuperRelatedValue();
    Assert.assertNotNull(superRelatedValue);
}
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 20 with RelatedEntity

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

the class JpaQuerySpecEndToEndTest method testFindOneTargetWithNullResult.

@Test
public void testFindOneTargetWithNullResult() throws InstantiationException, IllegalAccessException {
    TestEntity test = new TestEntity();
    test.setId(2L);
    test.setStringValue("test");
    testRepo.create(test);
    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.assertNull(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)

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