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"));
}
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());
}
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());
}
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());
}
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());
}
Aggregations