Search in sources :

Example 1 with UpdatableVersionView

use of com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatableVersionView 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());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatableDocumentView) UpdatablePersonView(com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatablePersonView) UpdatableVersionView(com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatableVersionView) Document(com.blazebit.persistence.testsuite.entity.Document) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Example 2 with UpdatableVersionView

use of com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatableVersionView 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());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatableDocumentView) UpdatablePersonView(com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatablePersonView) PluralChangeModel(com.blazebit.persistence.view.change.PluralChangeModel) UpdatableVersionView(com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatableVersionView) Document(com.blazebit.persistence.testsuite.entity.Document) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Example 3 with UpdatableVersionView

use of com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatableVersionView 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());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatableDocumentView) UpdatablePersonView(com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatablePersonView) UpdatableVersionView(com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatableVersionView) Document(com.blazebit.persistence.testsuite.entity.Document) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Aggregations

Document (com.blazebit.persistence.testsuite.entity.Document)3 AbstractEntityViewUpdateTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest)3 UpdatableDocumentView (com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatableDocumentView)3 UpdatablePersonView (com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatablePersonView)3 UpdatableVersionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatableVersionView)3 Test (org.junit.Test)3 PluralChangeModel (com.blazebit.persistence.view.change.PluralChangeModel)1