use of com.blazebit.persistence.view.testsuite.basic.model.DocumentWithEntityView in project blaze-persistence by Blazebit.
the class EntityViewSettingTest method testEntityViewSettingWithEntityAttribute.
@Test
public void testEntityViewSettingWithEntityAttribute() {
EntityViewManager evm = build(DocumentWithEntityView.class, PersonView.class);
// Base setting
EntityViewSetting<DocumentWithEntityView, PaginatedCriteriaBuilder<DocumentWithEntityView>> setting = EntityViewSetting.create(DocumentWithEntityView.class, 0, 1);
// Query
CriteriaBuilder<Document> cb = cbf.create(em, Document.class);
setting.addAttributeFilter("owner.name", "pers2");
// Currently we have no way to express what filter should be used when using entity attributes
try {
evm.applySetting(setting, cb);
Assert.fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// Ok
}
}
use of com.blazebit.persistence.view.testsuite.basic.model.DocumentWithEntityView in project blaze-persistence by Blazebit.
the class EntityViewSettingTest method testEntityViewFetches.
@Test
public void testEntityViewFetches() {
EntityViewManager evm = build(DocumentWithEntityView.class, PersonView.class);
EntityViewSetting<DocumentWithEntityView, CriteriaBuilder<DocumentWithEntityView>> setting = EntityViewSetting.create(DocumentWithEntityView.class);
setting.fetch("id");
setting.fetch("name");
DocumentWithEntityView view = evm.applySetting(setting, cbf.create(em, Document.class).where("name").eq("MyTest")).getSingleResult();
assertEquals("MyTest", view.getName());
assertNotNull(view.getId());
assertNull(view.getOwner());
}
use of com.blazebit.persistence.view.testsuite.basic.model.DocumentWithEntityView in project blaze-persistence by Blazebit.
the class EntityViewSettingTest method testEntityViewSettingNotExistingFilterAttribute.
@Test
public void testEntityViewSettingNotExistingFilterAttribute() {
EntityViewManager evm = build(DocumentWithEntityView.class, PersonView.class);
// Base setting
EntityViewSetting<DocumentWithEntityView, PaginatedCriteriaBuilder<DocumentWithEntityView>> setting = EntityViewSetting.create(DocumentWithEntityView.class, 0, 1);
// Query
CriteriaBuilder<Document> cb = cbf.create(em, Document.class);
setting.addAttributeFilter("asd", "test");
// Currently we have no way to express what filter should be used when using entity attributes
try {
evm.applySetting(setting, cb);
Assert.fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// Ok
}
}
use of com.blazebit.persistence.view.testsuite.basic.model.DocumentWithEntityView in project blaze-persistence by Blazebit.
the class EntityViewSettingTest method testEntityViewFetchesWithFilterAndSorter.
@Test
@Category({ NoMySQLOld.class, NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoHibernate51.class, NoEclipselink.class, NoDatanucleus.class, NoOpenJPA.class })
public // OpenJPA has no function support
void testEntityViewFetchesWithFilterAndSorter() {
EntityViewManager evm = build(DocumentWithEntityView.class, PersonView.class);
EntityViewSetting<DocumentWithEntityView, CriteriaBuilder<DocumentWithEntityView>> setting = EntityViewSetting.create(DocumentWithEntityView.class);
setting.fetch("id");
setting.addAttributeSorter("name", Sorters.ascending());
setting.addAttributeFilter("owner", false);
setting.addAttributeSorter("firstContact.name", Sorters.ascending());
setting.addAttributeSorter("contactCount", Sorters.ascending());
List<DocumentWithEntityView> list = evm.applySetting(setting, cbf.create(em, Document.class)).getResultList();
assertEquals(3, list.size());
DocumentWithEntityView view = list.get(0);
assertNotNull(view.getId());
assertNull(view.getName());
assertNull(view.getOwner());
// We need to fetch it to provide sorting
assertNotNull(view.getFirstContact());
Document document = cbf.create(em, Document.class).where("name").eq("MyTest").getSingleResult();
assertEquals(document.getId(), view.getId());
}
Aggregations