Search in sources :

Example 16 with EntityViewManager

use of com.blazebit.persistence.view.EntityViewManager in project blaze-persistence by Blazebit.

the class EntityViewJsonbDeserializerTest method testJsonIgnore.

@Test
public void testJsonIgnore() throws Exception {
    EntityViewManager evm = evm(ViewWithJsonIgnore.class);
    Jsonb mapper = mapper(evm);
    ViewWithJsonIgnore view = evm.create(ViewWithJsonIgnore.class);
    view.setId(1L);
    view.setName("Joe");
    JsonObject viewAsJsonTree = mapper.fromJson(mapper.toJson(view, ViewWithJsonIgnore.class), JsonObject.class);
    assertEquals(1L, viewAsJsonTree.getJsonNumber("id").longValue());
    assertNull(viewAsJsonTree.get("name"));
}
Also used : Jsonb(javax.json.bind.Jsonb) EntityViewManager(com.blazebit.persistence.view.EntityViewManager) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Example 17 with EntityViewManager

use of com.blazebit.persistence.view.EntityViewManager in project blaze-persistence by Blazebit.

the class SecondaryViewRootTest method testViewRoots.

@Test
public void testViewRoots() {
    EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration();
    cfg.addEntityView(DocumentWithViewRoots.class);
    cfg.addEntityView(DocumentWithViewRoots.SubView.class);
    EntityViewManager evm = cfg.createEntityViewManager(cbf);
    CriteriaBuilder<Document> cb = cbf.create(em, Document.class, "doc").orderByAsc("doc.id");
    List<DocumentWithViewRoots> list = evm.applySetting(EntityViewSetting.create(DocumentWithViewRoots.class), cb).getResultList();
    assertEquals(2, list.size());
    assertEquals("doc1", list.get(0).getName());
    assertEquals("doc1", list.get(0).getV1Name());
    assertEquals("doc1", list.get(0).getV2Name());
    assertEquals("doc1", list.get(0).getV3Name());
    assertEquals("doc1", list.get(0).getSubView().getV1Name());
    assertEquals("doc1", list.get(0).getSubView().getV2Name());
    assertEquals("doc1", list.get(0).getSubView().getV3Name());
    assertEquals("doc2", list.get(1).getName());
}
Also used : EntityViewConfiguration(com.blazebit.persistence.view.spi.EntityViewConfiguration) EntityViewManager(com.blazebit.persistence.view.EntityViewManager) Document(com.blazebit.persistence.testsuite.entity.Document) DocumentWithViewRoots(com.blazebit.persistence.view.testsuite.viewroot.model.DocumentWithViewRoots) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 18 with EntityViewManager

use of com.blazebit.persistence.view.EntityViewManager in project blaze-persistence by Blazebit.

the class VisibilityTest method testVisibilityModifierAndDifferentPackages.

@Test
public void testVisibilityModifierAndDifferentPackages() {
    EntityViewManager evm = build(IdHolderView.class, DocumentView.class);
    // Requires a class in the package where IdHolderView resides that overrides with public modifiers
    // Should also print a warning that equals can't support user types
    DocumentView documentView = evm.getReference(DocumentView.class, 0L);
    Assert.assertEquals(Long.MIN_VALUE, documentView.id());
}
Also used : EntityViewManager(com.blazebit.persistence.view.EntityViewManager) DocumentView(com.blazebit.persistence.view.testsuite.visibility.model2.DocumentView) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest) Test(org.junit.Test)

Example 19 with EntityViewManager

use of com.blazebit.persistence.view.EntityViewManager in project blaze-persistence by Blazebit.

the class CollectionOverCommonRelationSubviewTest method testSubview.

@Test
public void testSubview() {
    EntityViewManager evm = build(DocumentWithCollectionOverCommonRelationView.class, DocumentRelatedView.class, SimplePersonSubView.class);
    CriteriaBuilder<Document> criteria = cbf.create(em, Document.class, "d").orderByAsc("id");
    CriteriaBuilder<DocumentWithCollectionOverCommonRelationView> cb = evm.applySetting(EntityViewSetting.create(DocumentWithCollectionOverCommonRelationView.class), criteria);
    List<DocumentWithCollectionOverCommonRelationView> results = cb.getResultList();
    assertEquals(3, 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) DocumentWithCollectionOverCommonRelationView(com.blazebit.persistence.view.testsuite.subview.model.DocumentWithCollectionOverCommonRelationView) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 20 with EntityViewManager

use of com.blazebit.persistence.view.EntityViewManager 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)

Aggregations

EntityViewManager (com.blazebit.persistence.view.EntityViewManager)70 Test (org.junit.Test)61 AbstractEntityViewTest (com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)51 Document (com.blazebit.persistence.testsuite.entity.Document)31 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)25 Category (org.junit.experimental.categories.Category)25 PaginatedCriteriaBuilder (com.blazebit.persistence.PaginatedCriteriaBuilder)19 AbstractCorrelationTest (com.blazebit.persistence.view.testsuite.correlation.AbstractCorrelationTest)7 DocumentForCollections (com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections)6 FilteredDocument (com.blazebit.persistence.view.testsuite.basic.model.FilteredDocument)5 Person (com.blazebit.persistence.testsuite.entity.Person)4 DocumentWithEntityView (com.blazebit.persistence.view.testsuite.basic.model.DocumentWithEntityView)4 PersonForCollections (com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections)4 DocumentSimpleCorrelationViewJoinId (com.blazebit.persistence.view.testsuite.correlation.expression.model.DocumentSimpleCorrelationViewJoinId)4 DocumentMasterView (com.blazebit.persistence.view.testsuite.subview.model.DocumentMasterView)4 EntityViewConfiguration (com.blazebit.persistence.view.spi.EntityViewConfiguration)3 PrimitiveDocument (com.blazebit.persistence.testsuite.entity.PrimitiveDocument)2 PersonWithPartnerDocument (com.blazebit.persistence.view.testsuite.cte.model.PersonWithPartnerDocument)2 HashSet (java.util.HashSet)2 Jsonb (javax.json.bind.Jsonb)2