use of com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseUmappedTest method testAddNewElementToCollection.
@Test
public void testAddNewElementToCollection() {
// Given
UpdatableDocumentView newDocument = evm.create(UpdatableDocumentView.class);
UpdatablePersonView owner = evm.create(UpdatablePersonView.class);
owner.setName("test");
newDocument.setName("doc");
newDocument.setOwner(owner);
update(newDocument);
// When
UpdatableVersionView version = evm.create(UpdatableVersionView.class);
newDocument.getVersions().add(version);
update(newDocument);
// Then
em.clear();
Document doc = em.find(Document.class, newDocument.getId());
Assert.assertEquals(1, doc.getVersions().size());
Assert.assertEquals(version.getId(), doc.getVersions().iterator().next().getId());
}
use of com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseUmappedTest method testAddExistingViewToInverseCollection.
@Test
public void testAddExistingViewToInverseCollection() {
// Given
UpdatableDocumentView newDocument = evm.create(UpdatableDocumentView.class);
UpdatablePersonView owner = evm.create(UpdatablePersonView.class);
owner.setName("test");
newDocument.setName("doc");
newDocument.setOwner(owner);
update(newDocument);
// When
em.clear();
newDocument = evm.applySetting(EntityViewSetting.create(UpdatableDocumentView.class), cbf.create(em, Document.class)).getSingleResult();
UpdatablePersonView newPerson = evm.create(UpdatablePersonView.class);
newPerson.setName("newPerson");
update(newPerson);
newDocument.getPartners().add(newPerson);
update(newDocument);
// Then
em.clear();
Document doc = em.find(Document.class, newDocument.getId());
Assert.assertEquals(1, doc.getPartners().size());
}
use of com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseUmappedTest method testRemoveReadOnlyElementFromCollection.
@Test
public void testRemoveReadOnlyElementFromCollection() {
// Given
UpdatableDocumentView newDocument = evm.create(UpdatableDocumentView.class);
UpdatablePersonView owner = evm.create(UpdatablePersonView.class);
owner.setName("test");
newDocument.setName("doc");
newDocument.setOwner(owner);
UpdatableVersionView version = evm.create(UpdatableVersionView.class);
newDocument.getVersions().add(version);
update(newDocument);
// When
em.clear();
newDocument = evm.applySetting(EntityViewSetting.create(UpdatableDocumentView.class), cbf.create(em, Document.class)).getSingleResult();
newDocument.getVersions().remove(newDocument.getVersions().iterator().next());
PluralChangeModel<Object, Object> positionsChangeModel = (PluralChangeModel<Object, Object>) evm.getChangeModel(newDocument).get("versions");
Assert.assertEquals(1, positionsChangeModel.getRemovedElements().size());
update(newDocument);
// Then
em.clear();
Document doc = em.find(Document.class, newDocument.getId());
Assert.assertEquals(0, doc.getVersions().size());
}
use of com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseUmappedTest method testAddExistingViewWithMapChangesToInverseCollection.
@Test
public void testAddExistingViewWithMapChangesToInverseCollection() {
// Given
UpdatableDocumentView newDocument = evm.create(UpdatableDocumentView.class);
UpdatablePersonView owner = evm.create(UpdatablePersonView.class);
owner.setName("test");
newDocument.setName("doc");
newDocument.setOwner(owner);
update(newDocument);
// When
em.clear();
newDocument = evm.applySetting(EntityViewSetting.create(UpdatableDocumentView.class), cbf.create(em, Document.class)).getSingleResult();
UpdatablePersonView newPerson = evm.create(UpdatablePersonView.class);
newPerson.setName("newPerson");
update(newPerson);
newPerson.getLocalized().put(1, "key1");
newDocument.getPartners().add(newPerson);
update(newDocument);
// Then
em.clear();
Document doc = em.find(Document.class, newDocument.getId());
Assert.assertEquals(1, doc.getPartners().iterator().next().getLocalized().size());
}
use of com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseUmappedTest method testPersistAndAddNewElementToCollection.
@Test
public void testPersistAndAddNewElementToCollection() {
// When
UpdatableDocumentView newDocument = evm.create(UpdatableDocumentView.class);
UpdatablePersonView owner = evm.create(UpdatablePersonView.class);
owner.setName("test");
newDocument.setName("doc");
newDocument.setOwner(owner);
UpdatableVersionView version = evm.create(UpdatableVersionView.class);
newDocument.getVersions().add(version);
update(newDocument);
// Then
em.clear();
Document doc = em.find(Document.class, newDocument.getId());
Assert.assertEquals(1, doc.getVersions().size());
Assert.assertEquals(version.getId(), doc.getVersions().iterator().next().getId());
}
Aggregations