Search in sources :

Example 1 with TestIdEmbeddable

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

the class JpaQuerySpecEndToEndTest method testEmbeddableIds.

@Test
public void testEmbeddableIds() throws InstantiationException, IllegalAccessException {
    ResourceRepositoryV2<TestEmbeddedIdEntity, Serializable> rep = client.getQuerySpecRepository(TestEmbeddedIdEntity.class);
    // add
    TestEmbeddedIdEntity entity = new TestEmbeddedIdEntity();
    entity.setId(new TestIdEmbeddable(13, "test"));
    entity.setLongValue(100L);
    rep.create(entity);
    List<TestEmbeddedIdEntity> list = rep.findAll(new QuerySpec(TestEntity.class));
    Assert.assertEquals(1, list.size());
    TestEmbeddedIdEntity savedEntity = list.get(0);
    Assert.assertNotNull(savedEntity);
    Assert.assertEquals(100L, savedEntity.getLongValue());
    Assert.assertEquals(13, savedEntity.getId().getEmbIntValue().intValue());
    Assert.assertEquals("test", savedEntity.getId().getEmbStringValue());
    // update
    savedEntity.setLongValue(101L);
    rep.save(savedEntity);
    list = rep.findAll(new QuerySpec(TestEntity.class));
    Assert.assertEquals(1, list.size());
    savedEntity = list.get(0);
    Assert.assertEquals(101L, savedEntity.getLongValue());
    // delete
    rep.delete(entity.getId());
    list = rep.findAll(new QuerySpec(TestEntity.class));
    Assert.assertEquals(0, list.size());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) Serializable(java.io.Serializable) TestIdEmbeddable(io.crnk.jpa.model.TestIdEmbeddable) TestEmbeddedIdEntity(io.crnk.jpa.model.TestEmbeddedIdEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest) Test(org.junit.Test)

Example 2 with TestIdEmbeddable

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

the class JpaQueryParamsEndToEndTest method testEmbeddableIds.

@Test
public void testEmbeddableIds() throws InstantiationException, IllegalAccessException {
    ResourceRepositoryStub<TestEmbeddedIdEntity, Serializable> rep = client.getQueryParamsRepository(TestEmbeddedIdEntity.class);
    // add
    TestEmbeddedIdEntity entity = new TestEmbeddedIdEntity();
    entity.setId(new TestIdEmbeddable(13, "test"));
    entity.setLongValue(100L);
    rep.create(entity);
    List<TestEmbeddedIdEntity> list = rep.findAll(new QueryParams());
    Assert.assertEquals(1, list.size());
    TestEmbeddedIdEntity savedEntity = list.get(0);
    Assert.assertNotNull(savedEntity);
    Assert.assertEquals(100L, savedEntity.getLongValue());
    Assert.assertEquals(13, savedEntity.getId().getEmbIntValue().intValue());
    Assert.assertEquals("test", savedEntity.getId().getEmbStringValue());
    // update
    savedEntity.setLongValue(101L);
    rep.save(savedEntity);
    list = rep.findAll(new QueryParams());
    Assert.assertEquals(1, list.size());
    savedEntity = list.get(0);
    Assert.assertEquals(101L, savedEntity.getLongValue());
    // delete
    rep.delete(entity.getId());
    list = rep.findAll(new QueryParams());
    Assert.assertEquals(0, list.size());
}
Also used : Serializable(java.io.Serializable) TestIdEmbeddable(io.crnk.jpa.model.TestIdEmbeddable) QueryParams(io.crnk.legacy.queryParams.QueryParams) TestEmbeddedIdEntity(io.crnk.jpa.model.TestEmbeddedIdEntity) Test(org.junit.Test) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest)

Aggregations

AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)2 TestEmbeddedIdEntity (io.crnk.jpa.model.TestEmbeddedIdEntity)2 TestIdEmbeddable (io.crnk.jpa.model.TestIdEmbeddable)2 Serializable (java.io.Serializable)2 Test (org.junit.Test)2 QuerySpec (io.crnk.core.queryspec.QuerySpec)1 TestEntity (io.crnk.jpa.model.TestEntity)1 QueryParams (io.crnk.legacy.queryParams.QueryParams)1