Search in sources :

Example 11 with TestEntity

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

the class JpaQuerySpecEndToEndTest method testDelete.

@Test
public void testDelete() {
    TestEntity test = new TestEntity();
    test.setId(1L);
    test.setStringValue("test");
    testRepo.create(test);
    testRepo.delete(1L);
    List<TestEntity> list = testRepo.findAll(new QuerySpec(TestEntity.class));
    Assert.assertEquals(0, list.size());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest) Test(org.junit.Test)

Example 12 with TestEntity

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

the class JpaQuerySpecEndToEndTest method addTest.

private TestEntity addTest() {
    TestEntity test = new TestEntity();
    test.setId(2L);
    test.setStringValue("test");
    testRepo.create(test);
    return test;
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity)

Example 13 with TestEntity

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

the class JpaQuerySpecEndToEndTest method testIncludeEmptyRelations.

@Test
public void testIncludeEmptyRelations() throws InstantiationException, IllegalAccessException {
    addTest();
    QuerySpec querySpec = new QuerySpec(TestEntity.class);
    querySpec.includeRelation(Arrays.asList(TestEntity.ATTR_oneRelatedValue));
    querySpec.includeRelation(Arrays.asList(TestEntity.ATTR_manyRelatedValues));
    List<TestEntity> list = testRepo.findAll(querySpec);
    Assert.assertEquals(1, list.size());
    for (TestEntity test : list) {
        Assert.assertNull(test.getOneRelatedValue());
        Assert.assertEquals(0, test.getManyRelatedValues().size());
    }
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest) Test(org.junit.Test)

Example 14 with TestEntity

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

the class JpaPartialEntityExposureTest method testCrud.

@Test
public void testCrud() {
    TestEntity test = new TestEntity();
    test.setId(2L);
    test.setStringValue("test");
    testRepo.save(test);
    List<TestEntity> tests = testRepo.findAll(new QueryParams());
    Assert.assertEquals(1, tests.size());
    test = tests.get(0);
    Assert.assertEquals(2L, test.getId().longValue());
    Assert.assertNull(test.getOneRelatedValue());
    Assert.assertNull(test.getEagerRelatedValue());
    Assert.assertTrue(test.getManyRelatedValues().isEmpty());
    testRepo.delete(test.getId());
    tests = testRepo.findAll(new QueryParams());
    Assert.assertEquals(0, tests.size());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) QueryParams(io.crnk.legacy.queryParams.QueryParams)

Example 15 with TestEntity

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

the class JpaRepositoryDecoratorTest method addTestWithOneRelation.

private TestEntity addTestWithOneRelation() {
    ResourceRepositoryV2<RelatedEntity, Long> relatedRepo = client.getQuerySpecRepository(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");
    testRepo.create(test);
    RelationshipRepositoryV2<TestEntity, Long, RelatedEntity, Long> relRepo = client.getQuerySpecRepository(TestEntity.class, RelatedEntity.class);
    relRepo.setRelation(test, related.getId(), TestEntity.ATTR_oneRelatedValue);
    return test;
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) RelatedEntity(io.crnk.jpa.model.RelatedEntity)

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