Search in sources :

Example 36 with TestEntity

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

the class JpaQueryParamsEndToEndTest method testSaveOneRelation.

@Test
public void testSaveOneRelation() {
    TestEntity test = addTestWithOneRelation();
    TestEntity savedTest = testRepo.findOne(2L, includeOneRelatedValueParams());
    Assert.assertEquals(test.getId(), savedTest.getId());
    Assert.assertEquals(test.getStringValue(), savedTest.getStringValue());
    Assert.assertNotNull(savedTest.getOneRelatedValue());
    Assert.assertEquals(1L, savedTest.getOneRelatedValue().getId().longValue());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) Test(org.junit.Test) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest)

Example 37 with TestEntity

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

the class JpaQueryParamsEndToEndTest method testIncludeNoRelations.

@Test
public void testIncludeNoRelations() throws InstantiationException, IllegalAccessException {
    addTestWithOneRelation();
    List<TestEntity> list = testRepo.findAll(new QueryParams());
    Assert.assertEquals(1, list.size());
    for (TestEntity test : list) {
        // in the future we may get proxies here
        Assert.assertNull(test.getOneRelatedValue());
    }
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest)

Example 38 with TestEntity

use of io.crnk.jpa.model.TestEntity 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 39 with TestEntity

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

the class JpaQueryParamsEndToEndTest method testSaveAndFind.

@Test
public void testSaveAndFind() {
    TestEntity task = new TestEntity();
    task.setId(1L);
    task.setStringValue("test");
    testRepo.create(task);
    // check retrievable with findAll
    List<TestEntity> list = testRepo.findAll(new QueryParams());
    Assert.assertEquals(1, list.size());
    TestEntity savedTask = list.get(0);
    Assert.assertEquals(task.getId(), savedTask.getId());
    Assert.assertEquals(task.getStringValue(), savedTask.getStringValue());
    // check retrievable with findAll(ids)
    list = testRepo.findAll(Arrays.asList(1L), new QueryParams());
    Assert.assertEquals(1, list.size());
    savedTask = list.get(0);
    Assert.assertEquals(task.getId(), savedTask.getId());
    Assert.assertEquals(task.getStringValue(), savedTask.getStringValue());
    // check retrievable with findOne
    savedTask = testRepo.findOne(1L, new QueryParams());
    Assert.assertEquals(task.getId(), savedTask.getId());
    Assert.assertEquals(task.getStringValue(), savedTask.getStringValue());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest)

Example 40 with TestEntity

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

the class JpaQueryParamsEndToEndTest method testFindEmpty.

@Test
public void testFindEmpty() {
    List<TestEntity> list = testRepo.findAll(new QueryParams());
    Assert.assertTrue(list.isEmpty());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest)

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