Search in sources :

Example 1 with DocumentMasterView

use of com.blazebit.persistence.view.testsuite.subview.model.DocumentMasterView in project blaze-persistence by Blazebit.

the class SubviewEntityViewSettingTest method testEntityViewSettingFilterFilteredSubview.

@Test
@Category({ NoEclipselink.class })
public // Eclipselink does not support VALUE() dereferencing
void testEntityViewSettingFilterFilteredSubview() {
    EntityViewManager evm = build(DocumentMasterView.class, SimpleDocumentView.class, PersonSubView.class, PersonSubViewFiltered.class);
    // Base setting
    EntityViewSetting<DocumentMasterView, PaginatedCriteriaBuilder<DocumentMasterView>> setting = EntityViewSetting.create(DocumentMasterView.class, 0, 1);
    // Query
    CriteriaBuilder<Document> cb = cbf.create(em, Document.class);
    setting.addAttributeFilter("myContactPerson.name", "Owner");
    setting.addAttributeSorter("myContactPerson.name", Sorters.descending());
    setting.addAttributeSorter("id", Sorters.descending());
    setting.addOptionalParameter("contactPersonNumber", 1);
    PaginatedCriteriaBuilder<DocumentMasterView> paginatedCb = evm.applySetting(setting, cb);
    PagedList<DocumentMasterView> result = paginatedCb.getResultList();
    assertEquals(1, result.size());
    assertEquals(2, result.getTotalSize());
    assertEquals("HisTest", result.get(0).getName());
    assertEquals("DocumentOwnerSlave".toUpperCase(), result.get(0).getOwner().getName());
}
Also used : EntityViewManager(com.blazebit.persistence.view.EntityViewManager) DocumentMasterView(com.blazebit.persistence.view.testsuite.subview.model.DocumentMasterView) Document(com.blazebit.persistence.testsuite.entity.Document) PaginatedCriteriaBuilder(com.blazebit.persistence.PaginatedCriteriaBuilder) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 2 with DocumentMasterView

use of com.blazebit.persistence.view.testsuite.subview.model.DocumentMasterView in project blaze-persistence by Blazebit.

the class SubviewTest method testSubview.

@Test
@Category({ NoEclipselink.class })
public // Eclipselink has a result set mapping bug in case of map keys
void testSubview() {
    EntityViewManager evm = build(DocumentMasterView.class, SimpleDocumentView.class, PersonSubView.class, PersonSubViewFiltered.class);
    CriteriaBuilder<Document> criteria = cbf.create(em, Document.class, "d").orderByAsc("id");
    CriteriaBuilder<DocumentMasterView> cb = evm.applySetting(EntityViewSetting.create(DocumentMasterView.class), criteria).setParameter("contactPersonNumber", 2);
    List<DocumentMasterView> results = cb.getResultList();
    assertEquals(2, results.size());
    // Doc1
    assertEquals(doc1.getName(), results.get(0).getName());
    assertEquals("PERS1", results.get(0).getOwner().getName());
    assertEquals(Integer.valueOf(2), results.get(0).getContactPersonNumber());
    assertEquals(Integer.valueOf(2), results.get(0).getTheContactPersonNumber());
    // Filtered subview
    assertEquals(doc1.getContacts().get(2).getName(), results.get(0).getMyContactPerson().getName());
    assertEquals(Integer.valueOf(2), results.get(0).getMyContactPerson().getContactPersonNumber());
    assertSubviewEquals(doc1, doc1.getContacts2(), results.get(0).getContacts());
    assertSubviewEquals(doc1.getPartners(), results.get(0).getPartners());
    assertSubviewEquals(doc1.getPeople(), results.get(0).getPeople());
    // Doc2
    assertEquals(doc2.getName(), results.get(1).getName());
    assertEquals("PERS2", results.get(1).getOwner().getName());
    assertEquals(Integer.valueOf(2), results.get(1).getContactPersonNumber());
    assertEquals(Integer.valueOf(2), results.get(1).getTheContactPersonNumber());
    // Filtered subview
    assertEquals(doc2.getContacts().get(2).getName(), results.get(1).getMyContactPerson().getName());
    assertEquals(Integer.valueOf(2), results.get(1).getMyContactPerson().getContactPersonNumber());
    assertSubviewEquals(doc2, doc2.getContacts2(), results.get(1).getContacts());
    assertSubviewEquals(doc2.getPartners(), results.get(1).getPartners());
    assertSubviewEquals(doc2.getPeople(), results.get(1).getPeople());
}
Also used : EntityViewManager(com.blazebit.persistence.view.EntityViewManager) DocumentMasterView(com.blazebit.persistence.view.testsuite.subview.model.DocumentMasterView) Document(com.blazebit.persistence.testsuite.entity.Document) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 3 with DocumentMasterView

use of com.blazebit.persistence.view.testsuite.subview.model.DocumentMasterView in project blaze-persistence by Blazebit.

the class NullSubviewTest method testSubview.

@Test
@Category({ NoEclipselink.class })
public // Eclipselink has a result set mapping bug in case of map keys
void testSubview() {
    EntityViewManager evm = build(DocumentMasterView.class, SimpleDocumentView.class, PersonSubView.class, PersonSubViewFiltered.class);
    CriteriaBuilder<Document> criteria = cbf.create(em, Document.class, "d").orderByAsc("id");
    CriteriaBuilder<DocumentMasterView> cb = evm.applySetting(EntityViewSetting.create(DocumentMasterView.class), criteria).setParameter("contactPersonNumber", 2);
    List<DocumentMasterView> results = cb.getResultList();
    assertEquals(1, results.size());
    DocumentMasterView res = results.get(0);
    // Doc1
    assertEquals(doc1.getName(), res.getName());
    assertEquals("PERS1", res.getOwner().getName());
    assertEquals(Integer.valueOf(2), res.getContactPersonNumber());
    assertEquals(Integer.valueOf(2), res.getTheContactPersonNumber());
    // Filtered subview
    assertNull(res.getMyContactPerson());
    assertTrue(res.getContacts().isEmpty());
    assertTrue(res.getPartners().isEmpty());
    assertTrue(res.getPeople().isEmpty());
}
Also used : EntityViewManager(com.blazebit.persistence.view.EntityViewManager) DocumentMasterView(com.blazebit.persistence.view.testsuite.subview.model.DocumentMasterView) Document(com.blazebit.persistence.testsuite.entity.Document) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 4 with DocumentMasterView

use of com.blazebit.persistence.view.testsuite.subview.model.DocumentMasterView in project blaze-persistence by Blazebit.

the class SubviewEntityViewSettingTest method testEntityViewSettingFilterSubview.

@Test
@Category({ NoEclipselink.class })
public // Eclipselink has a result set mapping bug in case of map keys
void testEntityViewSettingFilterSubview() {
    EntityViewManager evm = build(DocumentMasterView.class, SimpleDocumentView.class, PersonSubView.class, PersonSubViewFiltered.class);
    // Base setting
    EntityViewSetting<DocumentMasterView, PaginatedCriteriaBuilder<DocumentMasterView>> setting = EntityViewSetting.create(DocumentMasterView.class, 0, 1);
    // Query
    CriteriaBuilder<Document> cb = cbf.create(em, Document.class);
    setting.addAttributeFilter("owner.name", "OWNER");
    setting.addAttributeSorter("owner.name", Sorters.descending());
    setting.addAttributeSorter("id", Sorters.descending());
    setting.addOptionalParameter("contactPersonNumber", 1);
    PaginatedCriteriaBuilder<DocumentMasterView> paginatedCb = evm.applySetting(setting, cb);
    PagedList<DocumentMasterView> result = paginatedCb.getResultList();
    assertEquals(1, result.size());
    assertEquals(2, result.getTotalSize());
    assertEquals("HisTest", result.get(0).getName());
    assertEquals("DocumentOwnerSlave".toUpperCase(), result.get(0).getOwner().getName());
}
Also used : EntityViewManager(com.blazebit.persistence.view.EntityViewManager) DocumentMasterView(com.blazebit.persistence.view.testsuite.subview.model.DocumentMasterView) Document(com.blazebit.persistence.testsuite.entity.Document) PaginatedCriteriaBuilder(com.blazebit.persistence.PaginatedCriteriaBuilder) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Aggregations

Document (com.blazebit.persistence.testsuite.entity.Document)4 EntityViewManager (com.blazebit.persistence.view.EntityViewManager)4 AbstractEntityViewTest (com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)4 DocumentMasterView (com.blazebit.persistence.view.testsuite.subview.model.DocumentMasterView)4 Test (org.junit.Test)4 Category (org.junit.experimental.categories.Category)4 PaginatedCriteriaBuilder (com.blazebit.persistence.PaginatedCriteriaBuilder)2