Search in sources :

Example 1 with MethodAnnotatedEntity

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

the class MethodAnnotatedEntityTest method testMethodAnnotatedFields.

@Test
public void testMethodAnnotatedFields() {
    // tests whether JPA annotations on methods are supported as well
    ResourceRepositoryV2<MethodAnnotatedEntity, Long> methodRepo = client.getQuerySpecRepository(MethodAnnotatedEntity.class);
    MethodAnnotatedEntity task = new MethodAnnotatedEntity();
    task.setId(1L);
    task.setStringValue("test");
    methodRepo.create(task);
    // check retrievable with findAll
    List<MethodAnnotatedEntity> list = methodRepo.findAll(new QuerySpec(MethodAnnotatedEntity.class));
    Assert.assertEquals(1, list.size());
    MethodAnnotatedEntity savedTask = list.get(0);
    Assert.assertEquals(task.getId(), savedTask.getId());
    Assert.assertEquals(task.getStringValue(), savedTask.getStringValue());
    // check retrievable with findAll(ids)
    list = methodRepo.findAll(Arrays.asList(1L), new QuerySpec(MethodAnnotatedEntity.class));
    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 = methodRepo.findOne(1L, new QuerySpec(MethodAnnotatedEntity.class));
    Assert.assertEquals(task.getId(), savedTask.getId());
    Assert.assertEquals(task.getStringValue(), savedTask.getStringValue());
}
Also used : MethodAnnotatedEntity(io.crnk.jpa.model.MethodAnnotatedEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Example 2 with MethodAnnotatedEntity

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

the class MethodAnnotatedEntityTest method testMeta.

@Test
public void testMeta() {
    MethodAnnotatedEntity entity = new MethodAnnotatedEntity();
    entity.setId(13L);
    entity.setStringValue("test");
    MetaEntity meta = jpaMetaProvider.getMeta(MethodAnnotatedEntity.class);
    MetaKey primaryKey = meta.getPrimaryKey();
    Assert.assertNotNull(primaryKey);
    Assert.assertEquals(1, primaryKey.getElements().size());
    MetaAttribute stringValueAttr = meta.getAttribute("stringValue");
    Assert.assertNotNull(stringValueAttr);
    Assert.assertEquals("stringValue", stringValueAttr.getName());
    Assert.assertEquals("test", stringValueAttr.getValue(entity));
    MetaAttribute idAttr = meta.getAttribute("id");
    Assert.assertNotNull(idAttr);
    Assert.assertEquals("id", idAttr.getName());
    Assert.assertEquals(13L, idAttr.getValue(entity));
}
Also used : MethodAnnotatedEntity(io.crnk.jpa.model.MethodAnnotatedEntity) MetaKey(io.crnk.meta.model.MetaKey) MetaEntity(io.crnk.jpa.meta.MetaEntity) MetaAttribute(io.crnk.meta.model.MetaAttribute) Test(org.junit.Test)

Aggregations

MethodAnnotatedEntity (io.crnk.jpa.model.MethodAnnotatedEntity)2 Test (org.junit.Test)2 QuerySpec (io.crnk.core.queryspec.QuerySpec)1 MetaEntity (io.crnk.jpa.meta.MetaEntity)1 MetaAttribute (io.crnk.meta.model.MetaAttribute)1 MetaKey (io.crnk.meta.model.MetaKey)1